yatex

view yatex19.el @ 49:eb0512bfcb7f

Abolish user-article table. Use normal read-string instead. Supply smart add-in function for documentstyle. Update user dictionary whenever new words entered. Enhance [prefix] c. Allow user defined sectioning commands in yatexsec.
author yuuji
date Fri, 25 Nov 1994 08:26:13 +0000
parents d7e7b4654058
children b0371b6ed799
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 Mon Nov 21 21:52:16 1994 on figaro
5 ;;; $Id$
7 ;;; とりあえず hilit19 を使っている時に色が付くようにして
8 ;;; メニューバーでごにょごにょできるようにしただけ。
9 ;;; いったい誰がメニューバー使ってLaTeXソース書くんだろうか?
10 ;;; まあいいや練習練習。後ろの方にちょっとコメントあり。
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 ;; ローカルなマクロを読み込んだ後 redraw すると
207 ;; ローカルマクロを keyword として光らせる(keywordじゃまずいかな…)。
208 (defvar YaTeX-hilit-pattern-adjustment
209 (list
210 ;;\def が define なんだから new* も define でしょう。
211 '("\\\\\\(re\\)?new\\(environment\\|command\\){" "}" define)
212 '("\\\\new\\(length\\|theorem\\|counter\\){" "}" define)
213 ;;セクションコマンドが単なるキーワードってことはないでしょう。
214 (list
215 (concat "\\\\\\(" YaTeX-sectioning-regexp "\\){") "}"
216 'sectioning)
217 ;;eqnarray などの数式環境が入ってないみたい…
218 '("\\\\begin{\\(eqnarray\\*?\\)\\|\\(equation\\*?\\)}"
219 "\\\\end{\\(eqnarray\\*?\\)\\|\\(equation\\*?\\)}"
220 formula))
221 "Adjustment for hilit19's LaTeX hilit pattern.")
222 (defvar YaTeX-hilit-sectioning-face
223 '(yellow/dodgerblue yellow/cornflowerblue))
224 (defvar YaTeX-hilit-singlecmd-face
225 '(slateblue2 aquamarine))
226 (defun YaTeX-19-collect-macro ()
227 (cond
228 ((and (featurep 'hilit19) (fboundp 'hilit-translate))
229 (let ((get-face
230 (function
231 (lambda (table)
232 (cond
233 ((eq hilit-background-mode 'light) (car table))
234 ((eq hilit-background-mode 'dark) (car (cdr table)))
235 (t nil))))))
236 (hilit-translate
237 sectioning (funcall get-face YaTeX-hilit-sectioning-face)
238 macro (funcall get-face YaTeX-hilit-singlecmd-face)))
239 (setq hilit-patterns-alist ;Remove at first.
240 (delq 'yatex-mode hilit-patterns-alist)
241 hilit-patterns-alist
242 (cons
243 (cons 'yatex-mode
244 (append
245 YaTeX-hilit-pattern-adjustment
246 (cdr (assq 'latex-mode hilit-patterns-alist))
247 (list
248 (list
249 (concat "\\\\\\("
250 (mapconcat
251 (function (lambda (s) (regexp-quote (car s))))
252 (append user-section-table tmp-section-table)
253 "\\|")
254 "\\){")
255 "}" 'keyword)
256 (list
257 (concat "\\\\\\("
258 (mapconcat
259 (function (lambda (s) (regexp-quote (car s))))
260 (append user-singlecmd-table tmp-singlecmd-table)
261 "\\|")
262 "\\)")
263 0 'macro))))
264 hilit-patterns-alist)))))
265 (YaTeX-19-collect-macro)
266 (defun YaTeX-hilit-recenter (arg)
267 "Collect current local macro and hilit-recenter."
268 (interactive "P")
269 (YaTeX-19-collect-macro)
270 (hilit-recenter arg))
271 (if (fboundp 'hilit-recenter) ;Replace hilit-recenter with
272 (mapcar (function (lambda (key) ;YaTeX-hilit-recenter in yatex-mode
273 (define-key YaTeX-mode-map key 'YaTeX-hilit-recenter)))
274 (where-is-internal 'hilit-recenter)))
276 ;;; reverseVideo にして hilit-background-mode を 'dark
277 ;;; にしている人は数式などが暗くなりすぎて見づらいかもしれない。
278 ;;; 次のコードを hilit19 をロードしている場所の直後に置くとちょっ
279 ;;; とはまし。
280 ;;; (if (eq hilit-background-mode 'dark)
281 ;;; (hilit-translate
282 ;;; string 'mediumspringgreen
283 ;;; formula 'khaki
284 ;;; label 'yellow-underlined))
286 (provide 'yatex19)