yatex

view yatexmth.el @ 53:5f4b18da14b3

Fix functions relating YaTeX-beginning-of-environment or YaTeX-end-of-environment. Line indentation by TAB much improved. Functions that work at enclosing environments, YaTeX-enclose-<ENVNAME>, introduced. Functions for enclosing verbatim and equations are supplied. SPC, DEL, +, - in YaTeX-hierarchy buffer. Compensate odd highlighting of hilit19.
author yuuji
date Thu, 02 Feb 1995 17:18:29 +0000
parents 5d94deabb9f9
children a9653fbd1c1c
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX math-mode-specific functions.
3 ;;; yatexmth.el rev.4
4 ;;; (c )1993-1995 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
5 ;;; Last modified Fri Jan 27 23:57:40 1995 on VFR
6 ;;; $Id$
8 ;;; [Customization guide]
9 ;;;
10 ;;; By default, you can use two completion groups in YaTeX math
11 ;;; mode, `;' for mathematical signs and `:' for greek letters. But
12 ;;; you can add other completion groups by defining the alist of
13 ;;; `prefix key' vs `completion list' into the variable
14 ;;; YaTeX-math-key-list-private. If you wish to accomplish the
15 ;;; completion as follows(prefix key is `,'):
16 ;;;
17 ;;; KEY COMPLETION
18 ;;; s \sin
19 ;;; S \arcsin
20 ;;; c \cos
21 ;;; C \arccos
22 ;;; :
23 ;;; T \arctan
24 ;;; l \log
25 ;;; hs \sinh
26 ;;;
27 ;;; Typing `s' after `,' makes `\sin', `hs' after `,' makes `\sinh'
28 ;;; and so on. First, you have to define list of key-completion
29 ;;; pairs. Variable name(YaTeX-math-funcs-list) is arbitrary.
30 ;;;
31 ;;; (setq YaTeX-math-funcs-list
32 ;;; '(("s" "sin")
33 ;;; ("S" "arcsin")
34 ;;; :
35 ;;; ("hs" "sinh")))
36 ;;;
37 ;;; Next, define the list of prefix-key vs completion list(defined
38 ;;; above) into the variable YaTeX-math-key-list-private.
39 ;;;
40 ;;; (setq YaTeX-math-key-list-private
41 ;;; '(("," . YaTeX-math-funcs-list)
42 ;;; ("'" . Other-List-if-any)))
43 ;;;
44 ;;; Put these expressions into your ~/.emacs, and you can use this
45 ;;; completion in the math-mode.
46 ;;;
47 ;;; And you can add your favorite completion sequences to the
48 ;;; default completion list invoked with `;', by defining those lists
49 ;;; into variable YaTeX-math-sign-alist-private.
51 ;;; 【イメージ補完の追加方法】
52 ;;;
53 ;;; 標準のイメージ補完では、「;」で始まる数式記号補完と、「:」で始
54 ;;; まるギリシャ文字補完が使用可能ですが、これ以外の文字で始まる補完
55 ;;; シリーズも定義することができます。例えば、「,」で始まる次のよう
56 ;;; な補完シリーズを定義する場合を考えてみます。
57 ;;;
58 ;;; 補完キー 補完結果
59 ;;; s \sin
60 ;;; S \arcsin
61 ;;; c \cos
62 ;;; C \arccos
63 ;;; :
64 ;;; T \arctan
65 ;;; l \log
66 ;;; hs \sinh
67 ;;;
68 ;;; 「,」のあとに s を押すと \sin が、hs を押すと \sinh が入力されま
69 ;;; す。このような補完リストの登録は以下のようにします(変数名は任意)。
70 ;;;
71 ;;; (setq YaTeX-math-funcs-list
72 ;;; '(("s" "sin")
73 ;;; ("S" "arcsin")
74 ;;; :
75 ;;; ("hs" "sinh")))
76 ;;;
77 ;;; さらに、「,」を押した時にイメージ補完が始まるよう次の変数に、起動キー
78 ;;; と上で定義した補完用変数の登録を行ないます。
79 ;;;
80 ;;; (setq YaTeX-math-key-list-private
81 ;;; '(("," . YaTeX-math-funcs-list)
82 ;;; ("'" . ほかに定義したいシリーズがあれば…)))
83 ;;;
84 ;;; これらを ~/.emacs に書いておけば、math-mode で自分専用のイメージ
85 ;;; 補完が利用できます。
87 (defvar YaTeX-jisold
88 (and (boundp 'dos-machine-type)
89 (eq dos-machine-type 'pc98)))
91 (defmacro YaTeX-setq-math-sym (sym old new)
92 (list 'setq sym (list 'if 'YaTeX-jisold old new)))
94 (YaTeX-setq-math-sym YaTeX-image-in "E" "∈")
95 (YaTeX-setq-math-sym YaTeX-image-ni "ヨ" "∋")
96 (YaTeX-setq-math-sym YaTeX-image-subset " _\n(\n ~" "⊂")
97 (YaTeX-setq-math-sym YaTeX-image-subseteq " _\n(_\n ~" "⊆")
98 (YaTeX-setq-math-sym YaTeX-image-supset "_\n )\n~" "⊃")
99 (YaTeX-setq-math-sym YaTeX-image-supseteq "_\n_)\n~" "⊇")
100 (YaTeX-setq-math-sym YaTeX-image-nabla "___\n\\\\/" "∇")
101 (YaTeX-setq-math-sym YaTeX-image-partial " -+\n+-+\n+-+" "∂")
102 (YaTeX-setq-math-sym YaTeX-image-dagger "+\n|" "†")
103 (YaTeX-setq-math-sym YaTeX-image-ddagger "+\n+\n|" "‡")
104 (YaTeX-setq-math-sym YaTeX-image-equiv "=\n ̄" "≡")
105 (YaTeX-setq-math-sym YaTeX-image-int " /\\\n \\\n\\/" "∫")
106 (YaTeX-setq-math-sym YaTeX-image-bot "|\n ̄" "⊥")
107 (YaTeX-setq-math-sym YaTeX-image-neg "イ" "¬")
108 (YaTeX-setq-math-sym YaTeX-image-flat "b" "♭")
109 (YaTeX-setq-math-sym YaTeX-image-sqrt "" "√")
111 (defvar
112 YaTeX-math-sign-alist-default
113 '(
114 ;frequently used
115 ("||" "|" ("||" "‖"))
116 ("sum" "sum" ("\\-+\n >\n/-+" "Σ"))
117 ("sigma" "sum" ("\\-+\n >\n/-+" "Σ"))
118 ("integral" "int" (" /\\\n \\\n\\/" YaTeX-image-int))
119 ("ointegral" "oint" " /\\\n(\\)\n\\/")
120 ("sqrt" "sqrt" (" __\n,/" YaTeX-image-sqrt))
121 ("root" "sqrt" (" __\n,/" YaTeX-image-sqrt))
122 ("A" "forall" "|_|\nV")
123 ("E" "exists" "-+\n-+\n-+")
124 ("!" "neg" ("--+\n |" YaTeX-image-neg))
125 ("oo" "infty" ("oo" "∞"))
126 ("\\" "backslash" ("\\" "\"))
128 ;;binary operators
129 ("+-" "pm" ("+\n-" "±"))
130 ("-+" "mp" "-\n+")
131 ("x" "times" ("x" "×"))
132 ("/" "div" (",\n-\n'" "÷"))
133 ("f" "frac" "xxx\n---\nyyy" "÷")
134 ("*" "ast" "*")
135 ("#" "star" ("_/\\_\n\\ /\n//\\\\" "★"))
136 ("o" "circ" "o")
137 ("o*" "bullet" " _\n(*)\n ~")
138 ("." "cdot" ".")
139 ("cap" "cap" "/-\\\n| |")
140 ("cup" "cup" "| |\n\\-/")
141 ("u+" "uplus" "|+|\n\\-/")
142 ("|~|" "sqcap" "|~|")
143 ("|_|" "sqcup" "|_|")
144 ("v" "vee" "v")
145 ("^" "wedge" "^")
146 ("\\\\" "setminus" "\\")
147 (")(" "wr" " )\n(")
148 ("<>" "diamond" "<>")
149 ("/\-" "bigtriangleup" ("/\\\n~~" "△"))
150 ("-\\/" "bigtriangledown" ("__\n\\/" "▽"))
151 ("<|" "triangleleft" "<|")
152 ("|>" "triangleright" "|>")
153 ("<||" "lhd" "/|\n\\|")
154 ("||>" "rhd" "|\\\n|/")
155 ("<|-" "unlhd" "<|\n~~")
156 ("|>-" "unrhd" "|>\n~~")
157 ("o+" "oplus" " _\n(+)\n ~")
158 ("o-" "ominus" " _\n(-)\n ~")
159 ("ox" "otimes" " _\n(x)\n ~")
160 ("o/" "oslash" " _\n(/)\n ~")
161 ("o." "odot" "(.)")
162 ("O" "bigcirc" "O")
163 ("t" "dagger" ("+\n|" YaTeX-image-dagger))
164 ("tt" "ddagger" ("+\n+\n|" YaTeX-image-ddagger))
165 ("II" "amalg" "II")
166 ; :
167 ;;relational operators
168 ("<" "leq" ("<\n-" "≦"))
169 (">" "geq" (">\n-" "≧"))
170 ("-=" "equiv" ("=\n-" YaTeX-image-equiv))
171 ("=-" "equiv" ("=\n-" YaTeX-image-equiv))
172 ("---" "equiv" ("=\n-" YaTeX-image-equiv))
173 ("(" "subset" (" _\n(\n ~" YaTeX-image-subset))
174 ("(-" "subseteq" (" _\n(_\n ~" YaTeX-image-subseteq))
175 (")" "supset" ("_\n )\n~" YaTeX-image-supset))
176 (")-" "supseteq" ("_\n_)\n~" YaTeX-image-supseteq))
177 ("[" "sqsubset" "[")
178 ("[-" "sqsubseteq" "[\n~")
179 ("]" "sqsupset" "]")
180 ("]-" "sqsupseteq" "]\n~")
181 ("{" "in" ("(-" YaTeX-image-in))
182 ("}" "ni" ("-)" YaTeX-image-ni))
183 ("|-" "vdash" "|-")
184 ("-|" "dashv" "-|")
185 ("~" "sim" "~(tild)")
186 ("~-" "simeq" "~\n-")
187 ("asymp" "asymp" "v\n^")
188 ("~~" "approx" "~\n~")
189 ("~=" "cong" "~\n=")
190 ("=/" "neq" ("=/=" "≠"))
191 (".=" "doteq" ".\n=")
192 ("o<" "propto" "o<")
193 ("|=" "models" "|=")
194 ("_|_" "perp" "_|_")
195 ("|" "mid" "|")
196 ("||" "parallel" "||")
197 ("bowtie" "bowtie" "|><|(wide)")
198 ("|><|" "join" "|><|")
199 ("\\_/" "smile" "\\_/")
200 ("/~\\" "frown" "/~~\\")
201 ("-<" "prec" ("-<" "く"))
202 ("-<=" "preceq" ("-<\n-" "く\n="))
203 ("<<" "ll" ("<<" "《"))
204 ; :
205 ;;arrows
206 ("<-" "leftarrow" ("<-" "←"))
207 ("\C-b" "leftarrow" ("<-" "←"))
208 ("<--" "longleftarrow" ("<--" "←--"))
209 ("<=" "Leftarrow" "<=")
210 ("<==" "Longleftarrow" "<==")
211 ("->" "rightarrow" ("->" "→"))
212 ("\C-f" "rightarrow" ("->" "→"))
213 ("-->" "longrightarrow" ("-->" "--→"))
214 ("==>" "Longrightarrow" "==>")
215 ("<->" "leftrightarrow" ("<->" "←→"))
216 ("<-->" "longleftrightarrow" ("<---->" "←--→"))
217 ("<=>" "Leftrightarrow" "<=>")
218 ("<==>" "Longleftrightarrow" "<==>")
219 ("^|" "uparrow" ("^\n|" "↑"))
220 ("\C-p" "uparrow" ("^\n|" "↑"))
221 ("^||" "Uparrow" "/\\\n||")
222 ("\C-n" "downarrow" ("|\nv" "↓"))
223 ("v|" "downarrow" ("|\nv" "↓"))
224 ("v||" "Downarrow" "||\n\\/")
225 ("|->" "mapsto" ("|->" "|→"))
226 ("<-)" "hookleftarrow" (" ,\n<--+" " ヽ\n<--/"))
227 ("/-" "leftharpoonup" "/\n~~~")
228 ("\\-" "leftharpoondown" "__\n\\")
229 ("-/" "rightharpoondown" "__\n/")
230 ("-\\" "rightharpoonup" "~~\n\\")
231 ;;left and right
232 ("left" "left" "(leftmark)")
233 ("right" "right" "(rightmark)")
234 ;other marks
235 ("Z" "aleph" "|\\|")
236 ("|\\|" "aleph" "|\\|")
237 ("h-" "hbar" "_\nh")
238 ("i" "imath" "i")
239 ("j" "jmath" "j")
240 ("l" "ell" "l")
241 ("wp" "wp" "???")
242 ("R" "Re" ")R")
243 ("Im" "Im" "???")
244 ("mho" "mho" "~|_|~")
245 ("'" "prime" "'")
246 ("0" "emptyset" "0")
247 ("nabla" "nabla" ("___\n\\\\/" YaTeX-image-nabla))
248 ("\\/" "surd" "-\\/")
249 ("surd" "surd" "-\\/")
250 ("top" "top" "T")
251 ("bot" "bot" ("_|_" YaTeX-image-bot))
252 ("b" "flat" ("b" YaTeX-image-flat))
253 ("LT" "natural" "|\nLT\n |")
254 ("6" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
255 ("partial" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
256 ("round" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
257 ("[]" "box" "[]")
258 ("Diamond" "Diamond" "/\\\n\\/")
259 ("3" "triangle" "/\\\n~~")
260 ("C" "clubsuit" " o\no+o\n |")
261 ("D" "diamondsuit" "/\\\n\\/")
262 ("H" "heartsuit" "<^^>\n \\/")
263 ("S" "spadesuit" " /\\\n<++>\n /\\")
264 )
265 "Default LaTeX-math-command alist.")
267 (defvar YaTeX-math-sign-alist-private nil
268 "*User definable key vs LaTeX-math-command alist.")
270 (defvar YaTeX-math-quit-with-strict-match nil
271 "*T for quitting completion as soon as strict-match is found.")
272 (defvar YaTeX-math-sign-alist
273 (append YaTeX-math-sign-alist-private YaTeX-math-sign-alist-default))
275 ;;(defun YaTeX-math-alist2array (alist array)
276 ;; (set array
277 ;; (let ((array (make-vector (length alist) "")) (list alist) (i 0))
278 ;; (while list
279 ;; (aset array i (car (car list)))
280 ;; (setq i (1+ i) list (cdr list)))
281 ;; array))
282 ;;)
284 (defvar YaTeX-greek-key-alist-default
285 '(
286 ("a" "alpha" ("a" "α"))
287 ("b" "beta" ("|>\n|>\n|" "β"))
288 ("g" "gamma" ("~r" "γ"))
289 ("G" "Gamma" ("|~" "Γ"))
290 ("d" "delta" ("<~\n<>" "δ"))
291 ("D" "Delta" ("/\\\n~~" "Δ"))
292 ("e" "epsilon" "<\n<~")
293 ("e-" "varepsilon" ("(\n(~" "ε"))
294 ("z" "zeta" ("(~\n >" "ζ"))
295 ("et" "eta" ("n\n/" "η"))
296 ("th" "theta" ("8" "θ"))
297 ("Th" "Theta" ("(8)" "Θ"))
298 ("th-" "vartheta" ("-8" "-θ"))
299 ("i" "iota" ("i\n\\_/" "ι"))
300 ("k" "kappa" ("k" "κ"))
301 ("l" "lambda" ("\\n/\\" "λ"))
302 ("L" "Lambda" ("/\\" "Λ"))
303 ("m" "mu" (" u_\n/" "μ"))
304 ("n" "nu" ("|/" "ν"))
305 ("x" "xi" ("E\n >" "ξ"))
306 ("X" "Xi" ("---\n -\n---" "Ξ"))
307 ("p" "pi" ("__\n)(" "π"))
308 ("P" "Pi" ("__\n||" "Π"))
309 ("p-" "varpi" ("_\nw" "__\nω"))
310 ("r" "rho" ("/O" "ρ"))
311 ("r-" "varrho" ("/O\n~~" "ρ\n~~"))
312 ("s" "sigma" ("o~" "σ"))
313 ("S" "Sigma" ("\\-+\n >\n/-+" "Σ"))
314 ("s-" "varsigma" "(~~ \n>")
315 ("t" "tau" ("__\n(" "τ"))
316 ("u" "upsilon" ("~v" "υ"))
317 ("y" "upsilon" ("~v" "υ"))
318 ("U" "Upsilon" ("~Y~" "Υ"))
319 ("Y" "Upsilon" ("~Y~" "Υ"))
320 ("ph" "phi" (" /\n(/)\n/" "φ"))
321 ("Ph" "Phi" (" _\n(|)\n ~" "Φ"))
322 ("ph-" "varphi" "\\O\n|")
323 ("c" "chi" ("x" "χ"))
324 ("ps" "psi" ("\\|/\\n |" "ψ"))
325 ("Ps" "Psi" (" ~\n\\|/\\n |" "Ψ"))
326 ("o" "omega" ("w" "ω"))
327 ("w" "omega" ("w" "ω"))
328 ("O" "Omega" ("(~)\n~ ~" "Ω"))
329 ("W" "Omega" ("(~)\n~ ~" "Ω"))
330 ("f" "foo")
331 )
332 "Default LaTeX-math-command alist.")
334 (defvar YaTeX-greek-key-alist-private nil
335 "*User definable key vs LaTeX-math-command alist.")
337 (defvar YaTeX-greek-key-alist
338 (append YaTeX-greek-key-alist-private YaTeX-greek-key-alist-default))
340 ;;(mapcar (function (lambda (x) (YaTeX-math-alist2array x)))
341 ;; YaTeX-math-key-list)
343 (defvar YaTeX-math-indicator "KEY\tLaTeX sequence\t\tsign")
345 (defvar YaTeX-math-need-image t
346 "*T for displaying pseudo image momentarily.")
347 (defvar YaTeX-math-max-key 8)
348 (defvar YaTeX-math-max-seq
349 (* 8 (1+ (/ (length "\\longleftrightarrow") 8))))
350 (defvar YaTeX-math-max-sign 5)
351 (defvar YaTeX-math-sign-width
352 (+ YaTeX-math-max-key YaTeX-math-max-seq YaTeX-math-max-sign))
353 (defvar YaTeX-math-display-width
354 (* 8 (1+ (/ YaTeX-math-sign-width 8))))
355 (defvar YaTeX-math-menu-map nil
356 "Keymap used in YaTeX mathematical sign menu mode."
357 )
358 (if YaTeX-math-menu-map nil
359 (setq YaTeX-math-menu-map (make-sparse-keymap))
360 (define-key YaTeX-math-menu-map "n" 'next-line)
361 (define-key YaTeX-math-menu-map "p" 'previous-line)
362 (define-key YaTeX-math-menu-map "f" 'YaTeX-math-forward)
363 (define-key YaTeX-math-menu-map "b" 'YaTeX-math-backward)
364 (define-key YaTeX-math-menu-map "v" 'scroll-up)
365 (define-key YaTeX-math-menu-map " " 'scroll-up)
366 (define-key YaTeX-math-menu-map "c" 'scroll-up)
367 (define-key YaTeX-math-menu-map "V" 'scroll-down)
368 (define-key YaTeX-math-menu-map "r" 'scroll-down)
369 (define-key YaTeX-math-menu-map "\^h" 'scroll-down)
370 (define-key YaTeX-math-menu-map "<" 'beginning-of-buffer)
371 (define-key YaTeX-math-menu-map ">" 'end-of-buffer)
372 (define-key YaTeX-math-menu-map "\^m" 'exit-recursive-edit)
373 (define-key YaTeX-math-menu-map "q" 'abort-recursive-edit))
375 (defvar YaTeX-math-exit-key "\e"
376 "*Key sequence after prefix key of YaTeX-math-mode to exit from math-mode."
377 )
379 (defmacro YaTeX-math-japanese-sign (list)
380 (list 'nth 1 list))
382 (defvar YaTeX-math-cmd-regexp (concat (regexp-quote YaTeX-ec) "[A-z]"))
383 (defvar YaTeX-math-verbatim-environments
384 '("alltt")
385 "*List of environments in which LaTeX math mode is disabled.
386 This value is appended with YaTeX-verbatim-environments.")
388 ;;;
389 ;;YaTeX math-mode functions
390 ;;;
391 ;;;###autoload from yatex.el
392 (defun YaTeX-toggle-math-mode (&optional arg)
393 (interactive "P")
394 (or (memq 'YaTeX-math-mode mode-line-format) nil
395 (setq mode-line-format
396 (append (list "" 'YaTeX-math-mode) mode-line-format)))
397 (if YaTeX-auto-math-mode nil ;Only effective on manual mode.
398 (if (or arg (null YaTeX-math-mode))
399 (let (keys)
400 (setq YaTeX-math-mode "math:")
401 (message "Turn on math mode. Prefix keys are %s"
402 (mapconcat 'car YaTeX-math-key-list " "))
403 (sit-for 3)
404 (message
405 (concat "To exit from math-mode, type `ESC' after prefix, "
406 "or type `"
407 (key-description
408 (car
409 (where-is-internal
410 'YaTeX-switch-mode-menu YaTeX-mode-map)))
411 " $'")))
412 (setq YaTeX-math-mode nil)
413 (message "Exit from math mode."))
414 (set-buffer-modified-p (buffer-modified-p)))
415 )
417 (defun YaTeX-math-forward (arg)
418 (interactive "p")
419 (re-search-forward YaTeX-math-cmd-regexp nil t arg))
421 (defun YaTeX-math-backward (arg)
422 (interactive "p")
423 (re-search-backward YaTeX-math-cmd-regexp nil t arg))
425 (defun YaTeX-math-gets (sign)
426 (cond
427 ((null sign) nil)
428 ((listp sign)
429 (setq sign
430 (cond
431 (YaTeX-japan (YaTeX-math-japanese-sign sign))
432 (t (car sign))))
433 (YaTeX-math-gets sign))
434 ((symbolp sign)
435 (YaTeX-math-gets (symbol-value sign)))
436 (t sign))
437 )
439 (defun YaTeX-math-get-sign (list)
440 (YaTeX-math-gets (car (cdr-safe (cdr-safe list))))
441 )
443 (defun YaTeX-in-math-mode-p ()
444 "If current position is supposed to be in LaTeX-math-mode, return t."
445 (or (YaTeX-quick-in-environment-p
446 '("math" "eqnarray" "equation" "eqnarray*" "displaymath"))
447 (let*((p (point)) (nest 0) me0
448 (delim (concat YaTeX-sectioning-regexp
449 "\\|^%\\|^$\\|^\C-l"))
450 (boundary
451 (save-excursion
452 (if (looking-at delim)
453 (goto-char (max (point-min) (1- (point)))))
454 (re-search-backward delim nil 1)
455 (point))))
456 (save-excursion
457 (cond
458 ((catch 'open
459 (save-excursion
460 (while (and (>= nest 0)
461 (re-search-backward
462 (concat YaTeX-ec-regexp ;\
463 "\\([()]\\|[][]\\)") boundary t))
464 (setq me0 (match-end 0))
465 (if (or (YaTeX-on-comment-p)
466 (YaTeX-literal-p)) nil
467 (if (or (= (char-after (1- me0)) ?\))
468 (= (char-after (1- me0)) ?\]))
469 (setq nest (1+ nest))
470 (if (= (preceding-char) ?\\ ) nil;;\\[5pt]
471 (setq nest (1- nest))))))
472 (if (< nest 0) (throw 'open t))))
473 t)
474 (t (catch 'dollar
475 (while ;(search-backward "$" boundary t);little bit fast.
476 (YaTeX-re-search-active-backward ;;;;;; Too slow???
477 "\\$" YaTeX-comment-prefix boundary t)
478 (cond
479 ((equal (char-after (1- (point))) ?$) ; $$ equation $$
480 (backward-char 1)
481 (setq nest (1+ nest)))
482 ((let ((YaTeX-verbatim-environments
483 (append YaTeX-math-verbatim-environments
484 YaTeX-verbatim-environments)))
485 (YaTeX-literal-p))
486 nil)
487 ((and (equal (char-after (1- (point))) ?\\ )
488 (not (equal (char-after (- (point) 3)) ?\\ )))
489 nil) ;\$
490 (t (setq nest (1+ nest)))))
491 (if (= (% nest 2) 1) (throw 'dollar t))))))))
492 )
494 (defun YaTeX-math-display-list (list cols)
495 (goto-char (point-max))
496 (if (= cols 0) (if (not (eolp)) (newline 1))
497 (forward-line -1)
498 (while (looking-at "[ \t\n]") (forward-line -1)))
499 (end-of-line)
500 (let ((indent (* YaTeX-math-display-width cols)) sign str to)
501 (indent-to indent)
502 (insert (car list))
503 (indent-to (setq indent (+ indent YaTeX-math-max-key)))
504 (insert "\\" (car (cdr list)))
505 (setq indent (+ indent YaTeX-math-max-seq))
506 (setq sign (YaTeX-math-get-sign list))
507 (while (and sign (not (string= "" sign)))
508 (setq to (string-match "\n" sign)
509 str (if to (substring sign 0 to) sign))
510 (end-of-line)
511 (indent-to indent)
512 (insert str)
513 (cond ((eobp) (newline 1))
514 ((> cols 0) (forward-line 1)))
515 (setq sign (if to (substring sign (1+ to)) "")))))
517 (defvar YaTeX-math-menu-buffer "*math-mode-signs*")
519 (defun YaTeX-math-show-menu (match-str)
520 (save-window-excursion
521 (pop-to-buffer YaTeX-math-menu-buffer)
522 (let ((maxcols (max 1 (/ (screen-width) YaTeX-math-sign-width)))
523 (case-fold-search nil)
524 (cols 0) (list alist) command)
525 (erase-buffer)
526 (insert
527 "Candidates of sign. [n:next p:prev f:forw b:back q:quit RET:select]\n")
528 (insert YaTeX-math-indicator "\t")
529 (insert YaTeX-math-indicator)
530 (newline 1)
531 (insert-char ?- (1- (screen-width)))
532 (newline 1)
533 (while list
534 (if (string-match match-str (car (car list)))
535 (progn (YaTeX-math-display-list (car list) cols)
536 (setq cols (% (1+ cols) maxcols))))
537 (setq list (cdr list)))
538 (goto-line 4)
539 (use-local-map YaTeX-math-menu-map)
540 (unwind-protect
541 (recursive-edit)
542 (skip-chars-backward "^ \t\n")
543 (setq command
544 (if (re-search-forward YaTeX-math-cmd-regexp nil t)
545 (buffer-substring
546 (match-beginning 0)
547 (prog2 (skip-chars-forward "^ \t\n") (point)))
548 nil))
549 (kill-buffer YaTeX-math-menu-buffer))
550 command))
551 )
553 ;
554 (defun YaTeX-math-show-image (image &optional exit-char)
555 "Momentarily display IMAGE at the beginning of the next line;
556 erase it on the next keystroke. The window is recentered if necessary
557 to make the whole string visible. If the window isn't large enough,
558 at least you get to read the beginning."
559 (if (and image (not (string= image "")))
560 (let ((buffer-read-only nil)
561 (modified (buffer-modified-p))
562 (name buffer-file-name)
563 insert-start
564 insert-end)
565 (unwind-protect
566 (progn
567 (save-excursion
568 ;; defeat file locking... don't try this at home, kids!
569 (setq buffer-file-name nil)
570 (forward-line 1)
571 (setq insert-start (point))
572 (if (eobp) (newline))
573 (insert image)
574 (setq insert-end (point)))
575 ; make sure the whole string is visible
576 (if (not (pos-visible-in-window-p insert-end))
577 (recenter (max 0
578 (- (window-height)
579 (count-lines insert-start insert-end)
580 2))))
581 (let ((char (read-char)))
582 (or (eq char exit-char)
583 (setq unread-command-char char))))
584 (if insert-end
585 (save-excursion
586 (delete-region insert-start insert-end)))
587 (setq buffer-file-name name)
588 (set-buffer-modified-p modified)))))
590 (defun YaTeX-math-insert-sequence (&optional force initial)
591 "Insert math-mode sequence with image completion."
592 (interactive "P")
593 (let*((key (or initial "")) regkey str last-char list i
594 (case-fold-search nil) match sign
595 (this-key (char-to-string last-command-char))
596 (alist (symbol-value (cdr (assoc this-key YaTeX-math-key-list))))
597 (n (length alist)) (beg (point)) result)
598 (if initial (insert YaTeX-ec (car (cdr (assoc initial alist)))))
599 (setq result
600 (catch 'complete
601 (if (and (not force)
602 (if YaTeX-auto-math-mode
603 (not (YaTeX-in-math-mode-p))
604 (not YaTeX-math-mode)))
605 (throw 'complete 'escape));this tag should be exit, but...
606 (while t
607 (message "Sequence(TAB for menu): %s" key)
608 (setq last-char (read-char)
609 key (concat key (char-to-string last-char))
610 i 0)
611 (cond
612 ((string= key this-key) ;;invoke key itself
613 (throw 'complete 'escape))
614 ((string= key YaTeX-math-exit-key) ;;exit from math-mode
615 (throw 'complete 'exit))
616 ((string-match "\r" key) ;;RET = kakutei
617 (throw 'complete 'select))
618 ((string-match "[\C-g\C-c]" key) ;;C-g = abort
619 (throw 'complete 'abort))
620 ((string-match "[\t\n]" key) ;;TAB, LFD = menu
621 (throw 'complete 'menu))
622 ((string-match "[\C-h\C-?]" key) ;;BS, DEL = BS
623 (if (< (length key) 2) (throw 'complete 'abort))
624 (setq key (substring key 0 -2))))
626 (setq regkey (concat "^" (regexp-quote key)))
627 (message "Sequence(TAB for menu): %s" key)
628 (if
629 (catch 'found
630 ;;(1)input string strictly matches with alist
631 (setq match (assoc key alist))
632 ;;remember previous match
634 ;;(2)search partial match into alist
635 (setq list alist)
636 (while (< i n)
637 (if (string-match
638 regkey
639 ;;(aref array i)
640 ;;(car (nth i alist))
641 (car (car list)))
642 (progn
643 (or match
644 ;;(setq match (nth i alist))
645 (setq match (car list)))
646 (throw 'found t)))
647 (setq i (1+ i) list (cdr list)))) ;catch 'found
648 nil ;;if any match, continue reading
649 ;;else reading of sequence has been done.
650 (message "complete.")
651 (throw 'complete t))
653 (if match
654 (progn (delete-region beg (point))
655 (setq single-command (car (cdr match)))
656 (insert YaTeX-ec single-command)
657 (if (and YaTeX-math-need-image
658 (setq sign (YaTeX-math-get-sign match)))
659 (YaTeX-math-show-image (concat sign "\n")))
660 )
661 nil)
662 )))
663 (cond
664 ((eq result t)
665 (setq YaTeX-current-completion-type 'maketitle)
667 ;;;(sit-for 1)
668 (setq unread-command-char last-char)
669 (insert (YaTeX-addin single-command)))
670 ((eq result 'abort)
671 (delete-region beg (point))
672 (message "Abort."))
673 ((eq result 'escape)
674 (delete-region beg (point))
675 (call-interactively (global-key-binding this-key)))
676 ((eq result 'select)
677 (message "Done.")
678 (setq YaTeX-current-completion-type 'maketitle)
679 (insert (YaTeX-addin single-command)))
680 ((eq result 'exit)
681 (delete-region beg (point))
682 (YaTeX-toggle-math-mode))
683 ((eq result 'menu)
684 (delete-region beg (point))
685 (setq key (concat "^" (regexp-quote (substring key 0 -1))))
686 (insert (YaTeX-math-show-menu key)))))
687 )
689 ;; ----- Change image completion types -----
690 (defun YaTeX-math-member-p (item)
691 "Check if ITEM is a member of image completion.
692 If so return the cons of its invocation key and image-string."
693 (let ((lists YaTeX-math-key-list) list)
694 (catch 'found
695 (while lists
696 (setq list (symbol-value (cdr (car lists))))
697 (while list
698 (if (string= item (nth 1 (car list)))
699 (throw 'found (cons (car (car lists)) (nth 0 (car list)))))
700 (setq list (cdr list)))
701 (setq lists (cdr lists))))))
703 ;;
704 (provide 'yatexmth)
706 ; Local variables:
707 ; fill-prefix: ";;; "
708 ; paragraph-start: "^$\\| \\|;;;$"
709 ; paragraph-separate: "^$\\| \\|;;;$"
710 ; End: