yatex

view yatexmth.el @ 52:5d94deabb9f9

Set YaTeX-indent-line to 'indent-line-function. Revise fill features.
author yuuji
date Sun, 22 Jan 1995 14:20:46 +0000
parents b0371b6ed799
children 5f4b18da14b3
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; YaTeX math-mode-specific functions.
3 ;;; yatexmth.el rev.3
4 ;;; (c )1993-1995 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
5 ;;; Last modified Sun Jan 22 23:14:51 1995 on landcruiser
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 ;other marks
232 ("Z" "aleph" "|\\|")
233 ("|\\|" "aleph" "|\\|")
234 ("h-" "hbar" "_\nh")
235 ("i" "imath" "i")
236 ("j" "jmath" "j")
237 ("l" "ell" "l")
238 ("wp" "wp" "???")
239 ("R" "Re" ")R")
240 ("Im" "Im" "???")
241 ("mho" "mho" "~|_|~")
242 ("'" "prime" "'")
243 ("0" "emptyset" "0")
244 ("nabla" "nabla" ("___\n\\\\/" YaTeX-image-nabla))
245 ("\\/" "surd" "-\\/")
246 ("surd" "surd" "-\\/")
247 ("top" "top" "T")
248 ("bot" "bot" ("_|_" YaTeX-image-bot))
249 ("b" "flat" ("b" YaTeX-image-flat))
250 ("LT" "natural" "|\nLT\n |")
251 ("6" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
252 ("partial" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
253 ("round" "partial" (" -+\n+-+\n+-+" YaTeX-image-partial))
254 ("[]" "box" "[]")
255 ("Diamond" "Diamond" "/\\\n\\/")
256 ("3" "triangle" "/\\\n~~")
257 ("C" "clubsuit" " o\no+o\n |")
258 ("D" "diamondsuit" "/\\\n\\/")
259 ("H" "heartsuit" "<^^>\n \\/")
260 ("S" "spadesuit" " /\\\n<++>\n /\\")
261 )
262 "Default LaTeX-math-command alist.")
264 (defvar YaTeX-math-sign-alist-private nil
265 "*User definable key vs LaTeX-math-command alist.")
267 (defvar YaTeX-math-quit-with-strict-match nil
268 "*T for quitting completion as soon as strict-match is found.")
269 (defvar YaTeX-math-sign-alist
270 (append YaTeX-math-sign-alist-private YaTeX-math-sign-alist-default))
272 ;;(defun YaTeX-math-alist2array (alist array)
273 ;; (set array
274 ;; (let ((array (make-vector (length alist) "")) (list alist) (i 0))
275 ;; (while list
276 ;; (aset array i (car (car list)))
277 ;; (setq i (1+ i) list (cdr list)))
278 ;; array))
279 ;;)
281 (defvar YaTeX-greek-key-alist-default
282 '(
283 ("a" "alpha" ("a" "α"))
284 ("b" "beta" ("|>\n|>\n|" "β"))
285 ("g" "gamma" ("~r" "γ"))
286 ("G" "Gamma" ("|~" "Γ"))
287 ("d" "delta" ("<~\n<>" "δ"))
288 ("D" "Delta" ("/\\\n~~" "Δ"))
289 ("e" "epsilon" "<\n<~")
290 ("e-" "varepsilon" ("(\n(~" "ε"))
291 ("z" "zeta" ("(~\n >" "ζ"))
292 ("et" "eta" ("n\n/" "η"))
293 ("th" "theta" ("8" "θ"))
294 ("Th" "Theta" ("(8)" "Θ"))
295 ("th-" "vartheta" ("-8" "-θ"))
296 ("i" "iota" ("i\n\\_/" "ι"))
297 ("k" "kappa" ("k" "κ"))
298 ("l" "lambda" ("\\n/\\" "λ"))
299 ("L" "Lambda" ("/\\" "Λ"))
300 ("m" "mu" (" u_\n/" "μ"))
301 ("n" "nu" ("|/" "ν"))
302 ("x" "xi" ("E\n >" "ξ"))
303 ("X" "Xi" ("---\n -\n---" "Ξ"))
304 ("p" "pi" ("__\n)(" "π"))
305 ("P" "Pi" ("__\n||" "Π"))
306 ("p-" "varpi" ("_\nw" "__\nω"))
307 ("r" "rho" ("/O" "ρ"))
308 ("r-" "varrho" ("/O\n~~" "ρ\n~~"))
309 ("s" "sigma" ("o~" "σ"))
310 ("S" "Sigma" ("\\-+\n >\n/-+" "Σ"))
311 ("s-" "varsigma" "(~~ \n>")
312 ("t" "tau" ("__\n(" "τ"))
313 ("u" "upsilon" ("~v" "υ"))
314 ("y" "upsilon" ("~v" "υ"))
315 ("U" "Upsilon" ("~Y~" "Υ"))
316 ("Y" "Upsilon" ("~Y~" "Υ"))
317 ("ph" "phi" (" /\n(/)\n/" "φ"))
318 ("Ph" "Phi" (" _\n(|)\n ~" "Φ"))
319 ("ph-" "varphi" "\\O\n|")
320 ("c" "chi" ("x" "χ"))
321 ("ps" "psi" ("\\|/\\n |" "ψ"))
322 ("Ps" "Psi" (" ~\n\\|/\\n |" "Ψ"))
323 ("o" "omega" ("w" "ω"))
324 ("w" "omega" ("w" "ω"))
325 ("O" "Omega" ("(~)\n~ ~" "Ω"))
326 ("W" "Omega" ("(~)\n~ ~" "Ω"))
327 ("f" "foo")
328 )
329 "Default LaTeX-math-command alist.")
331 (defvar YaTeX-greek-key-alist-private nil
332 "*User definable key vs LaTeX-math-command alist.")
334 (defvar YaTeX-greek-key-alist
335 (append YaTeX-greek-key-alist-private YaTeX-greek-key-alist-default))
337 ;;(mapcar (function (lambda (x) (YaTeX-math-alist2array x)))
338 ;; YaTeX-math-key-list)
340 (defvar YaTeX-math-indicator "KEY\tLaTeX sequence\t\tsign")
342 (defvar YaTeX-math-need-image t
343 "*T for displaying pseudo image momentarily.")
344 (defvar YaTeX-math-max-key 8)
345 (defvar YaTeX-math-max-seq
346 (* 8 (1+ (/ (length "\\longleftrightarrow") 8))))
347 (defvar YaTeX-math-max-sign 5)
348 (defvar YaTeX-math-sign-width
349 (+ YaTeX-math-max-key YaTeX-math-max-seq YaTeX-math-max-sign))
350 (defvar YaTeX-math-display-width
351 (* 8 (1+ (/ YaTeX-math-sign-width 8))))
352 (defvar YaTeX-math-menu-map nil
353 "Keymap used in YaTeX mathematical sign menu mode."
354 )
355 (if YaTeX-math-menu-map nil
356 (setq YaTeX-math-menu-map (make-sparse-keymap))
357 (define-key YaTeX-math-menu-map "n" 'next-line)
358 (define-key YaTeX-math-menu-map "p" 'previous-line)
359 (define-key YaTeX-math-menu-map "f" 'YaTeX-math-forward)
360 (define-key YaTeX-math-menu-map "b" 'YaTeX-math-backward)
361 (define-key YaTeX-math-menu-map "v" 'scroll-up)
362 (define-key YaTeX-math-menu-map " " 'scroll-up)
363 (define-key YaTeX-math-menu-map "c" 'scroll-up)
364 (define-key YaTeX-math-menu-map "V" 'scroll-down)
365 (define-key YaTeX-math-menu-map "r" 'scroll-down)
366 (define-key YaTeX-math-menu-map "\^h" 'scroll-down)
367 (define-key YaTeX-math-menu-map "<" 'beginning-of-buffer)
368 (define-key YaTeX-math-menu-map ">" 'end-of-buffer)
369 (define-key YaTeX-math-menu-map "\^m" 'exit-recursive-edit)
370 (define-key YaTeX-math-menu-map "q" 'abort-recursive-edit))
372 (defvar YaTeX-math-exit-key "\e"
373 "*Key sequence after prefix key of YaTeX-math-mode to exit from math-mode."
374 )
376 (defmacro YaTeX-math-japanese-sign (list)
377 (list 'nth 1 list))
379 (defvar YaTeX-math-cmd-regexp (concat (regexp-quote YaTeX-ec) "[A-z]"))
380 (defvar YaTeX-math-verbatim-environments
381 '("alltt")
382 "*List of environments in which LaTeX math mode is disabled.
383 This value is appended with YaTeX-verbatim-environments.")
385 ;;;
386 ;;YaTeX math-mode functions
387 ;;;
388 ;;;###autoload from yatex.el
389 (defun YaTeX-toggle-math-mode (&optional arg)
390 (interactive "P")
391 (or (memq 'YaTeX-math-mode mode-line-format) nil
392 (setq mode-line-format
393 (append (list "" 'YaTeX-math-mode) mode-line-format)))
394 (if YaTeX-auto-math-mode nil ;Only effective on manual mode.
395 (if (or arg (null YaTeX-math-mode))
396 (let (keys)
397 (setq YaTeX-math-mode "math:")
398 (message "Turn on math mode. Prefix keys are %s"
399 (mapconcat 'car YaTeX-math-key-list " "))
400 (sit-for 3)
401 (message
402 (concat "To exit from math-mode, type `ESC' after prefix, "
403 "or type `"
404 (key-description
405 (car
406 (where-is-internal
407 'YaTeX-switch-mode-menu YaTeX-mode-map)))
408 " $'")))
409 (setq YaTeX-math-mode nil)
410 (message "Exit from math mode."))
411 (set-buffer-modified-p (buffer-modified-p)))
412 )
414 (defun YaTeX-math-forward (arg)
415 (interactive "p")
416 (re-search-forward YaTeX-math-cmd-regexp nil t arg))
418 (defun YaTeX-math-backward (arg)
419 (interactive "p")
420 (re-search-backward YaTeX-math-cmd-regexp nil t arg))
422 (defun YaTeX-math-gets (sign)
423 (cond
424 ((null sign) nil)
425 ((listp sign)
426 (setq sign
427 (cond
428 (YaTeX-japan (YaTeX-math-japanese-sign sign))
429 (t (car sign))))
430 (YaTeX-math-gets sign))
431 ((symbolp sign)
432 (YaTeX-math-gets (symbol-value sign)))
433 (t sign))
434 )
436 (defun YaTeX-math-get-sign (list)
437 (YaTeX-math-gets (car (cdr-safe (cdr-safe list))))
438 )
440 (defun YaTeX-in-math-mode-p ()
441 "If current position is supposed to be in LaTeX-math-mode, return t."
442 (or (YaTeX-quick-in-environment-p
443 '("math" "eqnarray" "equation" "eqnarray*" "displaymath"))
444 (let*((p (point)) (nest 0) me0
445 (delim (concat YaTeX-sectioning-regexp
446 "\\|^%\\|^$\\|^\C-l"))
447 (boundary
448 (save-excursion
449 (if (looking-at delim)
450 (goto-char (max (point-min) (1- (point)))))
451 (re-search-backward delim nil 1)
452 (point))))
453 (save-excursion
454 (cond
455 ((catch 'open
456 (save-excursion
457 (while (and (>= nest 0)
458 (re-search-backward
459 (concat YaTeX-ec-regexp ;\
460 "\\([()]\\|[][]\\)") boundary t))
461 (setq me0 (match-end 0))
462 (if (or (YaTeX-on-comment-p)
463 (YaTeX-literal-p)) nil
464 (if (or (= (char-after (1- me0)) ?\))
465 (= (char-after (1- me0)) ?\]))
466 (setq nest (1+ nest))
467 (if (= (preceding-char) ?\\ ) nil;;\\[5pt]
468 (setq nest (1- nest))))))
469 (if (< nest 0) (throw 'open t))))
470 t)
471 (t (catch 'dollar
472 (while ;(search-backward "$" boundary t);little bit fast.
473 (YaTeX-re-search-active-backward ;;;;;; Too slow???
474 "\\$" YaTeX-comment-prefix boundary t)
475 (cond
476 ((equal (char-after (1- (point))) ?$) ; $$ equation $$
477 (backward-char 1)
478 (setq nest (1+ nest)))
479 ((let ((YaTeX-verbatim-environments
480 (append YaTeX-math-verbatim-environments
481 YaTeX-verbatim-environments)))
482 (YaTeX-literal-p))
483 nil)
484 ((and (equal (char-after (1- (point))) ?\\ )
485 (not (equal (char-after (- (point) 3)) ?\\ )))
486 nil) ;\$
487 (t (setq nest (1+ nest)))))
488 (if (= (% nest 2) 1) (throw 'dollar t))))))))
489 )
491 (defun YaTeX-math-display-list (list cols)
492 (goto-char (point-max))
493 (if (= cols 0) (if (not (eolp)) (newline 1))
494 (forward-line -1)
495 (while (looking-at "[ \t\n]") (forward-line -1)))
496 (end-of-line)
497 (let ((indent (* YaTeX-math-display-width cols)) sign str to)
498 (indent-to indent)
499 (insert (car list))
500 (indent-to (setq indent (+ indent YaTeX-math-max-key)))
501 (insert "\\" (car (cdr list)))
502 (setq indent (+ indent YaTeX-math-max-seq))
503 (setq sign (YaTeX-math-get-sign list))
504 (while (and sign (not (string= "" sign)))
505 (setq to (string-match "\n" sign)
506 str (if to (substring sign 0 to) sign))
507 (end-of-line)
508 (indent-to indent)
509 (insert str)
510 (cond ((eobp) (newline 1))
511 ((> cols 0) (forward-line 1)))
512 (setq sign (if to (substring sign (1+ to)) "")))))
514 (defvar YaTeX-math-menu-buffer "*math-mode-signs*")
516 (defun YaTeX-math-show-menu (match-str)
517 (save-window-excursion
518 (pop-to-buffer YaTeX-math-menu-buffer)
519 (let ((maxcols (max 1 (/ (screen-width) YaTeX-math-sign-width)))
520 (case-fold-search nil)
521 (cols 0) (list alist) command)
522 (erase-buffer)
523 (insert
524 "Candidates of sign. [n:next p:prev f:forw b:back q:quit RET:select]\n")
525 (insert YaTeX-math-indicator "\t")
526 (insert YaTeX-math-indicator)
527 (newline 1)
528 (insert-char ?- (1- (screen-width)))
529 (newline 1)
530 (while list
531 (if (string-match match-str (car (car list)))
532 (progn (YaTeX-math-display-list (car list) cols)
533 (setq cols (% (1+ cols) maxcols))))
534 (setq list (cdr list)))
535 (goto-line 4)
536 (use-local-map YaTeX-math-menu-map)
537 (unwind-protect
538 (recursive-edit)
539 (skip-chars-backward "^ \t\n")
540 (setq command
541 (if (re-search-forward YaTeX-math-cmd-regexp nil t)
542 (buffer-substring
543 (match-beginning 0)
544 (prog2 (skip-chars-forward "^ \t\n") (point)))
545 nil))
546 (kill-buffer YaTeX-math-menu-buffer))
547 command))
548 )
550 ;
551 (defun YaTeX-math-show-image (image &optional exit-char)
552 "Momentarily display IMAGE at the beginning of the next line;
553 erase it on the next keystroke. The window is recentered if necessary
554 to make the whole string visible. If the window isn't large enough,
555 at least you get to read the beginning."
556 (if (and image (not (string= image "")))
557 (let ((buffer-read-only nil)
558 (modified (buffer-modified-p))
559 (name buffer-file-name)
560 insert-start
561 insert-end)
562 (unwind-protect
563 (progn
564 (save-excursion
565 ;; defeat file locking... don't try this at home, kids!
566 (setq buffer-file-name nil)
567 (forward-line 1)
568 (setq insert-start (point))
569 (if (eobp) (newline))
570 (insert image)
571 (setq insert-end (point)))
572 ; make sure the whole string is visible
573 (if (not (pos-visible-in-window-p insert-end))
574 (recenter (max 0
575 (- (window-height)
576 (count-lines insert-start insert-end)
577 2))))
578 (let ((char (read-char)))
579 (or (eq char exit-char)
580 (setq unread-command-char char))))
581 (if insert-end
582 (save-excursion
583 (delete-region insert-start insert-end)))
584 (setq buffer-file-name name)
585 (set-buffer-modified-p modified)))))
587 (defun YaTeX-math-insert-sequence (&optional force initial)
588 "Insert math-mode sequence with image completion."
589 (interactive "P")
590 (let*((key (or initial "")) regkey str last-char list i
591 (case-fold-search nil) match sign
592 (this-key (char-to-string last-command-char))
593 (alist (symbol-value (cdr (assoc this-key YaTeX-math-key-list))))
594 (n (length alist)) (beg (point)) result)
595 (if initial (insert YaTeX-ec (car (cdr (assoc initial alist)))))
596 (setq result
597 (catch 'complete
598 (if (and (not force)
599 (if YaTeX-auto-math-mode
600 (not (YaTeX-in-math-mode-p))
601 (not YaTeX-math-mode)))
602 (throw 'complete 'escape));this tag should be exit, but...
603 (while t
604 (message "Sequence(TAB for menu): %s" key)
605 (setq last-char (read-char)
606 key (concat key (char-to-string last-char))
607 i 0)
608 (cond
609 ((string= key this-key) ;;invoke key itself
610 (throw 'complete 'escape))
611 ((string= key YaTeX-math-exit-key) ;;exit from math-mode
612 (throw 'complete 'exit))
613 ((string-match "\r" key) ;;RET = kakutei
614 (throw 'complete 'select))
615 ((string-match "[\C-g\C-c]" key) ;;C-g = abort
616 (throw 'complete 'abort))
617 ((string-match "[\t\n]" key) ;;TAB, LFD = menu
618 (throw 'complete 'menu))
619 ((string-match "[\C-h\C-?]" key) ;;BS, DEL = BS
620 (if (< (length key) 2) (throw 'complete 'abort))
621 (setq key (substring key 0 -2))))
623 (setq regkey (concat "^" (regexp-quote key)))
624 (message "Sequence(TAB for menu): %s" key)
625 (if
626 (catch 'found
627 ;;(1)input string strictly matches with alist
628 (setq match (assoc key alist))
629 ;;remember previous match
631 ;;(2)search partial match into alist
632 (setq list alist)
633 (while (< i n)
634 (if (string-match
635 regkey
636 ;;(aref array i)
637 ;;(car (nth i alist))
638 (car (car list)))
639 (progn
640 (or match
641 ;;(setq match (nth i alist))
642 (setq match (car list)))
643 (throw 'found t)))
644 (setq i (1+ i) list (cdr list)))) ;catch 'found
645 nil ;;if any match, continue reading
646 ;;else reading of sequence has been done.
647 (message "complete.")
648 (throw 'complete t))
650 (if match
651 (progn (delete-region beg (point))
652 (setq single-command (car (cdr match)))
653 (insert YaTeX-ec single-command)
654 (if (and YaTeX-math-need-image
655 (setq sign (YaTeX-math-get-sign match)))
656 (YaTeX-math-show-image (concat sign "\n")))
657 )
658 nil)
659 )))
660 (cond
661 ((eq result t)
662 (setq YaTeX-current-completion-type 'maketitle)
664 ;;;(sit-for 1)
665 (setq unread-command-char last-char)
666 (insert (YaTeX-addin single-command)))
667 ((eq result 'abort)
668 (delete-region beg (point))
669 (message "Abort."))
670 ((eq result 'escape)
671 (delete-region beg (point))
672 (call-interactively (global-key-binding this-key)))
673 ((eq result 'select)
674 (message "Done."))
675 ((eq result 'exit)
676 (delete-region beg (point))
677 (YaTeX-toggle-math-mode))
678 ((eq result 'menu)
679 (delete-region beg (point))
680 (setq key (concat "^" (regexp-quote (substring key 0 -1))))
681 (insert (YaTeX-math-show-menu key)))))
682 )
684 ;; ----- Change image completion types -----
685 (defun YaTeX-math-member-p (item)
686 "Check if ITEM is a member of image completion.
687 If so return the cons of its invocation key and image-string."
688 (let ((lists YaTeX-math-key-list) list)
689 (catch 'found
690 (while lists
691 (setq list (symbol-value (cdr (car lists))))
692 (while list
693 (if (string= item (nth 1 (car list)))
694 (throw 'found (cons (car (car lists)) (nth 0 (car list)))))
695 (setq list (cdr list)))
696 (setq lists (cdr lists))))))
698 ;;
699 (provide 'yatexmth)
701 ; Local variables:
702 ; fill-prefix: ";;; "
703 ; paragraph-start: "^$\\| \\|;;;$"
704 ; paragraph-separate: "^$\\| \\|;;;$"
705 ; End: