yatex

view yatex19.el @ 72:0aaebd07dad0

Support font-lock on XEmacs-21, Emacs-20, Emacs-21. Support Emacs-21.
author yuuji
date Mon, 25 Dec 2000 10:19:28 +0000
parents 44e3a5e1e883
children f41b01fef5d6
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX facilities for Emacs 19
3 ;;; (c )1994-2000 by HIROSE Yuuji.[yuuji@yatex.org]
4 ;;; Last modified Mon Dec 25 19:16:04 2000 on firestorm
5 ;;; $Id$
7 ;(require 'yatex)
9 (cond
10 (YaTeX-use-hilit19 (require 'hilit19))
11 (YaTeX-use-font-lock (require 'font-lock)))
13 (defvar YaTeX-use-highlighting (or YaTeX-use-font-lock YaTeX-use-hilit19)
14 "*Use highlighting buffer or not.")
15 (defvar YaTeX-background-mode
16 (cond
17 ((boundp 'hilit-background-mode) hilit-background-mode)
18 ((boundp 'frame-background-mode) frame-background-mode)
19 ((fboundp 'get-frame-background-mode)
20 (get-frame-background-mode (selected-frame)))
21 (t nil)))
23 (defvar YaTeX-mode-menu-map (make-sparse-keymap "YaTeX"))
24 (defvar YaTeX-mode-menu-map-process (make-sparse-keymap "Process"))
25 (define-key YaTeX-mode-map [menu-bar yatex]
26 (cons "YaTeX" YaTeX-mode-menu-map))
27 (YaTeX-define-menu
28 'YaTeX-mode-menu-map-process
29 (nreverse
30 '((buffer "LaTeX" . (lambda () (interactive) (YaTeX-typeset-menu nil ?j)))
31 (kill "Kill LaTeX" . (lambda () (interactive) (YaTeX-typeset-menu nil ?k)))
32 (bibtex "BibTeX" . (lambda () (interactive) (YaTeX-typeset-menu nil ?b)))
33 (mindex "makeindex" . (lambda () (interactive) (YaTeX-typeset-menu nil ?i)))
34 (preview "Preview" . (lambda () (interactive) (YaTeX-typeset-menu nil ?p)))
35 (lpr "lpr" . (lambda () (interactive) (YaTeX-typeset-menu nil ?l)))
36 (lpq "lpq" . (lambda () (interactive) (YaTeX-typeset-menu nil ?q))))))
37 (defvar YaTeX-mode-menu-map-modes (make-sparse-keymap "Modes"))
38 (YaTeX-define-menu
39 'YaTeX-mode-menu-map-modes
40 (delq nil
41 (nreverse
42 (list
43 (if YaTeX-auto-math-mode nil
44 (cons 'math (cons "Toggle math-mode"
45 '(lambda () (interactive)
46 (YaTeX-switch-mode-menu nil ?t)))))
47 (cons 'mod (cons "Toggle Modify Mode"
48 '(lambda () (interactive)
49 (YaTeX-switch-mode-menu nil ?m))))))))
50 (defvar YaTeX-mode-menu-map-percent (make-sparse-keymap "percent"))
51 (YaTeX-define-menu
52 'YaTeX-mode-menu-map-percent
53 (nreverse
54 '((! "Change LaTeX typesetter(%#!)"
55 . (lambda () (interactive) (YaTeX-%-menu nil nil ?!)))
56 (begend "Set %#BEGIN-%#END on region"
57 . (lambda () (interactive) (YaTeX-%-menu nil nil ?b)))
58 (lpr "Change LPR format"
59 . (lambda () (interactive) (YaTeX-%-menu nil nil ?l))))))
61 (defvar YaTeX-mode-menu-map-jump (make-sparse-keymap "jump"))
62 (YaTeX-define-menu
63 'YaTeX-mode-menu-map-jump
64 (nreverse
65 '((corres "Goto corersponding position" . YaTeX-goto-corresponding-*)
66 (main "Visit main source"
67 . (lambda () (interactive) (YaTeX-visit-main)))
68 (main-other "Visit main source other window"
69 . YaTeX-visit-main-other-window))))
71 (defvar YaTeX-mode-menu-map-comment (make-sparse-keymap "comment"))
72 (YaTeX-define-menu
73 'YaTeX-mode-menu-map-comment
74 (nreverse
75 '((comment "Comment region or environment" . YaTeX-comment-region)
76 (uncomment "Unomment region or environment" . YaTeX-uncomment-region)
77 (commentp "Comment paragraph" . YaTeX-comment-paragraph)
78 (uncommentp "Uncomment paragraph" . YaTeX-uncomment-paragraph))))
80 (YaTeX-define-menu
81 'YaTeX-mode-menu-map
82 (nreverse
83 (list
84 ;; Change/Kill/Fill -------------------------------------------------------
85 (cons (list 'chg "Change") (cons "Change macros" 'YaTeX-change-*))
86 (cons (list 'kill "Kill") (cons "Kill macros" 'YaTeX-kill-*))
87 (cons (list 'fill "Fill") (cons "Fill \\item" 'YaTeX-fill-item))
88 (cons (list 'nl "Newline") (cons "Newline" 'YaTeX-intelligent-newline))
89 ;; ========================================================================
90 (cons (list 'sep1 "---") (cons "---" nil))
91 ;; Comment/Uncomment ------------------------------------------------------
92 (cons (list 'comment "comment") (cons "Comment region or environment"
93 'YaTeX-comment-region))
94 (cons (list 'uncomment "uncomment") (cons "Uncomment region or environment"
95 'YaTeX-uncomment-region))
96 (cons (list 'commentp "commentp") (cons "Comment paragraph"
97 'YaTeX-comment-paragraph))
98 (cons (list 'uncommentp "uncommentp") (cons "Uncomment paragraph"
99 'YaTeX-uncomment-paragraph))
100 ;; ========================================================================
101 (cons (list 'sep2 "---") (cons "---" nil))
102 ;; Jump cursor ------------------------------------------------------------
103 (cons (list 'jump "jump") (cons "Jump Cursor" YaTeX-mode-menu-map-jump))
104 ;; Document hierarchy ---------------------------------------------------
105 (cons (list 'hier "hier") (cons "Display Document hierarchy"
106 'YaTeX-display-hierarchy))
107 ;; What position ----------------------------------------------------------
108 (cons (list 'col "column") (cons "What column in tabular"
109 'YaTeX-what-column))
110 ;; % menu -----------------------------------------------------------------
111 (cons (list 'percent "percent") (cons "Edit %# notation"
112 YaTeX-mode-menu-map-percent))
113 ;; Switch modes -----------------------------------------------------------
114 (cons (list 'mode "mode") (cons "Switching YaTeX's modes"
115 YaTeX-mode-menu-map-modes))
116 ;; ========================================================================
117 (cons (list 'sep "---") (cons "---" nil))
118 ;; Help for LaTeX ---------------------------------------------------------
119 (cons (list 'ap "apr") (cons "Apropos on LaTeX commands" 'YaTeX-apropos))
120 (cons (list 'help "help") (cons "Help on LaTeX commands" 'YaTeX-help))
121 ;; Menu for Typeset relating processes ------------------------------------
122 (cons (list 'process "Process menu")
123 (cons "Process" YaTeX-mode-menu-map-process)))
124 ))
126 ;; Make section-type commands menu -------------------------------------------
127 (defvar YaTeX-mode-menu-map-sectionr
128 (make-sparse-keymap "Enclose region with section-type macro"))
129 (defvar YaTeX-mode-menu-map-section (make-sparse-keymap "Section-type macro"))
130 (let ((sorted-section
131 (sort
132 (delq nil
133 (mapcar (function (lambda (s)
134 (if (> (length (car s)) 5)
135 (car s))))
136 (append section-table user-section-table)))
137 'string<)))
138 (YaTeX-define-menu
139 'YaTeX-mode-menu-map-section
140 (mapcar
141 (function (lambda (secname)
142 (cons (intern secname)
143 (cons secname
144 (list 'lambda ()
145 (list 'interactive)
146 (list 'YaTeX-make-section
147 nil nil nil
148 secname))))))
149 sorted-section))
150 (YaTeX-define-menu
151 'YaTeX-mode-menu-map-sectionr
152 (mapcar
153 (function (lambda (secname)
154 (cons (intern secname)
155 (cons secname
156 (list 'lambda ()
157 (list 'interactive)
158 (list 'YaTeX-make-section
159 nil
160 (list 'region-beginning)
161 (list 'region-end)
162 secname))))))
163 sorted-section)))
165 (YaTeX-define-menu
166 'YaTeX-mode-menu-map
167 (nreverse
168 (list
169 (cons '(sectionr "Section-type (long name)")
170 (cons "Section type" YaTeX-mode-menu-map-section))
171 (cons '(section "Section-type region (long name)")
172 (cons "Section type region (long name)"
173 YaTeX-mode-menu-map-sectionr)))))
175 ;; Make large-type commands menu ---------------------------------------------
176 (defvar YaTeX-mode-menu-map-envr (make-sparse-keymap "Environment region"))
177 (defvar YaTeX-mode-menu-map-env (make-sparse-keymap "Environment"))
179 (let ((sorted-env
180 (sort
181 (mapcar (function (lambda (s) (car s)))
182 (append env-table user-env-table))
183 'string<)))
184 (YaTeX-define-menu
185 'YaTeX-mode-menu-map-env
186 (mapcar
187 (function (lambda (envname)
188 (cons (intern envname)
189 (cons envname
190 (list 'lambda ()
191 (list 'interactive)
192 (list 'YaTeX-insert-begin-end
193 envname nil))))))
194 sorted-env))
195 (YaTeX-define-menu
196 'YaTeX-mode-menu-map-envr
197 (mapcar
198 (function (lambda (envname)
199 (cons (intern envname)
200 (cons envname
201 (list 'lambda ()
202 (list 'interactive)
203 (list 'YaTeX-insert-begin-end
204 envname t))))))
205 sorted-env)))
206 (YaTeX-define-menu
207 'YaTeX-mode-menu-map
208 (nreverse
209 (list
210 (cons '(envr "Environment")
211 (cons "Environment" YaTeX-mode-menu-map-env))
212 (cons '(env "Environment region")
213 (cons "Environment region"
214 YaTeX-mode-menu-map-envr)))))
216 (and (featurep 'xemacs)
217 (add-hook 'yatex-mode-hook
218 '(lambda ()
219 (or (assoc "YaTeX" current-menubar)
220 (progn
221 (set-buffer-menubar (copy-sequence current-menubar))
222 (add-submenu nil YaTeX-mode-menu-map))))))
224 ;; Other key bindings for window-system
225 ;(YaTeX-define-key [?\C- ] 'YaTeX-do-completion)
226 (define-key YaTeX-mode-map [?\M-\C- ] 'YaTeX-mark-environment)
228 ;; Highlightening
229 ;; メニューに比べてこっちは結構本気でやってます。
230 ;; だって文書構造がとっても分かり易いんだもん。
231 ;; みんなも hilit19.el を使おう!
232 ;; とかいってるうちに hilit19 って obsolete になってしまった…
233 ;; …ということで、hilit19 用のパターンを font-lock に変換する関数を
234 ;; 作成してなんとか font-lock にも対応(2000年12月)。
235 ;; しかし、font-lock は仕様が変わりやすい雰囲気でずっと動き続けるか
236 ;; どうかは不明。むしろ進化の止まったhilit19を使い続ける方が安心と
237 ;; 言えないこともないが世の流れは読めず……。
238 ;;
239 ;; さて、まずは対応する {} をピカピカ範囲とするような関数を作る。
240 ;; これは hilit-LaTeX.el を参考にした。でも、ちゃんと section 型コマンドの
241 ;; 引数を数えて正しい位置までピカピカさせるよ〜ん!
243 (defun YaTeX-19-region-section-type (pattern)
244 "Return list of starting and end point of section-type commands of PATTERN."
245 (if (re-search-forward pattern nil t)
246 (let ((m0 (match-beginning 0)) (e0 (match-end 0)) cmd (argc 1))
247 (setq cmd (substring (YaTeX-match-string 0) 1)
248 argc (or (car (cdr (YaTeX-lookup-table cmd 'section))) argc))
249 (if (= argc 0) (cons m0 (point)) ;引数個数0ならマッチした領域
250 (skip-chars-forward " \n\t*")
251 (while (looking-at "\\[") (forward-list 1)) ;optionならスキップ
252 (skip-chars-forward " \n\t")
253 (prog1
254 (if (looking-at "{") ;{}が始まるならちゃんとしたsection型
255 (cons m0
256 (condition-case err
257 (progn
258 ;;(skip-chars-backward "^{") (forward-char -2)
259 (while (> argc 0)
260 (skip-chars-forward "^{")
261 (forward-list 1)
262 (setq argc (1- argc)))
263 (point))
264 (error m0)))
265 ;{}でないならたぶん \verb 環境などにあるダミー
266 (cons m0 e0))
267 ;;move to re-search end not to make font-lock confused
268 (goto-char e0))))))
270 (defun YaTeX-19-region-large-type (pattern)
271 "Return list of large-type contents.
272 Assumes PATTERN begins with `{'."
273 (if (re-search-forward pattern nil t)
274 (let ((m0 (match-beginning 0)) (e0 (match-end 0))p)
275 (goto-char m0)
276 (skip-chars-forward "^ \t\n")
277 (skip-chars-forward " \t\n")
278 (prog1
279 (cons (setq p (point))
280 (condition-case err
281 (progn (goto-char m0) (forward-list 1) (1- (point)))
282 (error (1+ p))))
283 ;;move to re-search end not to make font-lock confused
284 (goto-char e0)))))
286 ;; 些細なことだが % の前の文字もピカリとさせてしまうようで… >hilit19
287 ;; ↓この関数は下の hilit-set-mode-patterns の "[^\\]\\(%\\).*$" に
288 ;; 依存している
289 (defun YaTeX-19-region-comment (pattern)
290 "Return list of comment start and end point."
291 (if (re-search-forward pattern nil t)
292 (cons (match-beginning 2) (match-end 0))))
294 ;;(make-face 'tt)
295 ;;(set-face-font 'tt "-schumacher-clean-medium-r-normal--*-*-*-*-*-*-*-*")
296 ;;(hilit-translate 'tt "white")
298 (defvar YaTeX-hilit-patterns-alist
299 '(
300 ;; comments
301 (YaTeX-19-region-comment "\\([^\\]\\|^\\)\\(%\\).*$" comment)
303 (YaTeX-19-region-section-type "\\\\footnote\\(mark\\|text\\)?\\>" keyword)
304 ("\\\\[a-z]+box" 0 keyword)
305 (YaTeX-19-region-section-type "\\\\\\(v\\|h\\)space\\>" keyword)
307 ;; (re-)define new commands/environments/counters
308 (YaTeX-19-region-section-type
309 "\\\\\\(re\\)?new\\(environment\\|command\\|theorem\\|length\\|counter\\)\\>"
310 defun)
311 (YaTeX-19-region-section-type
312 "\\\\textbf\\>" bold)
314 ;; various declarations/definitions
315 (YaTeX-19-region-section-type
316 "\\\\\\(set\\|setto\\|addto\\)\\(length\\|width\\|counter\\)\\>"
317 define)
318 (YaTeX-19-region-section-type
319 "\\\\\\(title\\|author\\|date\\|thanks\\)\\>" define)
321 ("\\\\document\\(style\\|class\\)\\(\\[.*\\]\\)?{" "}" decl)
322 ("\\\\\\(begin\\|end\\|nofiles\\|includeonly\\){" "}" decl)
323 ("\\\\\\(raggedright\\|makeindex\\|makeglossary\\|maketitle\\)\\b" 0 decl)
324 ("\\\\\\(pagestyle\\|thispagestyle\\|pagenumbering\\){" "}" decl)
325 ("\\\\\\(normalsize\\|small\\|footnotesize\\|scriptsize\\|tiny\\|large\\|Large\\|LARGE\\|huge\\|Huge\\)\\b" 0 decl)
326 ("\\\\\\(appendix\\|tableofcontents\\|listoffigures\\|listoftables\\)\\b"
327 0 decl)
328 ("\\\\\\(bf\\|em\\|it\\|rm\\|sf\\|sl\\|ss\\|tt\\)\\b" 0 decl)
330 ;; label-like things
331 ;;this should be customized by YaTeX-item-regexp
332 ("\\\\\\(sub\\)*item\\b\\(\\[[^]]*\\]\\)?" 0 label)
333 (YaTeX-19-region-section-type
334 "\\\\caption\\(\\[[^]]*\\]\\)?\\>" label)
336 ;; things that do some sort of cross-reference
337 (YaTeX-19-region-section-type
338 "\\\\\\(\\(no\\)?cite\\|\\(page\\)?ref\\|label\\|index\\|glossary\\)\\>"
339 crossref)
341 ;; things that bring in external files
342 ("\\\\\\(include\\|input\\|bibliography\\){" "}" include)
344 ;; formulas
345 ("[^\\]\\\\(" "\\\\)" formula) ; \( \)
346 ("[^\\]\\\\\\[" "\\\\\\]" formula) ; \[ \]
347 ("\\\\begin{\\(eqn\\|equation\\|x?x?align\\|split\\|multline\\|gather\\)"
348 "\\\\end{\\(eqn\\|equation\\|x?x?align\\|split\\|multline\\|gather\\).*}"
349 formula)
350 ("\\([^\\$]\\|^\\)\\($\\($[^$]*\\$\\|[^$]*\\)\\$\\)" 2 formula); '$...$' or '$$...$$'
352 ;; "wysiwyg" emphasis -- these don't work on nested expressions
353 (YaTeX-19-region-large-type "{\\\\\\(em\\|it\\|sl\\)" italic)
354 (YaTeX-19-region-large-type "{\\\\bf" bold)
355 ;;;(YaTeX-19-region-large-type "{\\\\tt" tt)
356 ;;;("\\\\begin{verbatim" "\\\\end{verbatim" tt)
358 ("``" "''" string))
359 "*Hiliting pattern alist for LaTeX text.")
361 ;;(defvar YaTeX-hilit-pattern-adjustment-default nil)
362 ;; ↑いらなくなった。
363 (defvar YaTeX-hilit-pattern-adjustment-private nil
364 "*Adjustment hilit-pattern-alist for default yatex-mode's pattern.")
365 (defvar YaTeX-hilit-sectioning-face
366 '(yellow/dodgerblue yellow/slateblue)
367 "*Hilightening face for sectioning unit. '(FaceForLight FaceForDark)")
368 (defvar YaTeX-hilit-sectioning-attenuation-rate
369 '(15 40)
370 "*Maximum attenuation rate of sectioning face. '(ForeRate BackRate)
371 Each rate specifies how much portion of RGB value should be attenuated
372 towards to lowest sectioning unit. Numbers should be written in percentage.")
373 (defvar YaTeX-sectioning-patterns-alist nil
374 "Hilightening patterns for sectioning units.")
375 (defvar YaTeX-hilit-singlecmd-face
376 '("slateblue2" . "aquamarine")
377 "*Hilightening face for maketitle type. '(FaceForLight FaceForDark)")
379 ;;; セクションコマンドを、構造レベルの高さに応じて色の濃度を変える
380 ;;; 背景が黒でないと何が嬉しいのか分からないに違いない.
381 ;;; もしかして白地の時は構造レベルに応じて色を明るくしたほうが良いのか?
382 ;;; ...どうやらそうでもないらしい。これでいいみたい(2000/12)。
383 ;(if (fboundp 'win32-color-values)
384 ; (fset 'x-color-values 'win32-color-values))
386 (defun YaTeX-19-create-face (sym fgcolor &optional bgcolor)
387 "Create face named SYM with face of FGCOLOR/BGCOLOR."
388 (cond
389 ((and YaTeX-use-font-lock (fboundp 'defface))
390 (custom-declare-face
391 sym
392 (list
393 (list (list
394 '(class color)
395 ;(list 'background YaTeX-background-mode)
396 )
397 (delq nil
398 (append
399 (list ':foreground fgcolor)
400 (if bgcolor
401 (list ':background bgcolor))
402 ))
403 )
404 (list t (list ':bold t ':underline t))
405 )
406 (format "Font lock face for %s" sym)
407 ':group 'font-lock-faces)
408 (set sym sym)
409 sym)
410 ((and YaTeX-use-hilit19 (and (fboundp 'hilit-translate)))
411 (let ((face (intern (concat fgcolor "/" bgcolor))))
412 (hilit-translate sym face)
413 face))))
415 (cond
416 (YaTeX-use-highlighting
417 (cond
418 (window-system
419 (let*((sectface
420 (car (if (eq YaTeX-background-mode 'dark)
421 (cdr YaTeX-hilit-sectioning-face)
422 YaTeX-hilit-sectioning-face)))
423 (sectcol (symbol-name sectface))
424 (fl YaTeX-use-font-lock)
425 (form (if fl "#%02x%02x%02x" "hex-%02x%02x%02x"))
426 sect-pat-alist)
427 (if (string-match "/" sectcol)
428 (let ((fmin (nth 0 YaTeX-hilit-sectioning-attenuation-rate))
429 (bmin (nth 1 YaTeX-hilit-sectioning-attenuation-rate))
430 colorvalue fR fG fB bR bG bB pat fg bg level from face list lm)
431 (require 'yatexsec)
432 (setq fg (substring sectcol 0 (string-match "/" sectcol))
433 bg (substring sectcol (1+ (string-match "/" sectcol)))
434 colorvalue (x-color-values fg)
435 fR (/ (nth 0 colorvalue) 256)
436 fG (/ (nth 1 colorvalue) 256)
437 fB (/ (nth 2 colorvalue) 256)
438 colorvalue (x-color-values bg)
439 bR (/ (nth 0 colorvalue) 256)
440 bG (/ (nth 1 colorvalue) 256)
441 bB (/ (nth 2 colorvalue) 256)
442 lm YaTeX-sectioning-max-level
443 list YaTeX-sectioning-level)
444 (while list
445 (setq pat (concat YaTeX-ec-regexp (car (car list))
446 ;;"\\*?\\(\\[[^]]*\\]\\)?\\>" ;改行はさむと駄目
447 "\\>"
448 )
449 level (cdr (car list))
450 fg (format form
451 (- fR (/ (* level fR fmin) lm 100))
452 (- fG (/ (* level fG fmin) lm 100))
453 (- fB (/ (* level fB fmin) lm 100)))
454 bg (format form
455 (- bR (/ (* level bR bmin) lm 100))
456 (- bG (/ (* level bG bmin) lm 100))
457 (- bB (/ (* level bB bmin) lm 100)))
458 from (intern (format "YaTeX-sectioning-%d" level))
459 ;;face (intern (concat fg "/" bg))
460 )
461 (setq face (YaTeX-19-create-face from fg bg))
462 (setq sect-pat-alist
463 (cons;;(list pat "}" face)
464 (list 'YaTeX-19-region-section-type pat face)
465 sect-pat-alist))
466 (setq list (cdr list)))
467 (setq YaTeX-sectioning-patterns-alist sect-pat-alist)))))
468 (t ;not window-system
469 (setq YaTeX-sectioning-patterns-alist
470 (list
471 (list
472 (concat YaTeX-ec-regexp
473 "\\(\\(sub\\)*\\(section\\|paragraph\\)\\|chapter"
474 "\\|part\\){[^}]*}")
475 0
476 'define)))))))
478 ;; ローカルなマクロを読み込んだ後 redraw すると
479 ;; ローカルマクロを keyword として光らせる(keywordじゃまずいかな…)。
480 (defvar hilit-patterns-alist nil) ;for absence of hilit19
482 (defun YaTeX-19-collect-macros ()
483 (cond
484 (YaTeX-use-highlighting
485 (let ((get-face
486 (function
487 (lambda (table)
488 (cond
489 ((eq YaTeX-background-mode 'light) (car table))
490 ((eq YaTeX-background-mode 'dark) (cdr table))
491 (t nil)))))
492 sect single)
493 (YaTeX-19-create-face ;;hilit-translate
494 ;;sectioning (funcall get-face YaTeX-hilit-sectioning-face)
495 'macro (funcall get-face YaTeX-hilit-singlecmd-face))
496 (if (setq sect (append user-section-table tmp-section-table))
497 (setq sect (concat "\\\\\\("
498 (mapconcat
499 (function
500 (lambda (s) (regexp-quote (car s))))
501 sect
502 "\\|")
503 "\\)\\>")))
504 (if (setq single (append user-singlecmd-table tmp-singlecmd-table))
505 (setq single (concat "\\\\\\("
506 (mapconcat
507 (function (lambda (s) (regexp-quote (car s))))
508 single
509 "\\|")
510 "\\)\\b")))
511 (setq hilit-patterns-alist ;Remove at first.
512 (delq (assq 'yatex-mode hilit-patterns-alist) hilit-patterns-alist)
513 hilit-patterns-alist
514 (cons
515 (cons 'yatex-mode
516 (append
517 (list nil)
518 YaTeX-sectioning-patterns-alist
519 YaTeX-hilit-pattern-adjustment-private
520 ;;YaTeX-hilit-pattern-adjustment-default
521 YaTeX-hilit-patterns-alist
522 (delq nil
523 (list
524 (if sect (list
525 'YaTeX-19-region-section-type
526 sect
527 'keyword))
528 (if single (list single 0 'macro))))))
529 hilit-patterns-alist))))))
530 ;;(YaTeX-19-collect-macros) ;causes an error
531 (defun YaTeX-hilit-recenter (arg)
532 "Collect current local macro and hilit-recenter."
533 (interactive "P")
534 (YaTeX-19-collect-macros)
535 (hilit-recenter arg))
536 (defvar YaTeX-19-recenter-function
537 (cond
538 (YaTeX-use-hilit19 (cons 'YaTeX-hilit-recenter 'hilit-recenter))
539 (YaTeX-use-font-lock (cons 'YaTeX-font-lock-recenter 'recenter))
540 (t nil)))
542 (if YaTeX-19-recenter-function
543 (let ((k (where-is-internal (cdr YaTeX-19-recenter-function))))
544 (while k
545 (define-key YaTeX-mode-map (car k) (car YaTeX-19-recenter-function))
546 (setq k (cdr k)))))
548 (defun YaTeX-font-lock-recenter (&optional arg)
549 (interactive "P")
550 (setq YaTeX-font-lock-keywords
551 (YaTeX-convert-pattern-hilit2fontlock
552 (cdr (assq 'yatex-mode (YaTeX-19-collect-macros))))
553 font-lock-keywords nil)
554 ;(save-excursion
555 ; (font-lock-fontify-region (window-start) (window-end)))
556 (font-lock-mode -1) ;is stupid, but sure.
557 (font-lock-mode 1))
559 (defvar YaTeX-font-lock-keywords nil
560 "Pattern-face alist of yahtml-mode for font-lock")
562 (defun YaTeX-font-lock-set-default-keywords ()
563 (put 'yatex-mode 'font-lock-defaults
564 (list 'YaTeX-font-lock-keywords nil nil))
565 (setq YaTeX-font-lock-keywords
566 (YaTeX-convert-pattern-hilit2fontlock
567 (cons nil
568 (append YaTeX-sectioning-patterns-alist
569 YaTeX-hilit-pattern-adjustment-private
570 YaTeX-hilit-patterns-alist)))))
572 (if YaTeX-use-font-lock
573 (progn
574 (if (and (boundp 'hilit-mode-enable-list) hilit-mode-enable-list)
575 ;;for those who use both hilit19 and font-lock
576 (if (eq (car hilit-mode-enable-list) 'not)
577 (or (member 'yatex-mode hilit-mode-enable-list)
578 (nconc hilit-mode-enable-list (list 'yatex-mode)))
579 (setq hilit-mode-enable-list
580 (delq 'yatex-mode hilit-mode-enable-list))))
581 (YaTeX-font-lock-set-default-keywords)))
583 (defun YaTeX-switch-to-new-window ()
584 (let ((c 0) (i 1) (free (make-string win:max-configs ? )))
585 (while (< i win:max-configs)
586 (or (aref win:configs i) (aset free i (+ i win:base-key)))
587 (setq i (1+ i)))
588 (while (not (string-match (char-to-string c) free))
589 (message "Which window to create? [%s]: " free)
590 (setq c (read-char)))
591 (message "Creating window [%c]" c)
592 (set-buffer (get-buffer-create "*scratch*"))
593 (win:switch-window (- c win:base-key))))
595 (defun YaTeX-visit-main-other-frame ()
596 "Visit main file in other frame.
597 WARNING, This code is not perfect."
598 (interactive)
599 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
600 (let (parent)
601 (save-excursion (YaTeX-visit-main t) (setq parent (current-buffer)))
602 (cond
603 ((get-buffer-window parent t)
604 (goto-buffer-window parent))
605 ((and (featurep 'windows) win:use-frame)
606 (YaTeX-switch-to-new-window)
607 (switch-to-buffer parent))
608 (t (switch-to-buffer-other-frame (buffer-name parent)))))))
610 (defun YaTeX-goto-corresponding-*-other-frame (arg)
611 "Go to corresponding object in other frame."
612 (interactive "P")
613 (let (b p)
614 (save-window-excursion
615 (save-excursion
616 (YaTeX-goto-corresponding-* arg)
617 (setq b (current-buffer) p (point))))
618 (cond
619 ((get-buffer-window b t)
620 (goto-buffer-window b)
621 (goto-char p))
622 ((and (featurep 'windows) win:use-frame)
623 (YaTeX-switch-to-new-window)
624 (switch-to-buffer b)
625 (goto-char p))
626 (t (switch-to-buffer-other-frame (buffer-name b))
627 (goto-char p)))))
629 ;;; reverseVideo にして hilit-background-mode を 'dark
630 ;;; にしている人は数式などが暗くなりすぎて見づらいかもしれない。
631 ;;; 次のコードを hilit19 をロードしている場所の直後に置くとちょっ
632 ;;; とはまし。
633 ;;; (if (eq hilit-background-mode 'dark)
634 ;;; (hilit-translate
635 ;;; string 'mediumspringgreen
636 ;;; formula 'khaki
637 ;;; label 'yellow-underlined))
638 (and YaTeX-emacs-19
639 (not (featurep 'xemacs))
640 (boundp 'byte-compile-current-file)
641 byte-compile-current-file
642 (progn
643 (if YaTeX-emacs-20 (require 'font-lock))
644 (if (and (boundp 'window-system) window-system)
645 (require 'hilit19)
646 (error "Byte compile this file on window system! Not `-nw'!"))))
648 (provide 'yatex19)
651 ; Local variables:
652 ; fill-prefix: ";;; "
653 ; paragraph-start: "^$\\| \\|;;;$"
654 ; paragraph-separate: "^$\\| \\|;;;$"
655 ; buffer-file-coding-system: sjis
656 ; End: