yatex

view yatex19.el @ 47:d7e7b4654058

Support special popup frame. Refine highlightening method. On Emacs-19, couldn't save user completion table correctly, fixed.
author yuuji
date Mon, 24 Oct 1994 17:26:47 +0000
parents cd1b63102eed
children eb0512bfcb7f
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX facilities for Emacs 19
3 ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
4 ;;; Last modified Fri Sep 23 04:30:27 1994 on figaro
5 ;;; $Id$
7 ;;; $B$H$j$"$($:(B hilit19 $B$r;H$C$F$$$k;~$K?'$,IU$/$h$&$K$7$F(B
8 ;;; $B%a%K%e!<%P!<$G$4$K$g$4$K$g$G$-$k$h$&$K$7$?$@$1!#(B
9 ;;; $B$$$C$?$$C/$,%a%K%e!<%P!<;H$C$F(BLaTeX$B%=!<%9=q$/$s$@$m$&$+(B?
10 ;;; $B$^$"$$$$$dN}=,N}=,!#8e$m$NJ}$K$A$g$C$H%3%a%s%H$"$j!#(B
12 (require 'yatex)
14 (defun YaTeX-19-define-sub-menu (map vec &rest bindings)
15 "Define sub-menu-item in MAP at vector VEC as BINDINGS.
16 BINDINGS is a form with optional length: (symbol title binding).
17 When you defined menu-bar keymap such like:
18 (define-key foo-map [menu-bar foo] (make-sparse-keymap \"foo menu\"))
19 and you want to define sub menu for `foo menu' as followings.
20 foo -> menu1 (calling function `func1')
21 menu2 (doing interactive call `(func2 ...)'
22 Call this function like this:
23 (YaTeX-19-define-sub-menu foo-map [menu-bar foo]
24 '(m1 \"Function 1\" func1)
25 '(m2 \"Function 2\" (lambda () (interactive) (func2 ...))))
26 where
27 `m1' and `m2' are the keymap symbol for sub-menu of `[menu-bar foo].
28 `Funtion 1' and `Function 2' are the title strings for sub-menu.
29 "
30 (let ((i 0) (vec2 (make-vector (1+ (length vec)) nil)))
31 (while (< i (length vec))
32 (aset vec2 i (aref vec i))
33 (setq i (1+ i)))
34 (setq bindings (reverse bindings))
35 (mapcar
36 (function
37 (lambda (bind)
38 (aset vec2 (1- (length vec2)) (car bind)) ;set menu-symbol
39 (define-key map vec2
40 (cons (car (cdr bind))
41 (car (cdr (cdr bind)))))))
42 bindings)))
44 ;; Menu for Typeset relating processes ----------------------------------------
45 (define-key YaTeX-mode-map [menu-bar yatex]
46 (cons "YaTeX" (make-sparse-keymap "YaTeX")))
47 (define-key YaTeX-mode-map [menu-bar yatex process]
48 (cons "Process" (make-sparse-keymap "Process")))
49 (YaTeX-19-define-sub-menu
50 YaTeX-mode-map [menu-bar yatex process]
51 '(buffer "LaTeX" (lambda () (interactive) (YaTeX-typeset-menu nil ?j)))
52 '(kill "Kill LaTeX" (lambda () (interactive) (YaTeX-typeset-menu nil ?k)))
53 '(bibtex "BibTeX" (lambda () (interactive) (YaTeX-typeset-menu nil ?b)))
54 '(makeindex "makeindex" (lambda () (interactive) (YaTeX-typeset-menu nil ?i)))
55 '(preview "Preview" (lambda () (interactive) (YaTeX-typeset-menu nil ?p)))
56 '(lpr "lpr" (lambda () (interactive) (YaTeX-typeset-menu nil ?l)))
57 '(lpq "lpq" (lambda () (interactive) (YaTeX-typeset-menu nil ?q)))
58 )
60 ;; Help for LaTeX ------------------------------------------------------------
61 (YaTeX-19-define-sub-menu
62 YaTeX-mode-map [menu-bar yatex]
63 '(sephelp "--")
64 '(help "Help on LaTeX commands" YaTeX-help)
65 '(apropos "Apropos on LaTeX commands" YaTeX-apropos))
67 ;; Switch modes --------------------------------------------------------------
68 (define-key YaTeX-mode-map [menu-bar yatex switch]
69 (cons "Switching YaTeX's modes" (make-sparse-keymap "modes")))
70 (or YaTeX-auto-math-mode
71 (define-key YaTeX-mode-map [menu-bar yatex switch math]
72 '("Toggle math mode" . (lambda () (interactive)
73 (YaTeX-switch-mode-menu nil ?t)))))
74 (define-key YaTeX-mode-map [menu-bar yatex switch mod]
75 '("Toggle modify mode" . (lambda () (interactive)
76 (YaTeX-switch-mode-menu nil ?m))))
78 ;; % menu --------------------------------------------------------------------
79 (define-key YaTeX-mode-map [menu-bar yatex percent]
80 (cons "Edit %# notation" (make-sparse-keymap "Edit %# notation")))
81 (YaTeX-19-define-sub-menu
82 YaTeX-mode-map [menu-bar yatex percent]
83 '(! "Change LaTeX typesetter(%#!)"
84 (lambda () (interactive) (YaTeX-%-menu nil nil ?!)))
85 '(begend "Set %#BEGIN-%#END on region"
86 (lambda () (interactive) (YaTeX-%-menu nil nil ?b)))
87 '(lpr "Change LPR format"
88 (lambda () (interactive) (YaTeX-%-menu nil nil ?l))))
90 ;; What position -------------------------------------------------------------
91 (YaTeX-19-define-sub-menu
92 YaTeX-mode-map [menu-bar yatex]
93 '(what "What column in tabular" YaTeX-what-column))
95 ;; Jump cursor ---------------------------------------------------------------
96 (define-key YaTeX-mode-map [menu-bar yatex jump]
97 (cons "Jump cursor"
98 (make-sparse-keymap "Jump cursor")))
99 (YaTeX-19-define-sub-menu
100 YaTeX-mode-map [menu-bar yatex jump]
101 '(corres "Goto corersponding position" YaTeX-goto-corresponding-*)
102 '(main "Visit main source" (lambda () (interactive) (YaTeX-visit-main)))
103 '(main-other "Visit main source other window" YaTeX-visit-main-other-window)
104 )
106 ;; ===========================================================================
107 (define-key YaTeX-mode-map [menu-bar yatex sepcom]
108 '("---" . nil))
110 ;; Comment/Uncomment ---------------------------------------------------------
111 (YaTeX-19-define-sub-menu
112 YaTeX-mode-map [menu-bar yatex]
113 '(comment "Comment region or environment" YaTeX-comment-region)
114 '(uncomment "Unomment region or environment" YaTeX-uncomment-region)
115 '(commentp "Comment paragraph" YaTeX-comment-paragraph)
116 '(uncommentp "Uncomment paragraph" YaTeX-uncomment-paragraph)
117 '(sepcom "--" nil)
118 )
121 ;; ===========================================================================
122 ;; Change/Kill/Fill
123 (YaTeX-19-define-sub-menu
124 YaTeX-mode-map [menu-bar yatex]
125 '(change "Change macros" YaTeX-change-*)
126 '(kill "Kill macros" YaTeX-kill-*)
127 '(fillitem "Fill \\item" YaTeX-fill-item)
128 '(newline "Newline" YaTeX-intelligent-newline)
129 '(sepchg "--" nil)
130 )
132 ;; Menu for completions ------------------------------------------------------
135 ;;;(YaTeX-19-define-sub-menu
136 ;;; YaTeX-mode-map [menu-bar yatex]
137 ;;; '(secr "Section-type command on region" YaTeX-make-section-region)
138 ;;; '(sec "Section-type command" YaTeX-make-section))
140 (define-key YaTeX-mode-map [menu-bar yatex sectionr]
141 (cons "Section-type region(long name)"
142 (make-sparse-keymap "Enclose region with section-type macro")))
143 (define-key YaTeX-mode-map [menu-bar yatex section]
144 (cons "Section-type(long name)"
145 (make-sparse-keymap "Section-type macro")))
146 (let ((sorted-section
147 (sort
148 (delq nil
149 (mapcar (function (lambda (s)
150 (if (> (length (car s)) 5)
151 (car s))))
152 (append section-table user-section-table)))
153 'string<)))
154 (apply 'YaTeX-19-define-sub-menu
155 YaTeX-mode-map [menu-bar yatex section]
156 (mapcar (function (lambda (secname)
157 (list (intern secname) secname
158 (list 'lambda ()
159 (list 'interactive)
160 (list 'YaTeX-make-section
161 nil nil nil secname)))))
162 sorted-section))
163 (apply 'YaTeX-19-define-sub-menu
164 YaTeX-mode-map [menu-bar yatex sectionr]
165 (mapcar (function (lambda (secname)
166 (list (intern secname) secname
167 (list 'lambda ()
168 (list 'interactive)
169 (list 'YaTeX-make-section
170 nil
171 (list 'region-beginning)
172 (list 'region-end)
173 secname)))))
174 sorted-section)))
176 (define-key YaTeX-mode-map [menu-bar yatex envr]
177 (cons "Environment region" (make-sparse-keymap "Environment region")))
178 (define-key YaTeX-mode-map [menu-bar yatex env]
179 (cons "Environment" (make-sparse-keymap "Environment")))
180 (let (prev envname)
181 (mapcar
182 (function
183 (lambda (envalist)
184 (setq envname (car envalist))
185 (define-key-after
186 (lookup-key YaTeX-mode-map [menu-bar yatex env])
187 (vector (intern envname))
188 (cons envname
189 (list 'lambda () (list 'interactive)
190 (list 'YaTeX-insert-begin-end
191 envname nil)))
192 prev)
193 (define-key-after
194 (lookup-key YaTeX-mode-map [menu-bar yatex envr])
195 (vector (intern envname))
196 (cons envname
197 (list 'lambda () (list 'interactive)
198 (list 'YaTeX-insert-begin-end
199 envname t)))
200 prev)
201 (setq prev (intern envname))))
202 (sort (append env-table user-env-table)
203 '(lambda (x y) (string< (car x) (car y))))))
205 ;; Highlightening
206 ;; $B%m!<%+%k$J%^%/%m$rFI$_9~$s$@8e(B redraw $B$9$k$H(B
207 ;; $B%m!<%+%k%^%/%m$r(B keyword $B$H$7$F8w$i$;$k(B(keyword$B$8$c$^$:$$$+$J!D(B)$B!#(B
208 (defvar YaTeX-hilit-pattern-adjustment
209 (list
210 ;;\def $B$,(B define $B$J$s$@$+$i(B new* $B$b(B define $B$G$7$g$&!#(B
211 '("\\\\\\(re\\)?new\\(environment\\|command\\){" "}" define)
212 '("\\\\new\\(length\\|theorem\\|counter\\){" "}" define)
213 ;;$B%;%/%7%g%s%3%^%s%I$,C1$J$k%-!<%o!<%I$C$F$3$H$O$J$$$G$7$g$&!#(B
214 (list
215 (concat "\\\\\\(" YaTeX-sectioning-regexp "\\){") "}"
216 'sectioning))
217 "Adjustment for hilit19's LaTeX hilit pattern.")
218 (defvar YaTeX-hilit-sectioning-face
219 '(yellow/dodgerblue yellow/cornflowerblue))
220 (defvar YaTeX-hilit-singlecmd-face
221 '(slateblue2 aquamarine))
222 (defun YaTeX-19-collect-macro ()
223 (cond
224 ((and (featurep 'hilit19) (fboundp 'hilit-translate))
225 (let ((get-face
226 (function
227 (lambda (table)
228 (cond
229 ((eq hilit-background-mode 'light) (car table))
230 ((eq hilit-background-mode 'dark) (car (cdr table)))
231 (t nil))))))
232 (hilit-translate
233 sectioning (funcall get-face YaTeX-hilit-sectioning-face)
234 macro (funcall get-face YaTeX-hilit-singlecmd-face)))
235 (setq hilit-patterns-alist ;Remove at first.
236 (delq 'yatex-mode hilit-patterns-alist)
237 hilit-patterns-alist
238 (cons
239 (cons 'yatex-mode
240 (append
241 YaTeX-hilit-pattern-adjustment
242 (cdr (assq 'latex-mode hilit-patterns-alist))
243 (list
244 (list
245 (concat "\\\\\\("
246 (mapconcat
247 (function (lambda (s) (regexp-quote (car s))))
248 (append user-section-table tmp-section-table)
249 "\\|")
250 "\\){")
251 "}" 'keyword)
252 (list
253 (concat "\\\\\\("
254 (mapconcat
255 (function (lambda (s) (regexp-quote (car s))))
256 (append user-singlecmd-table tmp-singlecmd-table)
257 "\\|")
258 "\\)")
259 0 'macro))))
260 hilit-patterns-alist)))))
261 (YaTeX-19-collect-macro)
262 (defun YaTeX-hilit-recenter (arg)
263 "Collect current local macro and hilit-recenter."
264 (interactive "P")
265 (YaTeX-19-collect-macro)
266 (hilit-recenter arg))
267 (if (fboundp 'hilit-recenter) ;Replace hilit-recenter with
268 (mapcar (function (lambda (key) ;YaTeX-hilit-recenter in yatex-mode
269 (define-key YaTeX-mode-map key 'YaTeX-hilit-recenter)))
270 (where-is-internal 'hilit-recenter)))
272 ;;; reverseVideo $B$K$7$F(B hilit-background-mode $B$r(B 'dark
273 ;;; $B$K$7$F$$$k?M$O?t<0$J$I$,0E$/$J$j$9$.$F8+$E$i$$$+$b$7$l$J$$!#(B
274 ;;; $B<!$N%3!<%I$r(B hilit19 $B$r%m!<%I$7$F$$$k>l=j$ND>8e$KCV$/$H$A$g$C(B
275 ;;; $B$H$O$^$7!#(B
276 ;;; (if (eq hilit-background-mode 'dark)
277 ;;; (hilit-translate
278 ;;; string 'mediumspringgreen
279 ;;; formula 'khaki
280 ;;; label 'yellow-underlined))
282 (provide 'yatex19)