yatex

view yatex19.el @ 79:0734be649cb8

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