yatex

view yatex19.el @ 52:5d94deabb9f9

Set YaTeX-indent-line to 'indent-line-function. Revise fill features.
author yuuji
date Sun, 22 Jan 1995 14:20:46 +0000
parents b0371b6ed799
children 5f4b18da14b3
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX facilities for Emacs 19
3 ;;; (c )1994-1995 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
4 ;;; Last modified Sun Jan 22 23:15:56 1995 on landcruiser
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 ;; Document hierarchy ------------------------------------------------------
96 (YaTeX-19-define-sub-menu
97 YaTeX-mode-map [menu-bar yatex]
98 '(hier "Display document hierarchy" YaTeX-display-hierarchy-directly))
100 ;; Jump cursor ---------------------------------------------------------------
101 (define-key YaTeX-mode-map [menu-bar yatex jump]
102 (cons "Jump cursor"
103 (make-sparse-keymap "Jump cursor")))
104 (YaTeX-19-define-sub-menu
105 YaTeX-mode-map [menu-bar yatex jump]
106 '(corres "Goto corersponding position" YaTeX-goto-corresponding-*)
107 '(main "Visit main source" (lambda () (interactive) (YaTeX-visit-main)))
108 '(main-other "Visit main source other window" YaTeX-visit-main-other-window)
109 )
111 ;; ===========================================================================
112 (define-key YaTeX-mode-map [menu-bar yatex sepcom]
113 '("---" . nil))
115 ;; Comment/Uncomment ---------------------------------------------------------
116 (YaTeX-19-define-sub-menu
117 YaTeX-mode-map [menu-bar yatex]
118 '(comment "Comment region or environment" YaTeX-comment-region)
119 '(uncomment "Unomment region or environment" YaTeX-uncomment-region)
120 '(commentp "Comment paragraph" YaTeX-comment-paragraph)
121 '(uncommentp "Uncomment paragraph" YaTeX-uncomment-paragraph)
122 '(sepcom "--" nil)
123 )
126 ;; ===========================================================================
127 ;; Change/Kill/Fill
128 (YaTeX-19-define-sub-menu
129 YaTeX-mode-map [menu-bar yatex]
130 '(change "Change macros" YaTeX-change-*)
131 '(kill "Kill macros" YaTeX-kill-*)
132 '(fillitem "Fill \\item" YaTeX-fill-item)
133 '(newline "Newline" YaTeX-intelligent-newline)
134 '(sepchg "--" nil)
135 )
137 ;; Menu for completions ------------------------------------------------------
140 ;;;(YaTeX-19-define-sub-menu
141 ;;; YaTeX-mode-map [menu-bar yatex]
142 ;;; '(secr "Section-type command on region" YaTeX-make-section-region)
143 ;;; '(sec "Section-type command" YaTeX-make-section))
145 (define-key YaTeX-mode-map [menu-bar yatex sectionr]
146 (cons "Section-type region(long name)"
147 (make-sparse-keymap "Enclose region with section-type macro")))
148 (define-key YaTeX-mode-map [menu-bar yatex section]
149 (cons "Section-type(long name)"
150 (make-sparse-keymap "Section-type macro")))
151 (let ((sorted-section
152 (sort
153 (delq nil
154 (mapcar (function (lambda (s)
155 (if (> (length (car s)) 5)
156 (car s))))
157 (append section-table user-section-table)))
158 'string<)))
159 (apply 'YaTeX-19-define-sub-menu
160 YaTeX-mode-map [menu-bar yatex section]
161 (mapcar (function (lambda (secname)
162 (list (intern secname) secname
163 (list 'lambda ()
164 (list 'interactive)
165 (list 'YaTeX-make-section
166 nil nil nil secname)))))
167 sorted-section))
168 (apply 'YaTeX-19-define-sub-menu
169 YaTeX-mode-map [menu-bar yatex sectionr]
170 (mapcar (function (lambda (secname)
171 (list (intern secname) secname
172 (list 'lambda ()
173 (list 'interactive)
174 (list 'YaTeX-make-section
175 nil
176 (list 'region-beginning)
177 (list 'region-end)
178 secname)))))
179 sorted-section)))
181 (define-key YaTeX-mode-map [menu-bar yatex envr]
182 (cons "Environment region" (make-sparse-keymap "Environment region")))
183 (define-key YaTeX-mode-map [menu-bar yatex env]
184 (cons "Environment" (make-sparse-keymap "Environment")))
185 (let (prev envname)
186 (mapcar
187 (function
188 (lambda (envalist)
189 (setq envname (car envalist))
190 (define-key-after
191 (lookup-key YaTeX-mode-map [menu-bar yatex env])
192 (vector (intern envname))
193 (cons envname
194 (list 'lambda () (list 'interactive)
195 (list 'YaTeX-insert-begin-end
196 envname nil)))
197 prev)
198 (define-key-after
199 (lookup-key YaTeX-mode-map [menu-bar yatex envr])
200 (vector (intern envname))
201 (cons envname
202 (list 'lambda () (list 'interactive)
203 (list 'YaTeX-insert-begin-end
204 envname t)))
205 prev)
206 (setq prev (intern envname))))
207 (sort (append env-table user-env-table)
208 '(lambda (x y) (string< (car x) (car y))))))
210 ;; Highlightening
211 ;; ローカルなマクロを読み込んだ後 redraw すると
212 ;; ローカルマクロを keyword として光らせる(keywordじゃまずいかな…)。
213 (defvar YaTeX-hilit-patterns-alist nil
214 "*Hiliting pattern alist for LaTeX text.
215 Default value is equal to latex-mode's one.")
216 (defvar YaTeX-hilit-pattern-adjustment-default
217 (list
218 ;;\def が define なんだから new* も define でしょう。
219 '("\\\\\\(re\\)?new\\(environment\\|command\\){" "}" define)
220 '("\\\\new\\(length\\|theorem\\|counter\\){" "}" define)
221 ;;セクションコマンドが単なるキーワードってことはないでしょう。
222 ;;(list
223 ;;(concat "\\\\\\(" YaTeX-sectioning-regexp "\\){") "}"
224 ;;'sectioning)
225 ;;eqnarray などの数式環境が入ってないみたい…
226 '("\\\\begin{\\(eqnarray\\*?\\|equation\\*?\\)}"
227 "\\\\end{\\(eqnarray\\*?\\|equation\\*?\\)}"
228 formula))
229 "Adjustment for hilit19's LaTeX hilit pattern.")
230 (defvar YaTeX-hilit-pattern-adjustment-private nil
231 "*Private variable, same purpose as YaTeX-hilit-pattern-adjustment-default.")
232 (defvar YaTeX-hilit-sectioning-face
233 '(yellow/dodgerblue yellow/cornflowerblue)
234 "*Hilightening face for sectioning unit. '(FaceForLight FaceForDark)")
235 (defvar YaTeX-sectioning-patterns-alist nil
236 "Hilightening patterns for sectioning units.")
237 (defvar YaTeX-hilit-singlecmd-face
238 '(slateblue2 aquamarine)
239 "*Hilightening face for maketitle type. '(FaceForLight FaceForDark)")
241 ;;; セクションコマンドを、構造レベルの高さに応じて色の濃度を変える
242 ;;; 背景が黒でないと何が嬉しいのか分からないに違いない.
243 (let*((sectface
244 (car (if (eq hilit-background-mode 'dark)
245 (cdr YaTeX-hilit-sectioning-face)
246 YaTeX-hilit-sectioning-face)))
247 (sectcol (symbol-name sectface))
248 sect-pat-alist)
249 (if (string-match "/" sectcol)
250 (let (colorvalue fR fG fB bR bG bB list pat fg bg level from face)
251 (require 'yatexsec)
252 (setq fg (substring sectcol 0 (string-match "/" sectcol))
253 bg (substring sectcol (1+ (string-match "/" sectcol)))
254 colorvalue (x-color-values fg)
255 fR (/ (nth 0 colorvalue) 256)
256 fG (/ (nth 1 colorvalue) 256)
257 fB (/ (nth 2 colorvalue) 256)
258 colorvalue (x-color-values bg)
259 bR (/ (nth 0 colorvalue) 256)
260 bG (/ (nth 1 colorvalue) 256)
261 bB (/ (nth 2 colorvalue) 256)
262 list YaTeX-sectioning-level)
263 (while list
264 (setq pat (concat YaTeX-ec-regexp (car (car list)) "\\*?{")
265 level (cdr (car list))
266 fg (format "hex-%02x%02x%02x"
267 (- fR (/ (* level fR) 40)) ;40 musn't be constant
268 (- fG (/ (* level fG) 40))
269 (- fB (/ (* level fB) 40)))
270 bg (format "hex-%02x%02x%02x"
271 (- bR (/ (* level bR) 15)) ;20 musn't be constant
272 (- bG (/ (* level bG) 15))
273 (- bB (/ (* level bB) 15)))
274 from (intern (format "sectioning-%d" level))
275 face (intern (concat fg "/" bg)))
276 (hilit-translate from face)
277 (setq sect-pat-alist
278 (cons (list pat "}" face)
279 sect-pat-alist))
280 (setq list (cdr list)))
281 (setq YaTeX-sectioning-patterns-alist sect-pat-alist))))
283 (defun YaTeX-19-collect-macro ()
284 (cond
285 ((and (featurep 'hilit19) (fboundp 'hilit-translate))
286 (or YaTeX-hilit-patterns-alist
287 (let ((alist (cdr (assq 'latex-mode hilit-patterns-alist))))
288 (setcar (assoc "\\\\item\\(\\[[^]]*\\]\\)?" alist)
289 (concat YaTeX-item-regexp "\\b\\(\\[[^]]*\\]\\)?"))
290 (setq YaTeX-hilit-patterns-alist alist)))
291 (let ((get-face
292 (function
293 (lambda (table)
294 (cond
295 ((eq hilit-background-mode 'light) (car table))
296 ((eq hilit-background-mode 'dark) (car (cdr table)))
297 (t nil))))))
298 (hilit-translate
299 ;;sectioning (funcall get-face YaTeX-hilit-sectioning-face)
300 macro (funcall get-face YaTeX-hilit-singlecmd-face)))
301 (setq hilit-patterns-alist ;Remove at first.
302 (delq 'yatex-mode hilit-patterns-alist)
303 hilit-patterns-alist
304 (cons
305 (cons 'yatex-mode
306 (append
307 YaTeX-sectioning-patterns-alist
308 YaTeX-hilit-pattern-adjustment-private
309 YaTeX-hilit-pattern-adjustment-default
310 YaTeX-hilit-patterns-alist
311 (list
312 (list
313 (concat "\\\\\\("
314 (mapconcat
315 (function (lambda (s) (regexp-quote (car s))))
316 (append user-section-table tmp-section-table)
317 "\\|")
318 "\\){")
319 "}" 'keyword)
320 (list
321 (concat "\\\\\\("
322 (mapconcat
323 (function (lambda (s) (regexp-quote (car s))))
324 (append user-singlecmd-table tmp-singlecmd-table)
325 "\\|")
326 "\\)\\b")
327 0 'macro))))
328 hilit-patterns-alist)))))
329 (YaTeX-19-collect-macro)
330 (defun YaTeX-hilit-recenter (arg)
331 "Collect current local macro and hilit-recenter."
332 (interactive "P")
333 (YaTeX-19-collect-macro)
334 (hilit-recenter arg))
335 (if (fboundp 'hilit-recenter) ;Replace hilit-recenter with
336 (mapcar (function (lambda (key) ;YaTeX-hilit-recenter in yatex-mode
337 (define-key YaTeX-mode-map key 'YaTeX-hilit-recenter)))
338 (where-is-internal 'hilit-recenter)))
340 ;;; reverseVideo にして hilit-background-mode を 'dark
341 ;;; にしている人は数式などが暗くなりすぎて見づらいかもしれない。
342 ;;; 次のコードを hilit19 をロードしている場所の直後に置くとちょっ
343 ;;; とはまし。
344 ;;; (if (eq hilit-background-mode 'dark)
345 ;;; (hilit-translate
346 ;;; string 'mediumspringgreen
347 ;;; formula 'khaki
348 ;;; label 'yellow-underlined))
350 (provide 'yatex19)