yatex

view yatexmth.el @ 13:eafae54794a0

Show message at comment-region on begin/end mode. Greek letters completion in yatexmth. YaTeX-mark environment and YaTeX-%-menu added. Erase cursor at the execution of dviout(DOS). Enable recursive completion at section-type completion.
author yuuji
date Sat, 29 Jan 1994 07:59:59 +0000
parents 390df0e505da
children b7b023a74293
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX interface for math-mode.
3 ;;; yatexmth.el rev.2
4 ;;; (c )1993 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
5 ;;; Last modified Sat Jan 29 16:55:03 1994 on gloria
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 YaTeX-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" "♭")
110 (setq
111 YaTeX-math-sign-alist-default
112 '(
113 ;frequently used
114 ("||" "|" ("||" "‖"))
115 ("sum" "sum" ("\\-+\n >\n/-+" "Σ"))
116 ("sigma" "sum" ("\\-+\n >\n/-+" "Σ"))
117 ("integral" "int" (" /\\\n \\\n\\/" YaTeX-image-int))
118 ("ointegral" "oint" " /\\\n(\\)\n\\/")
119 ("A" "forall" "|_|\nV")
120 ("E" "exists" "-+\n-+\n-+")
121 ("!" "neg" ("--+\n |" YaTeX-image-neg))
122 ("oo" "infty" ("oo" "∞"))
123 ("\\" "backslash" ("\\" "\"))
125 ;;binary operators
126 ("+-" "pm" ("+\n-" "±"))
127 ("-+" "mp" "-\n+")
128 ("x" "times" ("x" "×"))
129 ("/" "div" (",\n-\n'" "÷"))
130 ("*" "ast" "*")
131 ("#" "star" ("_/\\_\n\\ /\n//\\\\" "★"))
132 ("o" "circ" "o")
133 ("o*" "bullet" " _\n(*)\n ~")
134 ("." "cdot" ".")
135 ("cap" "cap" "/-\\\n| |")
136 ("cup" "cup" "| |\n\\-/")
137 ("u+" "uplus" "|+|\n\\-/")
138 ("|~|" "sqcap" "|~|")
139 ("|_|" "sqcup" "|_|")
140 ("v" "vee" "v")
141 ("^" "wedge" "^")
142 ("\\\\" "setminus" "\\")
143 (")(" "wr" " )\n(")
144 ("<>" "diamond" "<>")
145 ("/\-" "bigtriangleup" ("/\\\n~~" "△"))
146 ("-\\/" "bigtriangledown" ("__\n\\/" "▽"))
147 ("<|" "triangleleft" "<|")
148 ("|>" "triangleright" "|>")
149 ("<||" "lhd" "/|\n\\|")
150 ("||>" "rhd" "|\\\n|/")
151 ("<|-" "unlhd" "<|\n~~")
152 ("|>-" "unrhd" "|>\n~~")
153 ("o+" "oplus" " _\n(+)\n ~")
154 ("o-" "ominus" " _\n(-)\n ~")
155 ("ox" "otimes" " _\n(x)\n ~")
156 ("o/" "oslash" " _\n(/)\n ~")
157 ("o." "odot" "(.)")
158 ("O" "bigcirc" "O")
159 ("t" "dagger" ("+\n|" YaTeX-image-dagger))
160 ("tt" "ddagger" ("+\n+\n|" YaTeX-image-ddagger))
161 ("II" "amalg" "II")
162 ; :
163 ;;relational operators
164 ("<" "leq" ("<\n-" "≦"))
165 (">" "geq" (">\n-" "≧"))
166 ("-=" "equiv" ("=\n-" YaTeX-image-equiv))
167 ("=-" "equiv" ("=\n-" YaTeX-image-equiv))
168 ("---" "equiv" ("=\n-" YaTeX-image-equiv))
169 ("(" "subset" (" _\n(\n ~" YaTeX-image-subset))
170 ("(-" "subseteq" (" _\n(_\n ~" YaTeX-image-subseteq))
171 (")" "supset" ("_\n )\n~" YaTeX-image-supset))
172 (")-" "supseteq" ("_\n_)\n~" YaTeX-image-supseteq))
173 ("[" "sqsubset" "[")
174 ("[-" "sqsubseteq" "[\n~")
175 ("]" "sqsupset" "]")
176 ("]-" "sqsupseteq" "]\n~")
177 ("{" "in" ("(-" YaTeX-image-in))
178 ("}" "ni" ("-)" YaTeX-image-ni))
179 ("|-" "vdash" "|-")
180 ("-|" "dashv" "-|")
181 ("~" "sim" "~(tild)")
182 ("~-" "simeq" "~\n-")
183 ("asymp" "asymp" "v\n^")
184 ("~~" "approx" "~\n~")
185 ("~=" "cong" "~\n=")
186 ("=/" "neq" ("=/=" "≠"))
187 (".=" "doteq" ".\n=")
188 ("o<" "propto" "o<")
189 ("|=" "models" "|=")
190 ("_|_" "perp" "_|_")
191 ("|" "mid" "|")
192 ("||" "parallel" "||")
193 ("bowtie" "bowtie" "|><|(wide)")
194 ("|><|" "join" "|><|")
195 ("\\_/" "smile" "\\_/")
196 ("/~\\" "frown" "/~~\\")
197 ("-<" "prec" ("-<" "く"))
198 ("-<=" "preceq" ("-<\n-" "く\n="))
199 ("<<" "ll" ("<<" "《"))
200 ; :
201 ;;arrows
202 ("<-" "leftarrow" ("<-" "←"))
203 ("\C-b" "leftarrow" ("<-" "←"))
204 ("<--" "longleftarrow" ("<--" "←--"))
205 ("<=" "Leftarrow" "<=")
206 ("<==" "Longleftarrow" "<==")
207 ("->" "rightarrow" ("->" "→"))
208 ("\C-f" "rightarrow" ("->" "→"))
209 ("-->" "longrightarrow" ("-->" "--→"))
210 ("==>" "Longrightarrow" "==>")
211 ("<->" "leftrightarrow" ("<->" "←→"))
212 ("<-->" "longleftrightarrow" ("<---->" "←--→"))
213 ("<=>" "leftrightarrow" "<=>")
214 ("<==>" "Longleftrightarrow" "<==>")
215 ("^|" "uparrow" ("^\n|" "↑"))
216 ("\C-p" "uparrow" ("^\n|" "↑"))
217 ("^||" "Uparrow" "/\\\n||")
218 ("\C-n" "downarrow" ("|\nv" "↓"))
219 ("v|" "downarrow" ("|\nv" "↓"))
220 ("v||" "Downarrow" "||\n\\/")
221 ("|->" "mapsto" ("|->" "|→"))
222 ("<-)" "hookleftarrow" (" ,\n<--+" " ヽ\n<--/"))
223 ("/-" "leftharpoonup" "/\n~~~")
224 ("\\-" "leftharpoondown" "__\n\\")
225 ("-/" "rightharpoondown" "__\n/")
226 ("-\\" "rightharpoonup" "~~\n\\")
227 ;other marks
228 ("Z" "aleph" "|\\|")
229 ("|\\|" "aleph" "|\\|")
230 ("h-" "hbar" "_\nh")
231 ("i" "imath" "i")
232 ("j" "jmath" "j")
233 ("l" "ell" "l")
234 ("wp" "wp" "???")
235 ("R" "Re" ")R")
236 ("Im" "Im" "???")
237 ("mho" "mho" "~|_|~")
238 ("'" "prime" "'")
239 ("0" "emptyset" "0")
240 ("nabla" "nabla" ("___\n\\\\/" YaTeX-image-nabla))
241 ("\\/" "surd" "-\\/")
242 ("surd" "surd" "-\\/")
243 ("top" "top" "T")
244 ("bot" "bot" ("_|_" YaTeX-image-bot))
245 ("b" "flat" ("b" YaTeX-image-flat))
246 ("LT" "natural" "|\nLT\n |")
247 ("6" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
248 ("partial" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
249 ("round" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
250 ("[]" "box" "[]")
251 ("Diamond" "Diamond" "/\\\n\\/")
252 ("3" "triangle" "/\\\n~~")
253 ("C" "clubsuit" " o\no+o\n |")
254 ("D" "diamondsuit" "/\\\n\\/")
255 ("H" "heartsuit" "<^^>\n \\/")
256 ("S" "spadesuit" " /\\\n<++>\n /\\")
258 ))
260 (defvar YaTeX-math-sign-alist-private nil
261 "*User definable key vs LaTeX-math-command alist.")
263 (defvar YaTeX-math-quit-with-strict-match nil
264 "*T for quitting completion as soon as strict-match is found.")
265 (setq YaTeX-math-sign-alist
266 (append YaTeX-math-sign-alist-private YaTeX-math-sign-alist-default))
268 ;;(defun YaTeX-math-alist2array (alist array)
269 ;; (set array
270 ;; (let ((array (make-vector (length alist) "")) (list alist) (i 0))
271 ;; (while list
272 ;; (aset array i (car (car list)))
273 ;; (setq i (1+ i) list (cdr list)))
274 ;; array))
275 ;;)
277 (setq YaTeX-greek-key-alist-default
278 '(
279 ("a" "alpha" ("a" "α"))
280 ("b" "beta" ("|>\n|>\n|" "β"))
281 ("g" "gamma" ("~r" "γ"))
282 ("G" "Gamma" ("|~" "Γ"))
283 ("d" "delta" ("<~\n<>" "δ"))
284 ("D" "Delta" ("/\\\n~~" "Δ"))
285 ("e" "epsilon" "<\n<~")
286 ("e-" "varepsilon" ("(\n(~" "ε"))
287 ("z" "zeta" ("(~\n >" "ζ"))
288 ("et" "eta" ("n\n/" "η"))
289 ("th" "theta" ("8" "θ"))
290 ("Th" "Theta" ("(8)" "Θ"))
291 ("th-" "vartheta" ("-8" "-θ"))
292 ("i" "iota" ("i\n\\_/" "ι"))
293 ("k" "kappa" ("k" "κ"))
294 ("l" "lambda" ("\\n/\\" "λ"))
295 ("L" "Lambda" ("/\\" "Λ"))
296 ("m" "mu" (" u_\n/" "μ"))
297 ("n" "nu" ("|/" "ν"))
298 ("x" "xi" ("E\n >" "ξ"))
299 ("X" "Xi" ("---\n -\n---" "Ξ"))
300 ("p" "pi" ("__\n)(" "π"))
301 ("P" "Pi" ("__\n||" "Π"))
302 ("p-" "varpi" ("_\nw" "__\nω"))
303 ("r" "rho" ("/O" "ρ"))
304 ("r-" "varrho" ("/O\n~~" "ρ\n~~"))
305 ("s" "sigma" ("o~" "σ"))
306 ("S" "Sigma" ("\\-+\n >\n/-+" "Σ"))
307 ("s-" "varsigma" "(~~ \n>")
308 ("t" "tau" ("__\n(" "τ"))
309 ("u" "upsilon" ("~v" "υ"))
310 ("y" "upsilon" ("~v" "υ"))
311 ("U" "Upsilon" ("~Y~" "Υ"))
312 ("Y" "Upsilon" ("~Y~" "Υ"))
313 ("ph" "phi" (" /\n(/)\n/" "φ"))
314 ("Ph" "Phi" (" _\n(|)\n ~" "Φ"))
315 ("ph-" "varphi" "\\O\n|")
316 ("c" "chi" ("x" "χ"))
317 ("ps" "psi" ("\\|/\\n |" "ψ"))
318 ("Ps" "Psi" (" ~\n\\|/\\n |" "Ψ"))
319 ("o" "omega" ("w" "ω"))
320 ("w" "omega" ("w" "ω"))
321 ("O" "Omega" ("(~)\n~ ~" "Ω"))
322 ("W" "Omega" ("(~)\n~ ~" "Ω"))
323 ("f" "foo")
324 )
325 )
327 (defvar YaTeX-greek-key-alist-private nil
328 "*User definable key vs LaTeX-math-command alist.")
330 (setq YaTeX-greek-key-alist
331 (append YaTeX-greek-key-alist-private YaTeX-greek-key-alist-default))
333 ;;(mapcar (function (lambda (x) (YaTeX-math-alist2array x)))
334 ;; YaTeX-math-key-list)
336 (setq YaTeX-math-indicator
337 "KEY\tLaTeX sequence\t\tsign")
339 (defvar YaTeX-math-need-image t
340 "*T for displaying pseudo image momentarily.")
341 (defvar YaTeX-math-max-key 8)
342 (defvar YaTeX-math-max-seq
343 (* 8 (1+ (/ (length "\\longleftrightarrow") 8))))
344 (defvar YaTeX-math-max-sign 5)
345 (defvar YaTeX-math-sign-width
346 (+ YaTeX-math-max-key YaTeX-math-max-seq YaTeX-math-max-sign))
347 (defvar YaTeX-math-display-width
348 (* 8 (1+ (/ YaTeX-math-sign-width 8))))
349 (defvar YaTeX-math-menu-map nil
350 "Keymap used in YaTeX mathematical sign menu mode."
351 )
352 (if YaTeX-math-menu-map nil
353 (setq YaTeX-math-menu-map (make-sparse-keymap))
354 (define-key YaTeX-math-menu-map "n" 'next-line)
355 (define-key YaTeX-math-menu-map "p" 'previous-line)
356 (define-key YaTeX-math-menu-map "f" 'YaTeX-math-forward)
357 (define-key YaTeX-math-menu-map "b" 'YaTeX-math-backward)
358 (define-key YaTeX-math-menu-map "v" 'scroll-up)
359 (define-key YaTeX-math-menu-map " " 'scroll-up)
360 (define-key YaTeX-math-menu-map "c" 'scroll-up)
361 (define-key YaTeX-math-menu-map "V" 'scroll-down)
362 (define-key YaTeX-math-menu-map "r" 'scroll-down)
363 (define-key YaTeX-math-menu-map "\^h" 'scroll-down)
364 (define-key YaTeX-math-menu-map "<" 'beginning-of-buffer)
365 (define-key YaTeX-math-menu-map ">" 'end-of-buffer)
366 (define-key YaTeX-math-menu-map "\^m" 'exit-recursive-edit)
367 (define-key YaTeX-math-menu-map "q" 'abort-recursive-edit))
369 (defvar YaTeX-math-key-list-default
370 '(("," . YaTeX-math-sign-alist)
371 ("/" . YaTeX-greek-key-alist))
372 "Default key sequence to invoke math-mode's image completion."
373 )
374 (defvar YaTeX-math-key-list-private nil
375 "*User defined alist, math-mode-prefix vs completion alist"
376 )
377 (defvar YaTeX-math-key-list
378 (append YaTeX-math-key-list-private YaTeX-math-key-list-default)
379 "Key sequence to invoke math-mode's image completion."
380 )
381 (defvar YaTeX-math-exit-key "\e"
382 "*Key sequence after prefix key of YaTeX-math-mode to exit from math-mode."
383 )
385 (defmacro YaTeX-math-japanese-sign (list)
386 (list 'nth 1 list))
388 (defvar YaTeX-math-cmd-regexp (concat (regexp-quote YaTeX-ec) "[A-z]"))
390 ;;;
391 ;;YaTeX math-mode functions
392 ;;;
393 ;##autoload from yatex.el
394 (defun YaTeX-toggle-math-mode (&optional arg)
395 (interactive "P")
396 (require 'yatexmth)
397 (or (memq 'YaTeX-math-mode mode-line-format) nil
398 (setq mode-line-format
399 (append (list "" 'YaTeX-math-mode) mode-line-format)))
400 (if (or arg (null YaTeX-math-mode))
401 (let ((keys ""))
402 (setq YaTeX-math-mode "math:")
403 (mapcar
404 (function (lambda (x)
405 (let ((key (car x)) (list (cdr x)))
406 (setq keys (concat keys " " key))
407 (put 'YaTeX-math-key-list list (key-binding key))
408 (define-key YaTeX-mode-map key
409 'YaTeX-math-insert-sequence))))
410 YaTeX-math-key-list)
411 (message "Turn on math mode. Prefix keys are %s" keys)
412 (sit-for 3)
413 (message
414 (concat "To exit from math-mode, type `ESC' after prefix, "
415 "or type `"
416 (key-description
417 (car
418 (where-is-internal 'YaTeX-switch-mode-menu YaTeX-mode-map)))
419 " $'")))
420 (setq YaTeX-math-mode nil)
421 (mapcar
422 (function (lambda (x)
423 (let ((key (car x)) (list (cdr x)))
424 (define-key YaTeX-mode-map key
425 (get 'YaTeX-math-key-list list)))))
426 YaTeX-math-key-list)
427 (setq YaTeX-math-mode nil)
428 (message "Exit from math mode."))
429 (set-buffer-modified-p (buffer-modified-p))
430 )
432 (defun YaTeX-math-forward (arg)
433 (interactive "p")
434 (re-search-forward YaTeX-math-cmd-regexp nil t arg))
436 (defun YaTeX-math-backward (arg)
437 (interactive "p")
438 (re-search-backward YaTeX-math-cmd-regexp nil t arg))
440 (defun YaTeX-math-gets (sign)
441 (cond
442 ((null sign) nil)
443 ((listp sign)
444 (setq sign
445 (cond
446 (YaTeX-japan (YaTeX-math-japanese-sign sign))
447 (t (car sign))))
448 (YaTeX-math-gets sign))
449 ((symbolp sign)
450 (YaTeX-math-gets (symbol-value sign)))
451 (t sign))
452 )
454 (defun YaTeX-math-get-sign (list)
455 (YaTeX-math-gets (car (cdr-safe (cdr-safe list))))
456 )
458 (defun YaTeX-math-display-list (list cols)
459 (goto-char (point-max))
460 (if (= cols 0) (if (not (eolp)) (newline 1))
461 (forward-line -1)
462 (while (looking-at "[ \t\n]") (forward-line -1)))
463 (end-of-line)
464 (let ((indent (* YaTeX-math-display-width cols)) sign str to)
465 (indent-to indent)
466 (insert (car list))
467 (indent-to (setq indent (+ indent YaTeX-math-max-key)))
468 (insert "\\" (car (cdr list)))
469 (setq indent (+ indent YaTeX-math-max-seq))
470 (setq sign (YaTeX-math-get-sign list))
471 (while (and sign (not (string= "" sign)))
472 (setq to (string-match "\n" sign)
473 str (if to (substring sign 0 to) sign))
474 (end-of-line)
475 (indent-to indent)
476 (insert str)
477 (cond ((eobp) (newline 1))
478 ((> cols 0) (forward-line 1)))
479 (setq sign (if to (substring sign (1+ to)) "")))))
481 (defvar YaTeX-math-menu-buffer "*math-mode-signs*")
483 (defun YaTeX-math-show-menu (match-str)
484 (save-window-excursion
485 (pop-to-buffer YaTeX-math-menu-buffer)
486 (let ((maxcols (max 1 (/ (screen-width) YaTeX-math-sign-width)))
487 (case-fold-search nil)
488 (cols 0) (list alist) command)
489 (erase-buffer)
490 (insert
491 "Candidates of sign. [n:next p:prev f:forw b:back q:quit RET:select]\n")
492 (insert YaTeX-math-indicator "\t")
493 (insert YaTeX-math-indicator)
494 (newline 1)
495 (insert-char ?- (1- (screen-width)))
496 (newline 1)
497 (while list
498 (if (string-match match-str (car (car list)))
499 (progn (YaTeX-math-display-list (car list) cols)
500 (setq cols (% (1+ cols) maxcols))))
501 (setq list (cdr list)))
502 (goto-line 4)
503 (use-local-map YaTeX-math-menu-map)
504 (unwind-protect
505 (recursive-edit)
506 (skip-chars-backward "^ \t\n")
507 (setq command
508 (if (re-search-forward YaTeX-math-cmd-regexp nil t)
509 (buffer-substring
510 (match-beginning 0)
511 (prog2 (skip-chars-forward "^ \t\n") (point)))
512 nil))
513 (kill-buffer YaTeX-math-menu-buffer))
514 command))
515 )
517 ;
518 (defun YaTeX-math-show-image (image &optional exit-char)
519 "Momentarily display IMAGE at the beginning of the next line;
520 erase it on the next keystroke. The window is recentered if necessary
521 to make the whole string visible. If the window isn't large enough,
522 at least you get to read the beginning."
523 (if (and image (not (string= image "")))
524 (let ((buffer-read-only nil)
525 (modified (buffer-modified-p))
526 (name buffer-file-name)
527 insert-start
528 insert-end)
529 (unwind-protect
530 (progn
531 (save-excursion
532 ;; defeat file locking... don't try this at home, kids!
533 (setq buffer-file-name nil)
534 (forward-line 1)
535 (setq insert-start (point))
536 (if (eobp) (newline))
537 (insert image)
538 (setq insert-end (point)))
539 ; make sure the whole string is visible
540 (if (not (pos-visible-in-window-p insert-end))
541 (recenter (max 0
542 (- (window-height)
543 (count-lines insert-start insert-end)
544 2))))
545 (let ((char (read-char)))
546 (or (eq char exit-char)
547 (setq unread-command-char char))))
548 (if insert-end
549 (save-excursion
550 (delete-region insert-start insert-end)))
551 (setq buffer-file-name name)
552 (set-buffer-modified-p modified)))))
554 (defun YaTeX-math-insert-sequence ()
555 (interactive)
556 (let*((key "") regkey str last-char list i
557 (case-fold-search nil) match sign
558 (this-key (char-to-string last-command-char))
559 (alist (symbol-value (cdr (assoc this-key YaTeX-math-key-list))))
560 (n (length alist)) (beg (point)) result)
561 (setq result
562 (catch 'complete
563 (while t
564 (message "Sequence: %s" key)
565 (setq last-char (read-char)
566 key (concat key (char-to-string last-char))
567 i 0)
568 (cond
569 ((string= key this-key) ;;invoke key itself
570 (throw 'complete 'escape))
571 ((string= key YaTeX-math-exit-key) ;;exit from math-mode
572 (throw 'complete 'exit))
573 ((string-match "[\C-g\C-c]" key) (throw 'complete 'abort))
574 ((string-match "[\n\r]" key) (throw 'complete 'menu))
575 ((string-match "[\C-h\C-?]" key)
576 (if (string= key "") (throw 'complete 'abort))
577 (setq key (substring key 0 -2))))
579 (setq regkey (concat "^" (regexp-quote key)))
580 (message "Sequence: %s" key)
581 (if
582 (catch 'found
583 ;;(1)input string strictly matches with alist
584 (setq single-command (car (cdr match))
585 ;;remember previous match
586 match (assoc key alist))
587 ;;(2)search partial match into alist
588 (setq list alist)
589 (while (< i n)
590 (if (string-match
591 regkey
592 ;;(aref array i)
593 ;;(car (nth i alist))
594 (car (car list))
595 )
596 (progn
597 (or match
598 ;;(setq match (nth i alist))
599 (setq match (car list)))
600 (throw 'found t)))
601 (setq i (1+ i) list (cdr list)))) ;catch 'found
602 nil ;;if any match, continue reading
603 ;;else reading of sequence has been done.
604 (message "complete.")
605 (throw 'complete t)
606 )
607 (if match
608 (progn (delete-region beg (point))
609 (insert YaTeX-ec (car (cdr match)))
610 (if (and YaTeX-math-need-image
611 (setq sign (YaTeX-math-get-sign match)))
612 (YaTeX-math-show-image (concat sign "\n")))
613 )
614 nil)
615 )))
616 (cond
617 ((eq result t)
618 (setq YaTeX-current-completion-type 'maketitle)
619 (if t nil
620 (delete-region beg (point))
621 (setq single-command (car (cdr match)))
622 ;;(recursive-edit)
623 (insert YaTeX-ec single-command)
624 )
625 ;;;(sit-for 1)
626 (setq unread-command-char last-char)
627 (insert (YaTeX-addin single-command)))
628 ((eq result 'abort)
629 (delete-region beg (point))
630 (message "Abort."))
631 ((eq result 'escape)
632 (delete-region beg (point))
633 (insert this-key))
634 ((eq result 'exit)
635 (delete-region beg (point))
636 (YaTeX-toggle-math-mode))
637 ((eq result 'menu)
638 (delete-region beg (point))
639 (setq key (concat "^" (regexp-quote (substring key 0 -1))))
640 (insert (YaTeX-math-show-menu key)))))
641 )
642 ;;
643 (provide 'yatexmth)
645 ; Local variables:
646 ; fill-prefix: ";;; "
647 ; paragraph-start: "^$\\| \\|;;;$"
648 ; paragraph-separate: "^$\\| \\|;;;$"
649 ; End: