yatex

view yatex.el @ 59:48ac97a6b6ce

Call drawing tools ID completion (yahtml)
author yuuji
date Wed, 01 May 1996 15:35:40 +0000
parents 3a7c0c2bf16d
children 9e08ed569d80
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; Yet Another tex-mode for emacs.
3 ;;; yatex.el rev. 1.62
4 ;;; (c )1991-1995 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
5 ;;; Last modified Thu May 2 00:13:21 1996 on supra
6 ;;; $Id$
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 (require 'comment)
23 (defconst YaTeX-revision-number "1.62"
24 "Revision number of running yatex.el"
25 )
27 ;---------- Local variables ----------
28 ;;;
29 ;; Initialize local variable for yatex-mode.
30 ;; Preserving user preferred definitions.
31 ;; ** Check all of these defvar-ed values **
32 ;; ** and setq other values more suitable **
33 ;; ** for your site, if needed. **
34 ;;;
35 (defvar YaTeX-prefix "\C-c"
36 "*Prefix key to call YaTeX functions.
37 You can select favorite prefix key by setq in your ~/.emacs."
38 )
39 (defvar YaTeX-environment-indent 1
40 "*Indentation depth at column width in LaTeX environments."
41 )
42 (defvar YaTeX-fill-prefix ""
43 "*fill-prefix used for auto-fill-mode.
44 The default value is null string."
45 )
46 (defvar YaTeX-fill-column 72
47 "*fill-column used for auto-fill-mode."
48 )
49 (defvar YaTeX-comment-prefix "%"
50 "TeX comment prefix."
51 )
52 (defvar YaTeX-current-position-register ?3
53 "*Position register to keep where the last completion was done.
54 All of YaTeX completing input store the current position into
55 the register YaTeX-current-position-register. So every time you
56 make a trip to any other part of text other than you are writing, you can
57 return to the editing paragraph by calling register-to-point with argument
58 YaTeX-current-position-register."
59 )
60 (defvar YaTeX-dos (eq system-type 'ms-dos))
61 (defvar YaTeX-emacs-19 (string= "19" (substring emacs-version 0 2)))
62 (defvar YaTeX-user-completion-table
63 (if YaTeX-dos "~/_yatexrc" "~/.yatexrc")
64 "*Default filename in which user completion table is saved."
65 )
66 ;;(defvar YaTeX-tmp-dic-unit 'main-file
67 ;; "*Default switching unit of temporary dictionary.
68 ;;There are two switching unit:
69 ;;'main-file : switch tmp-dic according to main-file directory.
70 ;;'directory : switch tmp-dic dir by dir."
71 ;;)
72 (defvar YaTeX-japan (or (boundp 'NEMACS) (boundp 'MULE))
73 "Whether yatex mode is running on Japanese environment or not."
74 )
75 (defvar tex-command (if YaTeX-japan "jlatex" "latex")
76 "*Default command for typesetting LaTeX text."
77 )
78 (defvar bibtex-command (if YaTeX-japan "jbibtex" "bibtex")
79 "*Default command of BibTeX."
80 )
81 (defvar dvi2-command ;previewer command for your site
82 (if YaTeX-dos "dviout -wait=0"
83 "xdvi -geo +0+0 -s 4")
84 "*Default previewer command including its option.
85 This default value is for X window system."
86 )
87 (defvar makeindex-command (if YaTeX-dos "makeind" "makeindex")
88 "*Default makeindex command."
89 )
90 (defvar dviprint-command-format
91 (if YaTeX-dos "dviprt %s %f%t"
92 "dvi2ps %f %t %s | lpr")
93 "*Command line string to print out current file.
94 Format string %s will be replaced by the filename. Do not forget to
95 specify the `from usage' and `to usage' with their option by format string
96 %f and %t.
97 See also documentation of dviprint-from-format and dviprint-to-format."
98 )
99 (defvar dviprint-from-format
100 (if YaTeX-dos "%b-" "-f %b")
101 "*`From' page format of dvi filter. %b will turn to beginning page number."
102 )
103 (defvar dviprint-to-format
104 (if YaTeX-dos "%e" "-t %e")
105 "*`To' page format of dvi filter. %e will turn to end page number."
106 )
107 (defvar YaTeX-default-document-style
108 (concat (if YaTeX-japan "j") "article")
109 "*Default LaTeX Documentstyle for YaTeX-typeset-region."
110 )
111 (defvar YaTeX-need-nonstop nil
112 "*T for adding `\\nonstopmode{}' to text before invoking latex command."
113 )
114 (defvar latex-warning-regexp "line.* [0-9]*"
115 "*Regular expression of line number of warning message by latex command."
116 )
117 (defvar latex-error-regexp "l\\.[1-9][0-9]*"
118 "*Regular expression of line number of latex error.
119 Perhaps your latex command stops at this error message with line number of
120 LaTeX source text."
121 )
122 (defvar latex-dos-emergency-message
123 "Emergency stop" ;<- for Micro tex, ASCII-pTeX 1.6
124 "Message pattern of emergency stop of typesetting.
125 Because Demacs (GNU Emacs on DOS) cannot have concurrent process, the
126 latex command which is stopping on a LaTeX error, is terminated by Demacs.
127 Many latex command on DOS display some messages when it is terminated by
128 other process, user or OS. Define to this variable a message string of your
129 latex command on DOS shown at abnormal termination.
130 Remember Demacs's call-process function is not oriented for interactive
131 process."
132 )
133 (defvar latex-message-kanji-code 2
134 "*Kanji coding system latex command types out.
135 1 = Shift JIS, 2 = JIS, 3 = EUC."
136 )
137 (defvar YaTeX-inhibit-prefix-letter nil
138 "*T for changing key definitions from [prefix] Letter to [prefix] C-Letter."
139 )
140 (defvar NTT-jTeX nil
141 "*Use NTT-jTeX for latex command."
142 )
143 (defvar YaTeX-item-regexp (concat (regexp-quote "\\") "\\(sub\\)*item")
144 "*Regular expression of item command."
145 )
146 (defvar YaTeX-nervous t
147 "*If you are nervous about maintenance of yatexrc, set this value to T.
148 And you will have the local dictionary."
149 )
150 (defvar YaTeX-sectioning-regexp
151 "\\(part\\|chapter\\*?\\|\\(sub\\)*\\(section\\|paragraph\\)\\*?\\)\\b"
152 "*LaTeX sectioning commands regexp."
153 )
154 (defvar YaTeX-paragraph-start
155 (concat "^[ \t]*%\\|^[ \t]*$\\|\\'\\|^\C-l\\|\\\\\\\\$\\|^[ \t]*\\\\\\("
156 YaTeX-sectioning-regexp ;sectioning commands
157 "\\|[A-z]*item\\|begin{\\|end{" ;special declaration
158 "\\|newpage\\b\\|vspace\\b"
159 "\\)")
160 "*Paragraph starting regexp of common LaTeX source. Use this value
161 for YaTeX-uncomment-paragraph."
162 )
163 (defvar YaTeX-paragraph-separate
164 (concat "^[ \t]*%\\|^[ \t]*$\\|^\C-l\\|\\\\\\\\$\\|^[ \t]*\\\\\\("
165 YaTeX-sectioning-regexp ;sectioning commands
166 "\\|begin{\\|end{" ;special declaration
167 "\\|newpage\\b\\|vspace\\b"
168 "\\)")
169 "*Paragraph delimiter regexp of common LaTeX source. Use this value
170 for YaTeX-uncomment-paragraph."
171 )
172 (defvar YaTeX-verbatim-environments
173 '("verbatim" "verbatim*")
174 "*Assume these environments of this variable disable LaTeX commands.")
175 (defvar YaTeX-verb-regexp "verb\\*?\\|path"
176 "*Regexp of verb family. Do not contain preceding \\\\ nor \\(\\).")
177 (defvar YaTeX-fill-inhibit-environments
178 (append '("tabular" "tabular*" "array" "picture" "eqnarray" "eqnarray*"
179 "equation" "math" "displaymath")
180 YaTeX-verbatim-environments)
181 "*In these environments, YaTeX inhibits fill-paragraph from formatting.
182 Define those environments as a form of list."
183 )
184 (defvar YaTeX-itemizing-env-regexp
185 "itemize\\|enumerate\\|description\\|list"
186 "*Regexp of itemizing environments")
187 (defvar YaTeX-equation-env-regexp
188 "array\\*?\\|equation\\*?"
189 "*Regexp of environments for equations")
190 (defvar YaTeX-array-env-regexp
191 (concat
192 "array\\*?\\|eqnarray\\*?\\|tabbing\\|tabular\\*?\\|" ;LaTeX
193 "align\\*?\\|split\\*?\\|aligned\\*?\\|alignat\\*?\\|" ;AMS-LaTeX
194 "xalignat\\*?\\|xxalignat\\*?") ;AMS-LaTeX
195 "*Regexp of environments where `&' becomes field delimiter.")
196 (defvar YaTeX-uncomment-once t
197 "*T for removing all continuous commenting character(%).
198 Nil for removing only one commenting character at the beginning-of-line."
199 )
200 (defvar YaTeX-default-pop-window-height 10
201 "Default typesetting buffer height.
202 If integer, sets the window-height of typesetting buffer.
203 If string, sets the percentage of it.
204 If nil, use default pop-to-buffer."
205 )
206 (defvar YaTeX-close-paren-always t
207 "Close parenthesis always when YaTeX-modify-mode is nil."
208 )
209 (defvar YaTeX-no-begend-shortcut nil
210 "*T for disabling shortcut of begin-type completion, [prefix] b d, etc."
211 )
212 (defvar YaTeX-greek-by-maketitle-completion nil
213 "*T for greek letters completion by maketitle-type completion."
214 )
215 (defvar YaTeX-auto-math-mode t
216 "*T for changing YaTeX-math mode automatically.")
217 (defvar YaTeX-use-AMS-LaTeX nil
218 "*T for using AMS-LaTeX"
219 )
220 (defvar yatex-mode-hook nil
221 "*List of functions to be called at the end of yatex-mode initializations."
222 )
223 ;;-- Math mode values --
225 (defvar YaTeX-math-key-list-default
226 '((";" . YaTeX-math-sign-alist)
227 (":" . YaTeX-greek-key-alist))
228 "Default key sequence to invoke math-mode's image completion."
229 )
230 (defvar YaTeX-math-key-list-private nil
231 "*User defined alist, math-mode-prefix vs completion alist."
232 )
233 (defvar YaTeX-math-key-list
234 (append YaTeX-math-key-list-private YaTeX-math-key-list-default)
235 "Key sequence to invoke math-mode's image completion."
236 )
237 (defvar YaTeX-create-file-prefix-g nil
238 "*Non-nil creates new file when [prefix] g on \\include{foo}."
239 )
240 (defvar YaTeX-skip-default-reader nil
241 "Non-nil skips default argument reader of section-type completion."
242 )
243 (defvar YaTeX-simple-messages nil
244 "Non-nil makes minibuffer messages simpler."
245 )
246 (defvar YaTeX-addin-prefix "YaTeX:")
247 ;------------ Completion table ------------
248 ; Set tex-section-like command possible completion
249 (defvar section-table
250 '(("part") ("chapter") ("section") ("subsection")
251 ("subsubsection") ("paragraph") ("subparagraph")
252 ("author") ("thanks") ("documentstyle") ("pagestyle")
253 ("title") ("underline") ("label") ("makebox")
254 ("footnote") ("footnotetext")
255 ("hspace*") ("vspace*") ("bibliography") ("bibitem") ("cite")
256 ("input") ("include") ("includeonly") ("mbox") ("hbox") ("caption")
257 ("newlength") ("setlength" 2) ("addtolength" 2) ("settowidth" 2)
258 ("setcounter" 2) ("addtocounter" 2) ("stepcounter" 2)
259 ("newcommand" 2) ("renewcommand" 2)
260 ("setcounter" 2) ("newenvironment" 3) ("newtheorem" 2)
261 ("cline") ("framebox") ("savebox") ("date") ("put") ("ref")
262 ("frac" 2) ("multicolumn" 3) ("shortstack")
263 )
264 "Default completion table for section-type completion."
265 )
266 (defvar user-section-table nil)
267 (defvar tmp-section-table nil)
269 ; Set tex-environment possible completion
270 (defvar env-table
271 '(("quote") ("quotation") ("center") ("verse") ("document")
272 ("verbatim") ("itemize") ("enumerate") ("description")
273 ("list") ("tabular") ("tabular*") ("table") ("tabbing") ("titlepage")
274 ("sloppypar") ("quotation") ("picture") ("displaymath")
275 ("eqnarray") ("figure") ("equation") ("abstract") ("array")
276 ("thebibliography") ("theindex") ("flushleft") ("flushright")
277 ("minipage")
278 )
279 "Default completion table for begin-type completion."
280 )
281 (defvar user-env-table nil)
282 (defvar tmp-env-table nil)
284 ; Set {\Large }-like completion
285 (defvar fontsize-table
286 '(("rm") ("em") ("bf") ("boldmath") ("it") ("sl") ("sf") ("sc") ("tt")
287 ("dg") ("dm")
288 ("tiny") ("scriptsize") ("footnotesize") ("small")("normalsize")
289 ("large") ("Large") ("LARGE") ("huge") ("Huge")
290 )
291 "Default completion table for large-type completion."
292 )
293 (defvar user-fontsize-table nil)
294 (defvar tmp-fontsize-table nil)
296 (defvar singlecmd-table
297 (append
298 '(("maketitle") ("sloppy") ("protect")
299 ("LaTeX") ("TeX") ("item") ("item[]") ("appendix") ("hline")
300 ;;("rightarrow") ("Rightarrow") ("leftarrow") ("Leftarrow")
301 ("pagebreak") ("newpage") ("clearpage") ("cleardoublepage")
302 ("footnotemark") ("verb") ("verb*")
303 ("linebreak") ("pagebreak") ("noindent") ("indent")
304 ("left") ("right")
305 )
306 (if YaTeX-greek-by-maketitle-completion
307 '(("alpha") ("beta") ("gamma") ("delta") ("epsilon")
308 ("varepsilon") ("zeta") ("eta") ("theta")("vartheta")
309 ("iota") ("kappa") ("lambda") ("mu") ("nu") ("xi") ("pi")
310 ("varpi") ("rho") ("varrho") ("sigma") ("varsigma") ("tau")
311 ("upsilon") ("phi") ("varphi") ("chi") ("psi") ("omega")
312 ("Gamma") ("Delta") ("Theta") ("Lambda")("Xi") ("Pi")
313 ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega"))))
314 "Default completion table for maketitle-type completion."
315 )
316 (defvar user-singlecmd-table nil)
317 (defvar tmp-singlecmd-table nil)
319 ;---------- Key mode map ----------
320 ;;;
321 ;; Create new key map: YaTeX-mode-map
322 ;; Do not change this section.
323 ;;;
324 (defvar YaTeX-mode-map nil
325 "Keymap used in YaTeX mode"
326 )
327 (defvar YaTeX-typesetting-mode-map nil
328 "Keymap used in YaTeX typesetting buffer"
329 )
330 (defvar YaTeX-prefix-map nil
331 "Keymap used when YaTeX-prefix key pushed"
332 )
333 (defvar YaTeX-user-extensional-map (make-sparse-keymap)
334 "*Keymap used for the user's customization")
335 (defvar YaTeX-current-completion-type nil
336 "Has current completion type. This may be used in YaTeX addin functions."
337 )
338 (defvar YaTeX-modify-mode nil
339 "*Current editing mode.
340 When non-nil, each opening parentheses only opens,
341 nil enters both open/close parentheses when opening parentheses key pressed."
342 )
343 (defvar YaTeX-math-mode nil
344 "Holds whether current mode is math-mode."
345 )
346 ;---------- Define default key bindings on YaTeX mode map ----------
347 (defun YaTeX-define-key (key binding &optional map)
348 "Define key on YaTeX-prefix-map."
349 (if YaTeX-inhibit-prefix-letter
350 (let ((c (aref key 0)))
351 (cond
352 ((and (>= c ?a) (<= c ?z)) (aset key 0 (1+ (- c ?a))))
353 ((and (>= c ?A) (<= c ?Z) (numberp YaTeX-inhibit-prefix-letter))
354 (aset key 0 (1+ (- c ?A))))
355 (t nil))))
356 (define-key (or map YaTeX-prefix-map) key binding)
357 )
358 (defun YaTeX-define-begend-key-normal (key env &optional map)
359 "Define short cut YaTeX-make-begin-end key."
360 (YaTeX-define-key
361 key
362 (list 'lambda '(arg) '(interactive "P")
363 (list 'YaTeX-insert-begin-end env 'arg))
364 map)
365 )
366 (defun YaTeX-define-begend-region-key (key env &optional map)
367 "Define short cut YaTeX-make-begin-end-region key."
368 (YaTeX-define-key key (list 'lambda nil '(interactive)
369 (list 'YaTeX-insert-begin-end env t)) map)
370 )
371 (defun YaTeX-define-begend-key (key env &optional map)
372 "Define short cut key for begin type completion both for normal
373 and region mode. To customize YaTeX, user should use this function."
374 (YaTeX-define-begend-key-normal key env map)
375 (if YaTeX-inhibit-prefix-letter nil
376 (YaTeX-define-begend-region-key
377 (concat (upcase (substring key 0 1)) (substring key 1)) env))
378 )
379 ;;;
380 ;; Define key table
381 ;;;
382 (if YaTeX-mode-map
383 nil
384 (setq YaTeX-mode-map (make-sparse-keymap))
385 (setq YaTeX-prefix-map (make-sparse-keymap))
386 (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
387 (define-key YaTeX-mode-map "{" 'YaTeX-insert-braces)
388 (define-key YaTeX-mode-map "(" 'YaTeX-insert-parens)
389 (define-key YaTeX-mode-map "$" 'YaTeX-insert-dollar)
390 (define-key YaTeX-mode-map "&" 'YaTeX-insert-amper)
391 (define-key YaTeX-mode-map "[" 'YaTeX-insert-brackets)
392 (define-key YaTeX-mode-map YaTeX-prefix YaTeX-prefix-map)
393 (define-key YaTeX-mode-map "\M-\C-@" 'YaTeX-mark-environment)
394 (define-key YaTeX-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
395 (define-key YaTeX-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
396 (define-key YaTeX-mode-map "\M-\C-m" 'YaTeX-intelligent-newline)
397 (define-key YaTeX-mode-map "\C-i" 'YaTeX-indent-line)
398 (YaTeX-define-key "%" 'YaTeX-%-menu)
399 (YaTeX-define-key "t" 'YaTeX-typeset-menu)
400 (YaTeX-define-key "w" 'YaTeX-switch-mode-menu)
401 (YaTeX-define-key "'" 'YaTeX-prev-error)
402 (YaTeX-define-key "^" 'YaTeX-visit-main)
403 (YaTeX-define-key "4^" 'YaTeX-visit-main-other-window)
404 (YaTeX-define-key "4g" 'YaTeX-goto-corresponding-*-other-window)
405 (YaTeX-define-key "44" 'YaTeX-switch-to-window)
406 (and YaTeX-emacs-19 window-system
407 (progn
408 (YaTeX-define-key "5^" 'YaTeX-visit-main-other-frame)
409 (YaTeX-define-key "5g" 'YaTeX-goto-corresponding-*-other-frame)
410 (YaTeX-define-key "55" 'YaTeX-switch-to-window)))
411 (YaTeX-define-key " " 'YaTeX-do-completion)
412 (YaTeX-define-key "v" 'YaTeX-version)
414 (YaTeX-define-key "}" 'YaTeX-insert-braces-region)
415 (YaTeX-define-key "]" 'YaTeX-insert-brackets-region)
416 (YaTeX-define-key ")" 'YaTeX-insert-parens-region)
417 (YaTeX-define-key "$" 'YaTeX-insert-dollars-region)
418 (YaTeX-define-key "i" 'YaTeX-fill-item)
419 (YaTeX-define-key
420 "\\" '(lambda () (interactive) (insert "$\\backslash$")))
421 (if YaTeX-no-begend-shortcut
422 (progn
423 (YaTeX-define-key "B" 'YaTeX-make-begin-end-region)
424 (YaTeX-define-key "b" 'YaTeX-make-begin-end))
425 (YaTeX-define-begend-key "bc" "center")
426 (YaTeX-define-begend-key "bd" "document")
427 (YaTeX-define-begend-key "bD" "description")
428 (YaTeX-define-begend-key "be" "enumerate")
429 (YaTeX-define-begend-key "bE" "equation")
430 (YaTeX-define-begend-key "bi" "itemize")
431 (YaTeX-define-begend-key "bl" "flushleft")
432 (YaTeX-define-begend-key "bm" "minipage")
433 (YaTeX-define-begend-key "bt" "tabbing")
434 (YaTeX-define-begend-key "bT" "tabular")
435 (YaTeX-define-begend-key "b\^t" "table")
436 (YaTeX-define-begend-key "bp" "picture")
437 (YaTeX-define-begend-key "bq" "quote")
438 (YaTeX-define-begend-key "bQ" "quotation")
439 (YaTeX-define-begend-key "br" "flushright")
440 (YaTeX-define-begend-key "bv" "verbatim")
441 (YaTeX-define-begend-key "bV" "verse")
442 (YaTeX-define-key "B " 'YaTeX-make-begin-end-region)
443 (YaTeX-define-key "b " 'YaTeX-make-begin-end))
444 (YaTeX-define-key "e" 'YaTeX-end-environment)
445 (YaTeX-define-key "S" 'YaTeX-make-section-region)
446 (YaTeX-define-key "s" 'YaTeX-make-section)
447 (YaTeX-define-key "L" 'YaTeX-make-fontsize-region)
448 (YaTeX-define-key "l" 'YaTeX-make-fontsize)
449 (YaTeX-define-key "m" 'YaTeX-make-singlecmd)
450 (YaTeX-define-key "." 'YaTeX-comment-paragraph)
451 (YaTeX-define-key "," 'YaTeX-uncomment-paragraph)
452 (YaTeX-define-key ">" 'YaTeX-comment-region)
453 (YaTeX-define-key "<" 'YaTeX-uncomment-region)
454 (YaTeX-define-key "g" 'YaTeX-goto-corresponding-*)
455 (YaTeX-define-key "k" 'YaTeX-kill-*)
456 (YaTeX-define-key "c" 'YaTeX-change-*)
457 (YaTeX-define-key "a" 'YaTeX-make-accent)
458 (YaTeX-define-key "?" 'YaTeX-help)
459 (YaTeX-define-key "/" 'YaTeX-apropos)
460 (YaTeX-define-key "&" 'YaTeX-what-column)
461 (YaTeX-define-key "d" 'YaTeX-display-hierarchy)
462 (YaTeX-define-key "x" YaTeX-user-extensional-map)
463 (YaTeX-define-key "n"
464 '(lambda () (interactive) (insert "\\\\")))
465 (if YaTeX-dos
466 (define-key YaTeX-prefix-map "\C-r"
467 '(lambda () (interactive)
468 (set-screen-height YaTeX-saved-screen-height) (recenter))))
469 (mapcar
470 (function
471 (lambda (key)
472 (define-key YaTeX-mode-map (car key) 'YaTeX-math-insert-sequence)))
473 YaTeX-math-key-list)
474 )
476 (if YaTeX-typesetting-mode-map nil
477 (setq YaTeX-typesetting-mode-map (make-keymap))
478 ;(suppress-keymap YaTeX-typesetting-mode-map t)
479 (define-key YaTeX-typesetting-mode-map " " 'YaTeX-jump-error-line)
480 (define-key YaTeX-typesetting-mode-map "\C-m" 'YaTeX-send-string)
481 )
483 (defvar YaTeX-section-completion-map nil
484 "*Key map used at YaTeX completion in the minibuffer.")
485 (if YaTeX-section-completion-map nil
486 (setq YaTeX-section-completion-map
487 (copy-keymap (or (and (boundp 'gmhist-completion-map)
488 gmhist-completion-map)
489 minibuffer-local-completion-map)))
490 (define-key YaTeX-section-completion-map
491 " " 'YaTeX-minibuffer-complete)
492 (define-key YaTeX-section-completion-map
493 "\C-i" 'YaTeX-minibuffer-complete)
494 (define-key YaTeX-section-completion-map
495 "\C-v" 'YaTeX-read-section-with-overview))
497 (defvar YaTeX-recursive-map nil
498 "*Key map used at YaTeX reading arguments in the minibuffer.")
499 (if YaTeX-recursive-map nil
500 (setq YaTeX-recursive-map (copy-keymap global-map))
501 (define-key YaTeX-recursive-map YaTeX-prefix YaTeX-prefix-map))
503 ;; (define-key YaTeX-recursive-map
504 ;; (concat YaTeX-prefix (if YaTeX-inhibit-prefix-letter "\C-s" "s"))
505 ;; 'YaTeX-make-section)
506 ;; (define-key map
507 ;; (concat YaTeX-prefix (if YaTeX-inhibit-prefix-letter "\C-m" "m"))
508 ;; 'YaTeX-make-singlecmd)
509 ;; (define-key map
510 ;; (concat YaTeX-prefix (if YaTeX-inhibit-prefix-letter "\C-l" "l"))
511 ;; 'YaTeX-make-fontsize)
514 ;---------- Define other variable ----------
515 (defvar env-name "document" "*Initial tex-environment completion")
516 (defvar section-name "documentstyle" "*Initial tex-section completion")
517 (defvar fontsize-name "large" "*Initial fontsize completion")
518 (defvar single-command "maketitle" "*Initial LaTeX single command")
519 (defvar YaTeX-user-table-is-read nil
520 "Flag that means whether user completion table has been read or not."
521 )
522 (defvar YaTeX-kanji-code-alist nil
523 "Kanji-code expression translation table."
524 )
525 (if (boundp 'MULE)
526 (setq YaTeX-kanji-code-alist
527 (list (cons
528 1
529 (if YaTeX-dos (if (boundp '*sjis-dos*) *sjis-dos* *sjis*dos)
530 *sjis*))
531 '(2 . *junet*) '(3 . *euc-japan*))
532 ))
533 (defvar YaTeX-kanji-code (if YaTeX-dos 1 2)
534 "*File kanji code used by Japanese TeX."
535 )
536 (defvar YaTeX-coding-system nil "File coding system used by Japanese TeX.")
537 (defvar YaTeX-latex-message-code "Process coding system for LaTeX.")
538 (cond
539 ((boundp 'MULE)
540 (setq YaTeX-coding-system
541 (symbol-value (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist))))
542 (if (not YaTeX-dos)
543 (setq YaTeX-latex-message-code *autoconv*)))
544 ((boundp 'NEMACS)
545 (setq YaTeX-latex-message-code latex-message-kanji-code))
546 )
547 (defvar YaTeX-parent-file nil
548 "*Main LaTeX source file name used when %#! expression doesn't exist.")
549 (make-variable-buffer-local 'YaTeX-parent-file)
551 ;---------- Provide YaTeX-mode ----------
552 ;;;
553 ;; Major mode definition
554 ;;;
555 (defun yatex-mode ()
556 " Yet Another LaTeX mode: Major mode for editing input files of LaTeX.
557 -You can invoke processes concerning LaTeX typesetting by
558 \\[YaTeX-typeset-menu]
559 -Complete LaTeX environment form of `\\begin{env} ... \\end{env}' by
560 \\[YaTeX-make-begin-end]
561 -Enclose region into some environment by
562 \\[universal-argument] \\[YaTeX-make-begin-end]
563 -Complete LaTeX command which takes argument like `\\section{}' by
564 \\[YaTeX-make-section]
565 -Put LaTeX command which takes no arguments like `\\maketitle' by
566 \\[YaTeX-make-singlecmd]
567 -Complete font or character size descriptor like `{\\large }' by
568 \\[YaTeX-make-fontsize]
569 -Enclose region into those descriptors above by
570 \\[universal-argument] \\[YaTeX-make-fontsize]
571 -Enter European accent notations by
572 \\[YaTeX-make-accent]
573 -Toggle various modes of YaTeX by
574 \\[YaTeX-switch-mode-menu]
575 -Change environt name (on the begin/end line) by
576 \\[YaTeX-change-*]
577 -Kill LaTeX command/environment sequences by
578 \\[YaTeX-kill-*]
579 -Kill LaTeX command/environment with its contents
580 \\[universal-argument] \\[YaTeX-kill-*]
581 -Go to corresponding object (begin/end, file, labels) by
582 \\[YaTeX-goto-corresponding-*] or
583 \\[YaTeX-goto-corresponding-*-other-window] (in other window)
584 \\[YaTeX-goto-corresponding-*-other-frame] (in other frame)
585 -Go to main LaTeX source text by
586 \\[YaTeX-visit-main] or
587 \\[YaTeX-visit-main-other-window] (in other window)
588 \\[YaTeX-visit-main-other-frame] (in other frame)
589 -Comment out or uncomment region by
590 \\[YaTeX-comment-region] or \\[YaTeX-uncomment-region]
591 -Comment out or uncomment paragraph by
592 \\[YaTeX-comment-paragraph] or \\[YaTeX-uncomment-paragraph]
593 -Make an \\item entry hang-indented by
594 \\[YaTeX-fill-item]
595 -Enclose the region with parentheses by
596 \\[YaTeX-insert-parens-region]
597 \\[YaTeX-insert-braces-region]
598 \\[YaTeX-insert-brackets-region]
599 \\[YaTeX-insert-dollars-region]
600 -Look up the corresponding column header of tabular environment by
601 \\[YaTeX-what-column]
602 -Enter a newline and an entry suitable for environment by
603 \\[YaTeX-intelligent-newline]
604 -View the structure of file inclusion by
605 \\[YaTeX-display-hierarchy]
606 -Refer the online help of popular LaTeX commands by
607 \\[YaTeX-help] (help)
608 \\[YaTeX-apropos] (apropos)
609 -Edit `%# notation' by
610 \\[YaTeX-%-menu]
612 Those are enough for fastening your editing of LaTeX source. But further
613 more features are available and they are documented in the manual.
614 "
615 (interactive)
616 (kill-all-local-variables)
617 (setq major-mode 'yatex-mode)
618 (setq mode-name (if YaTeX-japan "‚â‚Ä‚Ó" "YaTeX"))
619 (mapcar 'make-local-variable
620 '(dvi2-command fill-column fill-prefix
621 tmp-env-table tmp-section-table tmp-fontsize-table
622 tmp-singlecmd-table paragraph-start paragraph-separate
623 YaTeX-math-mode indent-line-function
624 comment-start comment-start-skip
625 ))
626 (cond ((boundp 'MULE)
627 (set-file-coding-system YaTeX-coding-system))
628 ((boundp 'NEMACS)
629 (make-local-variable 'kanji-fileio-code)
630 (setq kanji-fileio-code YaTeX-kanji-code)))
631 (setq fill-column YaTeX-fill-column
632 fill-prefix YaTeX-fill-prefix
633 paragraph-start YaTeX-paragraph-start
634 paragraph-separate YaTeX-paragraph-separate
635 indent-line-function 'YaTeX-indent-line
636 comment-start YaTeX-comment-prefix
637 ;;comment-start-skip "[^\\\\]%+[ \t]*"
638 )
639 (use-local-map YaTeX-mode-map)
640 (if YaTeX-dos (setq YaTeX-saved-screen-height (screen-height)))
641 (YaTeX-read-user-completion-table)
642 (and (fboundp 'YaTeX-19-collect-macros) (YaTeX-19-collect-macros))
643 (run-hooks 'text-mode-hook 'yatex-mode-hook)
644 )
646 ;---------- Define YaTeX-mode functions ----------
647 (defvar YaTeX-ec "\\" "Escape character of current mark-up language.")
648 (defvar YaTeX-ec-regexp (regexp-quote YaTeX-ec))
649 (defvar YaTeX-struct-begin
650 (concat YaTeX-ec "begin{%1}%2")
651 "Keyword to begin environment.")
652 (defvar YaTeX-struct-end (concat YaTeX-ec "end{%1}")
653 "Keyword to end environment.")
654 (defvar YaTeX-struct-name-regexp "[^}]+"
655 "Environment name regexp.")
656 (defvar YaTeX-TeX-token-regexp
657 (cond (YaTeX-japan "[A-Za-z*‚ -‚ñˆŸ-êž]+")
658 (t "[A-Za-z*]+"))
659 "Regexp of characters which can be a member of TeX command's name.")
660 (defvar YaTeX-command-token-regexp YaTeX-TeX-token-regexp
661 "Regexp of characters which can be a member of current mark up language's command name.")
663 ;;(defvar YaTeX-struct-section
664 ;; (concat YaTeX-ec "%1{%2}")
665 ;; "Keyword to make section.")
667 ;;;
668 ;; autoload section
669 ;;;
670 ;;autoload from yatexlib(general functions).
671 (autoload 'YaTeX-showup-buffer "yatexlib" "YaTeX library" t)
672 (autoload 'YaTeX-window-list "yatexlib" "YaTeX library" t)
673 (autoload 'YaTeX-search-active-forward "yatexlib" "YaTeX library" t)
674 (autoload 'YaTeX-search-active-backward "yatexlib" "YaTeX library" t)
675 (autoload 'substitute-all-key-definition "yatexlib" "YaTeX library" t)
676 (autoload 'YaTeX-switch-to-buffer "yatexlib" "YaTeX library" t)
677 (autoload 'YaTeX-switch-to-buffer-other-window "yatexlib" "YaTeX library" t)
678 (autoload 'YaTeX-replace-format "yatexlib" "YaTeX library" t)
679 (autoload 'YaTeX-replace-format-args "yatexlib" "YaTeX library" t)
680 (autoload 'rindex "yatexlib" "YaTeX library" t)
681 (autoload 'YaTeX-match-string "yatexlib" "YaTeX library" t)
682 (autoload 'YaTeX-minibuffer-complete "yatexlib" "YaTeX library" t)
683 (autoload 'goto-buffer-window "yatexlib" "YaTeX library" t)
684 (autoload 'split-window-calculate-height "yatexlib" "YaTeX library" t)
685 (autoload 'read-string-with-history "yatexlib" "YaTeX library" t)
686 (autoload 'read-from-minibuffer-with-history "yatexlib" "YaTeX library" t)
687 (autoload 'completing-read-with-history "yatexlib" "YaTeX library" t)
688 (autoload 'YaTeX-switch-to-window "yatexlib" "For windows.el" t)
690 ;;autoload from yatexprc.el
691 (autoload 'YaTeX-visit-main "yatexprc" "Visit main LaTeX file." t)
692 (autoload 'YaTeX-visit-main-other-window "yatexprc"
693 "Visit main other window." t)
694 (autoload 'YaTeX-main-file-p "yatexprc" "Check if the file is main." t)
695 (autoload 'YaTeX-get-builtin "yatexprc" "Get %# built-in." t)
696 (autoload 'YaTeX-system "yatexprc" "Call system command" t)
698 ;;autoload from yatexmth.el
699 (autoload 'YaTeX-math-insert-sequence "yatexmth" "Image input." t)
700 (autoload 'YaTeX-in-math-mode-p "yatexmth" "Check if in math-env." t)
701 (autoload 'YaTeX-toggle-math-mode "yatexmth" "YaTeX math-mode interfaces." t)
702 (autoload 'YaTeX-math-member-p "yatexmth" "Check if a word is math command." t)
704 ;;autoload from yatexhlp.el
705 (autoload 'YaTeX-help "yatexhlp" "YaTeX helper with LaTeX commands." t)
706 (autoload 'YaTeX-apropos "yatexhlp" "Apropos for (La)TeX commands." t)
708 ;;autoload from yatexgen.el
709 (autoload 'YaTeX-generate "yatexgen" "YaTeX add-in function generator." t)
710 (autoload 'YaTeX-generate-simple "yatexgen" "YaTeX add-in support." t)
712 ;;autoload from yatexsec.el
713 (autoload 'YaTeX-read-section-in-minibuffer "yatexsec" "YaTeX sectioning" t)
714 (autoload 'YaTeX-make-section-with-overview "yatexsec" "YaTeX sectioning" t)
716 ;;autoload from yatexenv.el
717 (autoload 'YaTeX-what-column "yatexenv" "YaTeX env. specific funcs" t)
718 (autoload 'YaTeX-intelligent-newline "yatexenv" "YaTeX env. specific funcs" t)
719 (autoload 'YaTeX-indent-line-equation "yatexenv" "Indent equation lines." t)
720 (autoload 'YaTeX-goto-corresponding-leftright "yatexenv" "\left\right jumps" t)
722 ;;autoload from yatexhie.el
723 (autoload 'YaTeX-display-hierarchy "yatexhie"
724 "YaTeX document hierarchy browser" t)
726 ;;;
727 ;; YaTeX-mode functions
728 ;;;
729 (defun YaTeX-insert-begin-end (env region-mode)
730 "Insert \\begin{mode-name} and \\end{mode-name}.
731 This works also for other defined begin/end tokens to define the structure."
732 (setq YaTeX-current-completion-type 'begin)
733 (let*((ccol (current-column)) beg beg2 exchange
734 (arg region-mode) ;for old compatibility
735 (indent-column (+ ccol YaTeX-environment-indent))(i 1) func)
736 (if (and region-mode (> (point) (mark)))
737 (progn (exchange-point-and-mark)
738 (setq exchange t
739 ccol (current-column)
740 indent-column (+ ccol YaTeX-environment-indent))))
741 ;;VER2 (insert "\\begin{" env "}" (YaTeX-addin env))
742 (setq beg (point))
743 (YaTeX-insert-struc 'begin env)
744 (setq beg2 (point))
745 (insert "\n")
746 (indent-to indent-column)
747 (save-excursion
748 ;;indent optional argument of \begin{env}, if any
749 (while (> (point-beginning-of-line) beg)
750 (skip-chars-forward "\\s " (point-end-of-line))
751 (indent-to indent-column)
752 (forward-line -1)))
753 (require 'yatexenv)
754 (if region-mode
755 ;;if region-mode, indent all text in the region
756 (save-excursion
757 (if (fboundp (intern-soft (concat "YaTeX-enclose-" env)))
758 (funcall (intern-soft (concat "YaTeX-enclose-" env))
759 (point) (mark))
760 (while (< (progn (forward-line 1) (point)) (mark))
761 (if (eolp) nil
762 (skip-chars-forward " \t\n")
763 (indent-to indent-column))))))
764 (if region-mode (exchange-point-and-mark))
765 (indent-to ccol)
766 ;;VER2 (insert "\\end{" env "}\n")
767 (YaTeX-insert-struc 'end env)
768 (YaTeX-reindent ccol)
769 (if region-mode
770 (progn
771 (insert "\n")
772 (or exchange (exchange-point-and-mark)))
773 (goto-char beg2)
774 (YaTeX-intelligent-newline nil))
775 (if YaTeX-current-position-register
776 (point-to-register YaTeX-current-position-register)))
777 )
779 (defun YaTeX-make-begin-end (arg)
780 "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
781 by completing read.
782 If you invoke this command with universal argument,
783 \(key binding for universal-argument is \\[universal-argument]\)
784 you can put REGION into that environment between \\begin and \\end."
785 (interactive "P")
786 (let*
787 ((mode (if arg " region" ""))
788 (env
789 (YaTeX-read-environment
790 (format "Begin environment%s(default %s): " mode env-name))))
791 (if (string= env "")
792 (setq env env-name))
793 (setq env-name env)
794 (YaTeX-update-table
795 (list env-name) 'env-table 'user-env-table 'tmp-env-table)
796 (YaTeX-insert-begin-end env-name arg))
797 )
799 (defun YaTeX-make-begin-end-region ()
800 "Call YaTeX-make-begin-end with ARG to specify region mode."
801 (interactive)
802 (YaTeX-make-begin-end t)
803 )
805 (defun YaTeX-inner-environment (&optional quick)
806 "Return current inner-most environment.
807 Non-nil for optional argument QUICK restricts search bound to most
808 recent sectioning command. Matching point is stored to property 'point
809 of 'YaTeX-inner-environment, which can be referred by
810 (get 'YaTeX-inner-environment 'point)."
811 (let*((nest 0)
812 (beg (YaTeX-replace-format-args
813 (regexp-quote YaTeX-struct-begin)
814 YaTeX-struct-name-regexp
815 (if (eq major-mode 'yahtml-mode) "\\s *.*" "")
816 ""))
817 (end (YaTeX-replace-format-args
818 (regexp-quote YaTeX-struct-end)
819 YaTeX-struct-name-regexp "" ""))
820 (begend (concat "\\(" beg "\\)\\|\\(" end "\\)"))
821 bound m0
822 (open
823 (concat "^" (or (cdr (assq major-mode '((yahtml-mode . "<")))) "{")))
824 (close
825 (concat "^" (or (cdr(assq major-mode '((yahtml-mode . " >")))) "}"))))
826 (save-excursion
827 (if quick
828 (setq bound
829 (save-excursion
830 (YaTeX-re-search-active-backward
831 (concat YaTeX-ec-regexp
832 "\\(" YaTeX-sectioning-regexp "\\)\\*?\\{")
833 YaTeX-comment-prefix nil 1)
834 (or (bobp) (end-of-line))
835 (point))))
836 (if (catch 'begin
837 (if (and (numberp bound) (< (point) bound)) (throw 'begin nil))
838 (while (YaTeX-re-search-active-backward
839 begend YaTeX-comment-prefix bound t)
840 (setq m0 (match-beginning 0))
841 (if (looking-at end) ;;(match-beginning 2)
842 (setq nest (1+ nest))
843 (setq nest (1- nest)))
844 (if (< nest 0)
845 (progn
846 (put 'YaTeX-inner-environment 'point m0)
847 (goto-char m0)
848 (put 'YaTeX-inner-environment 'indent (current-column))
849 (throw 'begin t)))))
850 (buffer-substring
851 (progn (skip-chars-forward open) (1+ (point)))
852 (progn (skip-chars-forward close) (point))))))
853 )
855 (defun YaTeX-end-environment ()
856 "Close opening environment"
857 (interactive)
858 (let ((curp (point))
859 (env (YaTeX-inner-environment))
860 (md (match-data)))
862 (if (not env) (error "No premature environment")
863 (save-excursion
864 (if (YaTeX-search-active-forward
865 (YaTeX-replace-format-args YaTeX-struct-end env "" "")
866 YaTeX-comment-prefix nil t)
867 (if (y-or-n-p
868 (concat "Environment `" env
869 "' may be already closed. Force close?"))
870 nil
871 (error "end environment aborted."))))
872 (message "") ;Erase (y or n) message.
873 ;(insert "\\end{" env "}")
874 (YaTeX-insert-struc 'end env)
875 (store-match-data md)
876 (setq curp (point))
877 (goto-char (match-end 0))
878 (if (pos-visible-in-window-p)
879 (sit-for (if YaTeX-dos 2 1))
880 (message "Matches with %s at line %d"
881 (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
882 (count-lines (point-min) (point))))
883 (goto-char curp))
884 )
885 )
887 ;;;VER2
888 (defun YaTeX-insert-struc (what env)
889 (cond
890 ((eq what 'begin)
891 (insert (YaTeX-replace-format-args
892 YaTeX-struct-begin env (YaTeX-addin env))))
893 ((eq what 'end)
894 (insert (YaTeX-replace-format-args YaTeX-struct-end env)))
895 (t nil))
896 )
898 (defun YaTeX-make-section (arg &optional beg end cmd)
899 "Make LaTeX \\section{} type command with completing read.
900 With numeric ARG, you can specify the number of arguments of
901 LaTeX command.
902 For example, if you want to produce LaTeX command
904 \\addtolength{\\topmargin}{8mm}
906 which has two arguments. You can produce that sequence by typing...
907 ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
908 \(by default\)
909 Then yatex will automatically complete `addtolength' with two arguments
910 next time.
911 You can complete symbol at LaTeX command and the 1st argument.
913 If the optional 2nd and 3rd argument BEG END are specified, enclose
914 the region from BEG to END into the first argument of the LaTeX sequence.
915 Optional 4th arg CMD is LaTeX command name, for non-interactive use."
916 (interactive "P")
917 (setq YaTeX-current-completion-type 'section)
918 (unwind-protect
919 (let*
920 ((source-window (selected-window))
921 (section
922 (or cmd
923 (YaTeX-read-section
924 (if YaTeX-simple-messages
925 (format "Section-type (default %s): " section-name)
926 (if (> (minibuffer-depth) 0)
927 (format "%s???{} (default %s)%s: " YaTeX-ec section-name
928 (format "[level:%d]" (minibuffer-depth)))
929 (format "(C-v for view-section) %s???{} (default %s): "
930 YaTeX-ec section-name)))
931 nil)))
932 (section (if (string= section "") section-name section))
933 (numarg ;; The number of section-type command's argument
934 (or arg
935 (nth 1 (YaTeX-lookup-table section 'section))
936 1))
937 (arg-reader (intern-soft (concat "YaTeX::" section)))
938 (addin-args (and arg-reader (fboundp arg-reader)))
939 (title "")
940 (j 1)
941 (enable-recursive-minibuffers t));;let
942 (setq section-name section)
943 (if beg
944 (let ((e (make-marker)))
945 (goto-char end)
946 (insert "}")
947 (set-marker e (point))
948 (goto-char beg)
949 (insert YaTeX-ec section-name "{")
950 (goto-char (marker-position e)))
951 (use-global-map YaTeX-recursive-map)
952 (if (= numarg 0) (YaTeX-make-singlecmd section-name)
953 (insert YaTeX-ec section-name (YaTeX-addin section-name)))
954 (while (<= j numarg)
955 (insert
956 "{"
957 (setq title
958 (cond
959 (addin-args (funcall arg-reader j))
960 (YaTeX-skip-default-reader "")
961 (t
962 (read-string (format "Argument %d of %s: " j section)))))
963 "}")
964 (setq j (1+ j))))
965 (YaTeX-update-table
966 (if (/= numarg 1) (list section numarg)
967 (list section))
968 'section-table 'user-section-table 'tmp-section-table)
969 (if YaTeX-current-position-register
970 (point-to-register YaTeX-current-position-register))
971 (if (string= (buffer-substring (- (point) 2) (point)) "{}")
972 (forward-char -1))
973 (while (string= (buffer-substring (- (point) 3) (1- (point))) "{}")
974 (forward-char -2)))
975 (if (<= (minibuffer-depth) 0) (use-global-map global-map)))
976 )
978 (defun YaTeX-make-section-region (args beg end)
979 "Call YaTeX-make-section with arguments to specify region mode."
980 (interactive "P\nr")
981 (YaTeX-make-section args beg end)
982 )
984 (defun YaTeX-make-fontsize (arg &optional fontsize)
985 "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
986 If you invoke this command with universal argument, you can put region
987 into {\\xxx } braces.
988 \(key binding for universal-argument is \\[universal-argument]\)"
989 (interactive "P")
990 (YaTeX-sync-local-table 'tmp-fontsize-table)
991 (let* ((mode (if arg "region" ""))
992 (fontsize
993 (or fontsize
994 (YaTeX-read-fontsize
995 (if YaTeX-simple-messages
996 (format "Font or size (default %s): " fontsize-name)
997 (format "{\\??? %s} (default %s)%s: " mode fontsize-name
998 (if (> (minibuffer-depth) 0)
999 (format "[level:%d]" (minibuffer-depth)) "")))
1000 nil nil))))
1001 (if (string= fontsize "")
1002 (setq fontsize fontsize-name))
1003 (setq fontsize-name fontsize)
1004 (YaTeX-update-table
1005 (list fontsize-name)
1006 'fontsize-table 'user-fontsize-table 'tmp-fontsize-table)
1007 (if arg
1008 (save-excursion
1009 (if (> (point) (mark)) (exchange-point-and-mark))
1010 (insert "{\\" fontsize-name " ")
1011 (exchange-point-and-mark)
1012 (insert "}"))
1013 (insert "{\\" fontsize-name " }")
1014 (if YaTeX-current-position-register
1015 (point-to-register YaTeX-current-position-register))
1016 (forward-char -1)))
1019 (defun YaTeX-make-fontsize-region ()
1020 "Call function:YaTeX-make-fontsize with ARG to specify region mode."
1021 (interactive)
1022 (YaTeX-make-fontsize t)
1025 (defvar YaTeX-singlecmd-suffix "" "*Suffix for maketitle-type commands.")
1026 (defvar YaTeX-read-singlecmd-history nil "Holds maketitle-type history.")
1027 (put 'YaTeX-read-singlecmd-history 'no-default t)
1028 (defun YaTeX-make-singlecmd (single)
1029 (interactive
1030 (list (YaTeX-cplread-with-learning
1031 (if YaTeX-simple-messages
1032 (format "maketitle-type (default %s): " single-command)
1033 (format "%s??? (default %s)%s: " YaTeX-ec single-command
1034 (if (> (minibuffer-depth) 0)
1035 (format "[level:%d]" (minibuffer-depth)) "")))
1036 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table
1037 nil nil nil 'YaTeX-read-singlecmd-history)))
1038 (if (string= single "")
1039 (setq single single-command))
1040 (setq single-command single)
1041 (setq YaTeX-current-completion-type 'maketitle)
1042 (let ((dollar (and (not (YaTeX-in-math-mode-p))
1043 (YaTeX-math-member-p single-command)))
1044 p q)
1045 (if dollar (insert "$"))
1046 (insert YaTeX-ec single-command)
1047 (setq p (point))
1048 (insert (YaTeX-addin single) YaTeX-singlecmd-suffix)
1049 (if dollar (insert "$"))
1050 (setq q (point))
1051 (goto-char p)
1052 (forward-char -2)
1053 (if (looking-at "\\[\\]") (forward-char 1) (goto-char q)))
1054 (if YaTeX-current-position-register
1055 (point-to-register YaTeX-current-position-register))
1058 (defvar YaTeX-completion-begin-regexp "[{\\]"
1059 "Regular expression of limit where LaTeX command's completion begins.")
1061 (defun YaTeX-do-completion ()
1062 "Try completion on LaTeX command preceding point."
1063 (interactive)
1064 (if
1065 (or (eq (preceding-char) ? )
1066 (eq (preceding-char) ?\t)
1067 (eq (preceding-char) ?\n)
1068 (bobp))
1069 (message "Nothing to complete.") ;Do not complete
1070 (let* ((end (point))
1071 (limit (point-beginning-of-line))
1072 (completion-begin
1073 (progn (re-search-backward "[ \t\n]" limit 1) (point)))
1074 (begin (progn
1075 (goto-char end)
1076 (if (re-search-backward YaTeX-completion-begin-regexp
1077 completion-begin t)
1078 (1+ (point))
1079 nil))))
1080 (goto-char end)
1081 (cond
1082 ((null begin)
1083 (message "I think it is not a LaTeX sequence."))
1084 (t
1085 (mapcar 'YaTeX-sync-local-table
1086 '(tmp-section-table tmp-env-table tmp-singlecmd-table))
1087 (let*((pattern (buffer-substring begin end))
1088 (all-table
1089 (append
1090 section-table user-section-table tmp-section-table
1091 env-table user-env-table tmp-env-table
1092 singlecmd-table user-singlecmd-table tmp-singlecmd-table))
1093 ;; First,
1094 ;; search completion without backslash.
1095 (completion (try-completion pattern all-table)))
1096 (if
1097 (eq completion nil)
1098 ;; Next,
1099 ;; search completion with backslash
1100 (setq completion
1101 (try-completion (buffer-substring (1- begin) end)
1102 all-table nil)
1103 begin (1- begin)))
1104 (cond
1105 ((null completion)
1106 (message (concat "Can't find completion for '" pattern "'"))
1107 (ding))
1108 ((eq completion t) (message "Sole completion."))
1109 ((not (string= completion pattern))
1110 (kill-region begin end)
1111 (insert completion)
1113 (t
1114 (message "Making completion list...")
1115 (with-output-to-temp-buffer "*Help*"
1116 (display-completion-list
1117 (all-completions pattern all-table))))))))))
1120 (defun YaTeX-toggle-modify-mode (&optional arg)
1121 (interactive "P")
1122 (or (memq 'YaTeX-modify-mode mode-line-format)
1123 (setq mode-line-format
1124 (append (list "" 'YaTeX-modify-mode) mode-line-format)))
1125 (if (or arg (null YaTeX-modify-mode))
1126 (progn
1127 (setq YaTeX-modify-mode "*m*")
1128 (message "Modify mode"))
1129 (setq YaTeX-modify-mode nil)
1130 (message "Cancel modify mode."))
1131 (set-buffer-modified-p (buffer-modified-p)) ;redraw mode-line
1134 (defun YaTeX-switch-mode-menu (arg &optional char)
1135 (interactive "P")
1136 (message "Toggle: (M)odify-mode ma(T)h-mode")
1137 (let ((c (or char (read-char))))
1138 (cond
1139 ((= c ?m) (YaTeX-toggle-modify-mode arg))
1140 ((or (= c ?$) (= c ?t))
1141 (if YaTeX-auto-math-mode
1142 (message "Makes no sense in YaTeX-auto-math-mode.")
1143 (YaTeX-toggle-math-mode arg)))))
1146 (defun YaTeX-insert-quote ()
1147 (interactive)
1148 (insert
1149 (cond
1150 ((YaTeX-literal-p) ?\")
1151 ((= (preceding-char) ?\\ ) ?\")
1152 ;((= (preceding-char) ?\( ) ?\")
1153 ((or (= (preceding-char) 32)
1154 (= (preceding-char) 9)
1155 (= (preceding-char) ?\n)
1156 (bobp)
1157 (string-match
1158 (regexp-quote (char-to-string (preceding-char)))
1159 "ABCDHIuvwxyz()"))
1160 "``")
1161 (t "''")))
1164 (defun YaTeX-closable-p ()
1165 (and (not YaTeX-modify-mode)
1166 (not (eq YaTeX-close-paren-always 'never))
1167 (or YaTeX-close-paren-always (eolp))
1168 (not (input-pending-p))
1169 (not (YaTeX-literal-p)))
1170 ;;(or YaTeX-modify-mode
1171 ;; (and (not YaTeX-close-paren-always) (not (eolp)))
1172 ;; (input-pending-p)
1173 ;; (YaTeX-quick-in-environment-p "verbatim"))
1176 (defun YaTeX-insert-braces-region (beg end &optional open close)
1177 (interactive "r")
1178 (save-excursion
1179 (goto-char end)
1180 (insert (or close "}"))
1181 (goto-char beg)
1182 (insert (or open "{")))
1185 (defun YaTeX-insert-braces (arg &optional open close)
1186 (interactive "p")
1187 (let (env)
1188 (cond
1189 ((YaTeX-jmode) (YaTeX-self-insert arg))
1190 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1191 ((save-excursion
1192 (and (> (- (point) (point-min)) 6)
1193 (condition-case () (forward-char -6) (error nil)))
1194 (looking-at "\\\\left\\\\"))
1195 (insert "{\\right\\}")
1196 (forward-char -8))
1197 ((and (> (point) (+ (point-min) 4))
1198 (save-excursion (backward-char 4) (looking-at "\\\\end"))
1199 (not (YaTeX-literal-p))
1200 (setq env (YaTeX-inner-environment)))
1201 (momentary-string-display
1202 (concat
1203 "{"
1204 (cond
1205 (YaTeX-japan
1206 (format "¡“x‚©‚ç‚Í‚¿‚á‚ñ‚Æ %s b ‚ðŽg‚¢‚Ü‚µ‚傤" YaTeX-prefix))
1207 (t (format "You don't understand Zen of `%s b':p" YaTeX-prefix)))
1208 "}")
1209 (point))
1210 (insert (or open "{") env (or close "}")))
1211 (t
1212 (insert (or open "{") (or close "}"))
1213 (forward-char -1))))
1216 (defun YaTeX-jmode ()
1217 (or (and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
1218 (and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*))
1221 (defun YaTeX-jmode-off ()
1222 (cond
1223 ((and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
1224 (canna-toggle-japanese-mode))
1225 ((and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
1226 (egg:toggle-egg-mode-on-off))
1227 ((and (fboundp 'skk-mode)) (skk-mode -1))
1228 ((and (fboundp 'fep-force-off) (fep-force-off))))
1231 (defun YaTeX-self-insert (arg)
1232 (call-interactively (global-key-binding (char-to-string last-command-char))))
1234 (defun YaTeX-insert-brackets (arg)
1235 "Insert Kagi-kakko or \\ [ \\] pair or simply \[."
1236 (interactive "p")
1237 (let ((col (1- (current-column))))
1238 (cond
1239 ((YaTeX-jmode) (YaTeX-self-insert arg))
1240 ((not (YaTeX-closable-p))
1241 (YaTeX-self-insert arg))
1242 ((save-excursion
1243 (and (> (- (point) (point-min)) 5) (forward-char -5))
1244 (looking-at "\\\\left"))
1245 (insert "[\\right]")
1246 (forward-char -7))
1247 ((and (= (preceding-char) ?\\ )
1248 (/= (char-after (- (point) 2)) ?\\ )
1249 (not (YaTeX-in-math-mode-p)))
1250 (insert last-command-char "\n")
1251 (indent-to (max 0 col))
1252 (insert "\\]")
1253 (beginning-of-line)
1254 (open-line 1)
1255 (delete-region (point) (progn (beginning-of-line) (point)))
1256 (indent-to (+ YaTeX-environment-indent (max 0 col)))
1257 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1)))
1258 ((YaTeX-closable-p)
1259 (insert "[]")
1260 (backward-char 1))
1261 (t (YaTeX-self-insert arg)))
1265 (defun YaTeX-insert-brackets-region (beg end)
1266 (interactive "r")
1267 (YaTeX-insert-braces-region beg end "[" "]")
1270 (defun YaTeX-insert-parens (arg)
1271 "Insert parenthesis pair."
1272 (interactive "p")
1273 (cond
1274 ((YaTeX-jmode) (YaTeX-self-insert arg))
1275 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1276 ((save-excursion
1277 (and (> (- (point) (point-min)) 5) (forward-char -5))
1278 (looking-at "\\\\left"))
1279 (insert "(\\right)")
1280 (forward-char -7))
1281 ((and (= (preceding-char) ?\\ ) (not (YaTeX-in-math-mode-p)))
1282 (insert "(\\)")
1283 (backward-char 2))
1284 ((YaTeX-closable-p)
1285 (insert "()")
1286 (backward-char 1))
1287 (t (YaTeX-self-insert arg)))
1290 (defun YaTeX-insert-parens-region (beg end)
1291 (interactive "r")
1292 (YaTeX-insert-braces-region beg end "(" ")")
1295 (defun YaTeX-insert-dollar ()
1296 (interactive)
1297 (if (or (not (YaTeX-closable-p))
1298 (= (preceding-char) 92)
1299 (and (YaTeX-in-math-mode-p)
1300 (or (/= (preceding-char) ?$) (/= (following-char) ?$))))
1301 (insert "$")
1302 (insert "$$")
1303 (forward-char -1)
1304 (YaTeX-jmode-off)
1305 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1)))
1308 (defun YaTeX-insert-dollars-region (beg end)
1309 (interactive "r")
1310 (YaTeX-insert-braces-region beg end "$" "$")
1313 (defun YaTeX-insert-amper ()
1314 (interactive)
1315 (if (or (string-match YaTeX-array-env-regexp
1316 (or (YaTeX-inner-environment t) "document"))
1317 (= (preceding-char) 92)
1318 (YaTeX-literal-p))
1319 (insert "&")
1320 (insert "\\&"))
1323 (defun YaTeX-version ()
1324 "Return string of the version of running YaTeX."
1325 (interactive)
1326 (message
1327 (concat "Yet Another tex-mode "
1328 (if YaTeX-japan "u–ì’¹v" "`Wild Bird'")
1329 " Revision "
1330 YaTeX-revision-number))
1333 (defun YaTeX-typeset-menu (arg &optional char)
1334 "Typeset, preview, visit error and miscellaneous convenient menu.
1335 Optional second argument CHAR is for non-interactive call from menu."
1336 (interactive "P")
1337 (message
1338 (concat "J)latex R)egion B)ibtex mk(I)ndex "
1339 (if (not YaTeX-dos) "K)ill-latex ")
1340 "P)review "
1341 (and (boundp 'window-system) window-system "S)earch ")
1342 "V)iewerr L)pr"))
1343 (let ((sw (selected-window)) (c (or char (read-char))))
1344 (require 'yatexprc) ;for Nemacs's bug
1345 (select-window sw)
1346 (cond
1347 ((= c ?j) (YaTeX-typeset-buffer))
1348 ((= c ?r) (YaTeX-typeset-region))
1349 ((= c ?b) (YaTeX-call-command-on-file
1350 bibtex-command "*YaTeX-bibtex*"))
1351 ((= c ?i) (YaTeX-call-command-on-file
1352 makeindex-command "*YaTeX-makeindex*"))
1353 ((= c ?k) (YaTeX-kill-typeset-process YaTeX-typeset-process))
1354 ((= c ?p) (call-interactively 'YaTeX-preview))
1355 ((= c ?q) (YaTeX-system "lpq" "*Printer queue*"))
1356 ((= c ?v) (YaTeX-view-error))
1357 ((= c ?l) (YaTeX-lpr arg))
1358 ((= c ?m) (YaTeX-switch-mode-menu arg))
1359 ((= c ?b) (YaTeX-insert-string "\\"))
1360 ((= c ?s) (YaTeX-xdvi-remote-search arg))))
1363 (defun YaTeX-%-menu (&optional beg end char)
1364 "Operate %# notation."
1365 ;;Do not use interactive"r" for the functions which require no mark
1366 (interactive)
1367 (message "!)Edit-%%#! B)EGIN-END-region L)Edit-%%#LPR")
1368 (let ((c (or char (read-char))) (string "") key
1369 (b (make-marker)) (e (make-marker)))
1370 (save-excursion
1371 (cond
1372 ((or (= c ?!) (= c ?l)) ;Edit `%#!'
1373 (goto-char (point-min))
1374 (setq key (cond ((= c ?!) "%#!")
1375 ((= c ?l) "%#LPR")))
1376 (if (re-search-forward key nil t)
1377 (progn
1378 (setq string (buffer-substring (point) (point-end-of-line)))
1379 (delete-region (point) (progn (end-of-line) (point))))
1380 (open-line 1)
1381 (delete-region (point) (progn (beginning-of-line)(point)));for 19 :-<
1382 (insert key))
1383 (unwind-protect
1384 (setq string (read-string (concat key ": ") string))
1385 (insert string)))
1387 ((= c ?b) ;%#BEGIN %#END region
1388 (or end (setq beg (min (point) (mark)) end (max (point) (mark))))
1389 (set-marker b beg)
1390 (set-marker e end)
1391 (goto-char (point-min))
1392 (while (re-search-forward "^%#\\(BEGIN\\)\\|\\(END\\)$" nil t)
1393 (beginning-of-line)
1394 (delete-region (point) (progn (forward-line 1) (point))))
1395 (goto-char (marker-position b))
1396 (open-line 1)
1397 (delete-region (point) (progn (beginning-of-line)(point)));for 19 :-<
1398 (insert "%#BEGIN")
1399 (goto-char (marker-position e))
1400 (insert "%#END\n"))
1401 )))
1404 (defun YaTeX-goto-corresponding-label (reverse &optional otherwin)
1405 "Jump to corresponding \\label{} and \\ref{} or \\cite and \\bibitem.
1406 The default search direction depends on the command at the cursor position.
1407 When the cursor is on \\ref(\\cite), YaTeX will try to search the
1408 corresponding \\label(\\bibitem) backward,
1409 and if it fails search forward again. And when the cursor is
1410 on \\label(\\bibitem), YaTeX will search the corresponding \\ref(\\cite)
1411 forward at first and secondary backward.
1412 Argument REVERSE non-nil makes the default
1413 direction rule reverse. Since Search string is automatically set in
1414 search-last-string, you can repeat search the same label/ref by typing
1415 \\[isearch-forward] or \\[isearch-backward].
1416 If optional second argument OTHERWIN is non-nil, move to other window."
1418 (let ((scmd "") label direc string blist (p (point)) (cb (current-buffer))
1419 (refcommands "label\\|ref\\|cite\\|bibitem")
1420 (func (function (lambda (string sfunc)
1421 (or
1422 (funcall sfunc string nil t)
1423 (funcall (if (eq sfunc 'search-forward)
1424 'search-backward 'search-forward)
1425 string nil t))))))
1426 (cond
1427 ((YaTeX-on-section-command-p refcommands)
1428 (setq scmd (cdr (assoc (YaTeX-match-string 1)
1429 '(("label" . "ref") ("ref" . "label")
1430 ("cite" . "bibitem") ("bibitem" . "cite")))))
1431 (goto-char (match-end 0))
1432 (let ((label (buffer-substring
1433 (1- (point)) (progn (backward-list 1) (1+ (point))))))
1434 (setq string (concat "\\" scmd "{" label "}"))
1435 (setq direc (if (string-match "ref\\|cite" scmd)
1436 'search-forward 'search-backward))
1437 (if YaTeX-current-position-register
1438 (point-to-register YaTeX-current-position-register))
1439 (if reverse (setq direc (if (eq direc 'search-forward)
1440 'search-backward 'search-forward)))
1441 (if (funcall func string direc) ;label/ref found!
1442 (progn
1443 (if otherwin
1444 (progn
1445 (goto-char p)
1446 (if (one-window-p)
1447 (split-window-calculate-height
1448 YaTeX-default-pop-window-height))
1449 (select-window (get-lru-window))
1450 (switch-to-buffer cb)))
1451 (goto-char (match-beginning 0))
1452 (push-mark p))
1453 ;;if label/ref not found, search through all yatex buffers.
1454 (goto-char p) ;resume position of current buffer
1455 (setq blist (YaTeX-yatex-buffer-list))
1456 (catch 'found
1457 (while blist
1458 (set-buffer (car blist))
1459 (if (YaTeX-on-section-command-p refcommands)
1460 (goto-char (match-beginning 0)))
1461 (if (funcall func string direc)
1462 (progn
1463 (cond
1464 (otherwin
1465 (set-buffer cb)
1466 (goto-char p)
1467 (if (one-window-p)
1468 (split-window-calculate-height
1469 YaTeX-default-pop-window-height))
1470 (select-window (get-lru-window))
1471 (switch-to-buffer (car blist)))
1472 ((or (get-buffer-window (car blist))
1473 (and YaTeX-emacs-19
1474 (get-buffer-window (car blist) t)))
1475 (goto-buffer-window (car blist)))
1476 (t
1477 (switch-to-buffer (car blist))
1478 (message
1479 (format "Type %s %c to return to original position."
1480 (key-description
1481 (car
1482 (or (where-is-internal 'register-to-point)
1483 (where-is-internal 'jump-to-register))))
1484 YaTeX-current-position-register))))
1485 (goto-char (match-beginning 0))
1486 (throw 'found t)))
1487 (setq blist (cdr blist)))))
1489 (if YaTeX-emacs-19
1490 (setq search-ring (cons string search-ring))
1491 (setq search-last-string string)))
1492 (t nil)))
1495 (defun YaTeX-goto-corresponding-environment (&optional allow-mismatch noerr)
1496 "Go to corresponding begin/end enclosure.
1497 Optional argument ALLOW-MISMATCH allows mismatch open/clese. Use this
1498 for \left(, \right).
1499 Optional third argument NOERR causes no error for unballanced environment."
1500 (interactive)
1501 (if (not (YaTeX-on-begin-end-p)) nil
1502 (let ((p (match-end 0)) b0 b1 env (nest 0) regexp re-s (op (point))
1503 (m0 (match-beginning 0)) ;whole matching
1504 (m1 (match-beginning 1)) ;environment in \begin{}
1505 (m2 (match-beginning 2))) ;environment in \end{}
1506 ;(setq env (regexp-quote (buffer-substring p (match-beginning 0))))
1507 (if (cond
1508 (m1 ;if begin{xxx}
1509 (setq env
1510 (if allow-mismatch YaTeX-struct-name-regexp
1511 (regexp-quote (buffer-substring m1 (match-end 1)))))
1512 ; (setq regexp (concat "\\(\\\\end{" env "}\\)\\|"
1513 ; "\\(\\\\begin{" env "}\\)"))
1514 (setq regexp
1515 (concat
1516 "\\("
1517 (YaTeX-replace-format-args
1518 (regexp-quote YaTeX-struct-end) env "" "")
1519 "\\)\\|\\("
1520 (YaTeX-replace-format-args
1521 (regexp-quote YaTeX-struct-begin) env "" "")
1522 "\\)"))
1523 (setq re-s 're-search-forward))
1524 (m2 ;if end{xxx}
1525 (setq env
1526 (if allow-mismatch YaTeX-struct-name-regexp
1527 (regexp-quote (buffer-substring m2 (match-end 2)))))
1528 ; (setq regexp (concat "\\(\\\\begin{" env "}\\)\\|"
1529 ; "\\(\\\\end{" env "}\\)"))
1530 (setq regexp
1531 (concat
1532 "\\("
1533 (YaTeX-replace-format-args
1534 (regexp-quote YaTeX-struct-begin) env "" "")
1535 "\\)\\|\\("
1536 (YaTeX-replace-format-args
1537 (regexp-quote YaTeX-struct-end) env "" "")
1538 "\\)"))
1539 (setq re-s 're-search-backward))
1540 (t (if noerr nil (error "Corresponding environment not found."))))
1541 (progn
1542 (while (and (>= nest 0) (funcall re-s regexp nil t))
1543 (setq b0 (match-beginning 0) b1 (match-beginning 1))
1544 (if (or (equal b0 m0)
1545 (YaTeX-literal-p b0))
1546 nil
1547 (setq nest (if (equal b0 b1)
1548 (1- nest) (1+ nest)))))
1549 (if (< nest 0)
1550 (goto-char (match-beginning 0)) ;found.
1551 (goto-char op)
1552 (funcall
1553 (if noerr 'message 'error)
1554 "Corresponding environment `%s' not found." env)
1555 (sit-for 1)
1556 nil)))))
1559 ;(defun YaTeX-goto-corresponding-file (&optional other)
1560 ; "Visit or switch buffer of corresponding file,
1561 ;looking at \\input or \\include or \includeonly on current line."
1562 ; (if (not (YaTeX-on-includes-p)) nil
1563 ; (let ((parent buffer-file-name) input-file)
1564 ; (save-excursion
1565 ; (if (search-forward "{" (point-end-of-line) t)
1566 ; nil
1567 ; (skip-chars-backward "^,{"))
1568 ; (setq input-file
1569 ; (buffer-substring
1570 ; (point) (progn (skip-chars-forward "^ ,}") (point))))
1571 ; (if (not (string-match "\\.\\(tex\\|sty\\)$" input-file))
1572 ; (setq input-file (concat input-file ".tex"))))
1573 ; (cond
1574 ; (other (YaTeX-switch-to-buffer-other-window input-file))
1575 ; ((get-file-buffer input-file) (goto-buffer-window input-file))
1576 ; (t (YaTeX-switch-to-buffer input-file)))
1577 ; (or (YaTeX-get-builtin "!")
1578 ; YaTeX-parent-file
1579 ; (setq YaTeX-parent-file parent))))
1580 ;)
1582 (defun YaTeX-goto-corresponding-BEGIN-END ()
1583 (if (not (YaTeX-on-BEGIN-END-p)) nil
1584 (if (cond
1585 ((equal (match-beginning 0) (match-beginning 1)) ;if on %#BEGIN
1586 (not (search-forward "%#END" nil t)))
1587 (t ; if on %#END
1588 (not (search-backward "%#BEGIN" nil t))))
1589 (error "Corresponding %%#BEGIN/END not found."))
1590 (beginning-of-line)
1591 t)
1594 (defvar YaTeX-processed-file-regexp-alist nil
1595 "Alist of regexp of processed file regexp vs. its file name part;
1596 For example, if you include image file with `\\epsfile{file=FILE}' where
1597 `FILE' is processed file. You might want to view FILE with other previewer
1598 such as ghostview, or want to preview its source which was drawn with
1599 other drawing tool, tgif for example. Then you should set entire regexp
1600 of including expression and enclose its file name part with \\\\( and \\\\).
1602 Ex. (\"\\\\\\\\epsfile{[^}]*file=\\\\([^,} ]+\\\\)\\\\(\\\\.e?ps\\\\)?[^}]*}\" 1)
1604 Where the first group surrounded by \\\\( and \\\\) is the file name part
1605 of expression. So you should set 1 to second element. And the first
1606 matching group is sent to (image) processor defined by the variable
1607 YaTeX-file-processor-alist. See also the documentation of
1608 YaTeX-file-processor-alist.
1610 ª‚¶‚á—Ç‚­‚í‚©‚ñ‚È‚¢‚·‚ËB—Ⴆ‚Î tgif hoge.obj ‚µ‚Ä hoge.eps ‚ð
1611 \\epsfile{file=hoge.eps} ‚ŃCƒ“ƒNƒ‹[ƒh‚µ‚Ä‚¢‚é‚Æ‚µ‚悤B‚»‚Ìs‚Å
1612 \[prefix\] g ‚ð‰Ÿ‚µ‚½Žž‚É tgif ‚ð‹N“®‚µ‚Ä—~‚µ‚©‚Á‚½‚çA‚Ü‚¸ã‚̂悤‚È
1613 ³‹K•\Œ»‚ðÝ’è‚·‚éB\\\\(‚Æ\\\\)‚ň͂ñ‚¾‚Æ‚±‚낪ƒtƒ@ƒCƒ‹–¼‚É‚È‚é‚悤‚É
1614 ’ˆÓ‚·‚éB‚Ńtƒ@ƒCƒ‹–¼•”•ª‚ª‰½”Ô–Ú‚Ì\\\\(\\\\)‚É‚È‚é‚©‚ðƒŠƒXƒg‚Ì2”Ô–Ú‚É‘‚­B
1615 ‚·‚é‚ÆA‚»‚Ì•”•ª‚ª•Ï” YaTeX-file-processor-alist ‚Å’è‹`‚³‚ꂽ
1616 ˆ—ƒvƒƒOƒ‰ƒ€‚É“n‚³‚ê‚éB‚Æ‚¢‚¤‚킯B
1617 ‚ñ`‚â‚Á‚Ï‚è‚Þ‚¸‚©‚µ‚¢‚ËB•ª‚©‚ç‚È‚¢Žž‚Í—×‚Ì Lisper ‚É•·‚­‚©A
1618 fj–ì’¹‚̉ï‚Å•·‚±‚¤!
1619 ")
1621 (defvar YaTeX-processed-file-regexp-alist-default
1622 '(("\\\\epsfile{[^},]*file=\\([^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 1)
1623 ("\\\\epsfig{[^},]*fi\\(le\\|gure\\)=\\([^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1624 ("\\\\postscriptbox{[^}]*}{[^}]*}{\\([^} ]+\\)\\(\\.e?ps\\)?}" 1)
1625 ("\\\\\\(epsfbox\\|includegraphics\\){\\([^} ]+\\)\\(\\.e?ps\\)?}" 2)
1626 ("\\\\\\(include\\|input\\){\\([^},.]+\\)\\(\\.\\(tex\\|sty\\)\\)?}" 2 t)
1628 "See the documentation of YaTeX-processed-file-regexp-alist."
1631 (defvar YaTeX-file-processor-alist nil
1632 "*Alist of files' processor vs. its extension;
1633 See also the documentation of YaTeX-processed-file-regexp-alist."
1635 (defvar YaTeX-file-processor-alist-default
1636 '(("tgif" . ".obj")
1637 ("ghostview" . ".ps")
1638 ("ghostview" . ".eps")
1639 (t . ".tex")
1640 (t . ".sty")
1641 (t . ""))
1642 "See the documentation of YaTeX-file-processor-alist."
1645 (defun YaTeX-goto-corresponding-file-processor (&optional other)
1646 "Execute corresponding file processor."
1647 (save-excursion
1648 (or (looking-at YaTeX-ec-regexp)
1649 (skip-chars-backward (concat "^" YaTeX-ec) (point-beginning-of-line)))
1650 (let ((list (append YaTeX-processed-file-regexp-alist
1651 YaTeX-processed-file-regexp-alist-default))
1652 (p (point)) flist file
1653 (peol (point-end-of-line)))
1654 (setq flist (catch 'found
1655 (while list
1656 (goto-char p)
1657 (if (re-search-forward (car (car list)) peol t)
1658 (progn
1659 (setq file (YaTeX-match-string
1660 (car (cdr (car list)))))
1661 (throw 'found (cdr (car list)))))
1662 (setq list (cdr list)))))
1663 (if flist ;if pattern and file name found
1664 (let*((plist (append YaTeX-file-processor-alist
1665 YaTeX-file-processor-alist-default))
1666 (plist0 plist)
1667 ext cmd src buf (alt (car (cdr flist))))
1668 (if (and (re-search-forward
1669 (concat YaTeX-comment-prefix "\\s *\\(.*\\)$") peol t)
1670 (assoc (setq cmd (YaTeX-match-string 1))
1671 YaTeX-file-processor-alist))
1672 (setq src ;if processor is specified
1673 (concat file
1674 (cdr (assoc cmd YaTeX-file-processor-alist))))
1675 (while plist ;if processor is not specified
1676 (setq ext (cdr (car plist)))
1677 (if (file-exists-p (concat file ext))
1678 (setq cmd (car (car plist))
1679 src (concat file ext) plist nil))
1680 (setq plist (cdr plist)))
1681 (if (and (null src) alt YaTeX-create-file-prefix-g)
1682 (setq cmd alt
1683 src (concat file (cdr (assoc alt plist0))))))
1684 (if src ;if processor and src file found
1685 (cond
1686 ((stringp cmd)
1687 (let ((buf (concat "* " cmd " " src " *")))
1688 (YaTeX-system (concat cmd " " src) buf)
1689 t))
1690 ((eq t cmd)
1691 (let ((parent buffer-file-name))
1692 (funcall
1693 (cond
1694 (other 'YaTeX-switch-to-buffer-other-window)
1695 ((get-file-buffer src) 'goto-buffer-window)
1696 (t 'YaTeX-switch-to-buffer))
1697 src)
1698 (or (YaTeX-get-builtin "!")
1699 YaTeX-parent-file
1700 (setq YaTeX-parent-file parent))
1701 t))
1702 ((symbolp cmd)
1703 (cond
1704 ((symbol-function cmd)
1705 (funcall cmd src)))
1706 t)))))))
1709 (defun YaTeX-on-section-command-p (command)
1710 "Check if point is on the LaTeX command: COMMAND(regexp).
1711 Return nil if point is not on it. Otherwise return the
1712 number of argument position.
1713 Section command name is stored in match-data #1."
1714 (let ((p (point)) md (parg 0) (argc 1) word (grouping 0) (i 0))
1715 (while (setq i (string-match "\\\\(" command i))
1716 (setq grouping (1+ grouping) i (+ i 2)))
1717 (save-excursion
1718 (if (looking-at YaTeX-ec-regexp) nil
1719 (catch 'found ;caught value has no meaning
1720 (while t
1721 (if (bobp) (throw 'found nil))
1722 (cond
1723 ((looking-at YaTeX-ec-regexp) (throw 'found t))
1724 ((looking-at "[[{]") nil)
1725 ((looking-at "[]}]")(condition-case nil (up-list -1) (error nil)))
1726 (t (skip-chars-backward " \t\r\n")))
1727 (skip-chars-backward (concat "^ \t\r\n{}[]" YaTeX-ec-regexp))
1728 (or (bobp) (forward-char -1)))))
1729 (if (and
1730 (looking-at (concat YaTeX-ec-regexp "\\(" command "\\)"
1731 "\\(\\(\\[[^]]+\\]\\)*\\)" ;optional arg
1732 "[ \t\n\r]*{[^}]+}")) ;arg braces
1733 (not (YaTeX-lookup-table
1734 (setq word (YaTeX-match-string 1)) 'singlecmd)))
1735 (progn
1736 (setq md (match-data))
1737 (skip-chars-forward "^{")
1738 (if (<= (point) p) (setq parg (1+ parg)))
1739 (setq argc
1740 (or (car (cdr (YaTeX-lookup-table word 'section)))
1741 argc))
1742 (while (and (>= (setq argc (1- argc)) 0)
1743 (progn (skip-chars-forward " \t\n\r")
1744 (looking-at "{")))
1745 (forward-list 1)
1746 (if (<= (point) p) (setq parg (1+ parg))))
1747 (store-match-data md)
1748 (setq i (+ 2 grouping))
1749 (if (and (match-beginning i)
1750 (>= p (match-beginning i)) (< p (match-end i)))
1751 -1 ;return -1 if point is on optional arg
1752 (if (< p (point)) parg))
1753 ))))
1756 (defun YaTeX-on-maketitle-p ()
1757 "Check if point is on maketitle type commands.
1758 Call this function after YaTeX-on-section-command-p."
1759 (let ((p (point)))
1760 (save-excursion
1761 (or (= (char-after (point)) ?\\ )
1762 (progn
1763 (skip-chars-backward
1764 (concat "^" YaTeX-ec-regexp) (point-beginning-of-line))
1765 (or (bobp) (bolp) (backward-char 1))))
1766 (and (looking-at (concat YaTeX-ec-regexp YaTeX-TeX-token-regexp))
1767 (<= (match-beginning 0) p)
1768 (> (match-end 0) p)))))
1770 (defun YaTeX-on-begin-end-p ()
1771 (save-excursion
1772 (beginning-of-line)
1773 (re-search-forward
1774 ;;"\\\\begin{\\([^}]+\\)}\\|\\\\end{\\([^}]+\\)}"
1775 (concat
1776 (YaTeX-replace-format-args
1777 (regexp-quote YaTeX-struct-begin)
1778 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" "")
1779 "\\|"
1780 (YaTeX-replace-format-args
1781 (regexp-quote YaTeX-struct-end)
1782 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" ""))
1783 (point-end-of-line) t))
1786 (defun YaTeX-on-includes-p ()
1787 (save-excursion
1788 (beginning-of-line)
1789 (re-search-forward "\\(\\(include.*\\)\\|\\(input\\)\\){.*}"
1790 (point-end-of-line) t))
1793 (defun YaTeX-on-comment-p (&optional sw)
1794 "Return t if current line is commented out.
1795 Optional argument SW t to treat all `%' lines as comment,
1796 even if on `%#' notation."
1797 (save-excursion
1798 (beginning-of-line)
1799 (skip-chars-forward "\\s ")
1800 (looking-at (if sw "%" "%[^#]")))
1803 (defun YaTeX-on-BEGIN-END-p ()
1804 (save-excursion
1805 (let ((case-fold-search nil))
1806 (beginning-of-line)
1807 (re-search-forward "\\(%#BEGIN\\)\\|\\(%#END\\)" (point-end-of-line) t)))
1810 (defun YaTeX-goto-corresponding-* (arg)
1811 "Parse current line and call suitable function."
1812 (interactive "P")
1813 (cond
1814 ((YaTeX-goto-corresponding-label arg))
1815 ((YaTeX-goto-corresponding-environment))
1816 ((YaTeX-goto-corresponding-file-processor arg))
1817 ;;((YaTeX-goto-corresponding-file))
1818 ((YaTeX-goto-corresponding-BEGIN-END))
1819 ((and (string-match
1820 YaTeX-equation-env-regexp ;to delay loading
1821 (or (YaTeX-inner-environment t) "document"))
1822 (YaTeX-goto-corresponding-leftright)))
1823 (t (message "I don't know where to go.")))
1826 (defun YaTeX-goto-corresponding-*-other-window (arg)
1827 "Parse current line and call suitable function."
1828 (interactive "P")
1829 (cond
1830 ((YaTeX-goto-corresponding-label arg t))
1831 ;;((YaTeX-goto-corresponding-environment))
1832 ((YaTeX-goto-corresponding-file t))
1833 ;;((YaTeX-goto-corresponding-BEGIN-END))
1834 (t (message "I don't know where to go.")))
1837 (defun YaTeX-comment-region (alt-prefix)
1838 "Comment out region by '%'.
1839 If you call this function on the 'begin{}' or 'end{}' line,
1840 it comments out whole environment"
1841 (interactive "P")
1842 (if (not (YaTeX-on-begin-end-p))
1843 (comment-out-region
1844 (if alt-prefix
1845 (read-string "Insert prefix: ")
1846 YaTeX-comment-prefix))
1847 (YaTeX-comment-uncomment-env 'comment-out-region))
1850 (defun YaTeX-uncomment-region (alt-prefix)
1851 "Uncomment out region by '%'."
1852 (interactive "P")
1853 (if (not (YaTeX-on-begin-end-p))
1854 (uncomment-region
1855 (if alt-prefix (read-string "Remove prefix: ")
1856 YaTeX-comment-prefix)
1857 (region-beginning) (region-end) YaTeX-uncomment-once)
1858 (YaTeX-comment-uncomment-env 'uncomment-region))
1861 (defun YaTeX-comment-uncomment-env (func)
1862 "Comment or uncomment out one LaTeX environment switching function by FUNC."
1863 (let (beg (p (point)))
1864 (save-excursion
1865 (beginning-of-line)
1866 (setq beg (point))
1867 (YaTeX-goto-corresponding-environment)
1868 (beginning-of-line)
1869 (if (> p (point)) (setq beg (1+ beg)) (forward-char 1))
1870 (funcall func YaTeX-comment-prefix beg (point) YaTeX-uncomment-once)))
1871 (message "%sommented out current environment."
1872 (if (eq func 'comment-region) "C" "Un-c"))
1875 (defun YaTeX-beginning-of-environment (&optional limit-search-bound end)
1876 "Goto the beginning of the current environment.
1877 Optional argument LIMIT-SEARCH-BOUND non-nil limits the search bound to
1878 most recent sectioning command. Non-nil for optional third argument END
1879 goes to end of environment."
1880 (interactive)
1881 (let ((op (point)))
1882 (if (YaTeX-inner-environment limit-search-bound)
1883 (progn
1884 (goto-char (get 'YaTeX-inner-environment 'point))
1885 (and end (YaTeX-goto-corresponding-environment))
1886 (if (interactive-p) (push-mark op))
1887 t)))
1890 (defun YaTeX-end-of-environment (&optional limit-search-bound)
1891 "Goto the end of the current environment.
1892 Optional argument LIMIT-SEARCH-BOUND non-nil limits the search bound
1893 to most recent sectioning command."
1894 (interactive)
1895 (YaTeX-beginning-of-environment limit-search-bound t)
1898 (defun YaTeX-mark-environment ()
1899 "Mark current position and move point to end of environment."
1900 (interactive)
1901 (let ((curp (point)))
1902 (if (and (YaTeX-on-begin-end-p) (match-beginning 1)) ;if on \\begin
1903 (forward-line 1)
1904 (beginning-of-line))
1905 (if (not (YaTeX-end-of-environment)) ;arg1 turns to match-beginning 1
1906 (progn
1907 (goto-char curp)
1908 (error "Cannot found the end of current environment."))
1909 (YaTeX-goto-corresponding-environment)
1910 (beginning-of-line) ;for confirmation
1911 (if (< curp (point))
1912 (progn
1913 (message "Mark this environment?(y or n): ")
1914 (if (= (read-char) ?y) nil
1915 (goto-char curp)
1916 (error "Abort. Please call again at more proper position."))))
1917 (set-mark-command nil)
1918 (YaTeX-goto-corresponding-environment)
1919 (end-of-line)
1920 (if (eobp) nil (forward-char 1))))
1923 (defun YaTeX-comment-paragraph ()
1924 "Comment out current paragraph."
1925 (interactive)
1926 (save-excursion
1927 (cond
1928 ((YaTeX-on-begin-end-p)
1929 (beginning-of-line)
1930 (insert YaTeX-comment-prefix)
1931 (YaTeX-goto-corresponding-environment)
1932 (beginning-of-line)
1933 (insert YaTeX-comment-prefix))
1934 ((YaTeX-on-comment-p)
1935 (message "Already commented out."))
1936 (t
1937 (mark-paragraph)
1938 (if (looking-at paragraph-separate) (forward-line 1))
1939 (comment-out-region "%"))))
1942 (defun YaTeX-uncomment-paragraph ()
1943 "Uncomment current paragraph."
1944 (interactive)
1945 (save-excursion
1946 (if (YaTeX-on-begin-end-p)
1947 (let ((p (make-marker)))
1948 (set-marker p (point))
1949 (YaTeX-goto-corresponding-environment)
1950 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once)
1951 (goto-char (marker-position p))
1952 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once))
1953 (if (YaTeX-on-comment-p)
1954 (let*((fill-prefix "")
1955 ;;append `^%' to head of paragraph delimiter.
1956 (paragraph-start
1957 (concat
1958 "^$\\|^%\\(" YaTeX-paragraph-delimiter "\\)"))
1959 (paragraph-separate paragraph-start))
1960 (mark-paragraph)
1961 (if (not (bobp)) (forward-line 1))
1962 (uncomment-region "%" nil nil YaTeX-uncomment-once))
1963 (message "This line is not a comment line."))))
1966 (defun YaTeX-remove-prefix (prefix &optional once)
1967 "Remove prefix on current line as far as prefix detected. But
1968 optional argument ONCE makes deletion once."
1969 (interactive "sPrefix:")
1970 (beginning-of-line)
1971 (while (re-search-forward (concat "^" prefix) (point-end-of-line) t)
1972 (replace-match "")
1973 (if once (end-of-line)))
1976 (defun YaTeX-kill-option-string ()
1977 (if (and (eq predicate 'YaTeX-on-begin-end-p)
1978 (looking-at "\\(\\[.*\\]\\)*\\({.*}\\)*"))
1979 (delete-region (match-beginning 0) (match-end 0)))
1982 (defun YaTeX-kill-some-pairs (predicate gofunc kill-contents)
1983 "Kill some matching pair.
1984 This function assumes that pairs occupy each line where they resid."
1985 ;;(interactive)
1986 (if (not (funcall predicate)) nil
1987 (let ((beg (make-marker)) (end (make-marker)) (p (make-marker)))
1988 (set-marker end (match-end 0))
1989 (if (match-beginning 2)
1990 (set-marker beg (match-beginning 2))
1991 (set-marker beg (match-beginning 1))
1992 (goto-char (match-end 0))
1993 (YaTeX-kill-option-string))
1994 (save-excursion
1995 (funcall gofunc)
1996 (delete-region (point-beginning-of-line) (match-end 0))
1997 (YaTeX-kill-option-string)
1998 (if (and (eolp) (not (eobp))) (delete-char 1))
1999 (set-marker p (point))
2000 (goto-char beg)
2001 (delete-region (point-beginning-of-line) end)
2002 (if (and (eolp) (not (eobp))) (delete-char 1))
2003 (if kill-contents (delete-region p (point))))
2004 t))
2007 (defun YaTeX-kill-section-command (point kill-all)
2008 "Kill section-type command at POINT leaving its argument.
2009 Non-nil for the second argument kill its argument too."
2010 (let (beg (end (make-marker)))
2011 (save-excursion
2012 (goto-char point)
2013 (or (looking-at YaTeX-ec-regexp)
2014 (progn
2015 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
2016 (forward-char -1)))
2017 (setq beg (point))
2018 (skip-chars-forward "^{")
2019 (forward-list 1)
2020 (set-marker end (point))
2021 (if kill-all (delete-region beg end)
2022 (goto-char beg)
2023 (delete-region
2024 (point) (progn (skip-chars-forward "^{" end) (1+ (point))))
2025 (goto-char end)
2026 (backward-delete-char 1))))
2029 (defun YaTeX-kill-paren (kill-contents)
2030 "Kill parentheses leaving its contents.
2031 But kill its contents if the argument KILL-CONTENTS is non-nil."
2032 (save-excursion
2033 (let (p)
2034 (if (looking-at "\\s(\\|\\(\\s)\\)")
2035 (progn
2036 (if (match-beginning 1)
2037 (up-list -1))
2038 (setq p (point))
2039 (forward-list 1)
2040 (if kill-contents (delete-region p (point))
2041 (backward-delete-char 1)
2042 (goto-char p)
2043 (if (looking-at
2044 (concat "{" YaTeX-ec-regexp
2045 YaTeX-command-token-regexp "+"
2046 "\\s +"))
2047 (delete-region
2048 (point)
2049 (progn (re-search-forward "\\s +" nil t) (point)))
2050 (delete-char 1)))
2051 t))))
2054 (defvar YaTeX-read-environment-history nil "Holds history of environments.")
2055 (put 'YaTeX-read-environment-history 'no-default t)
2056 (defun YaTeX-read-environment (prompt &optional predicate must-match initial)
2057 "Read a LaTeX environment name with completion."
2058 (YaTeX-sync-local-table 'tmp-env-table)
2059 (completing-read-with-history
2060 prompt
2061 (append tmp-env-table user-env-table env-table)
2062 predicate must-match initial
2063 'YaTeX-read-environment-history)
2066 (defvar YaTeX-read-section-history nil "Holds history of section-types.")
2067 (put 'YaTeX-read-section-history 'no-default t)
2068 (defun YaTeX-read-section (prompt &optional predicate initial)
2069 "Read a LaTeX section-type command with completion."
2070 (YaTeX-sync-local-table 'tmp-section-table)
2071 (let ((minibuffer-completion-table
2072 (append tmp-section-table user-section-table section-table)))
2073 (read-from-minibuffer-with-history
2074 prompt initial YaTeX-section-completion-map nil
2075 'YaTeX-read-section-history))
2078 (defun YaTeX-read-section-with-overview ()
2079 "Read sectioning command with overview.
2080 This function refers a local variable `source-window' in YaTeX-make-section"
2081 (interactive)
2082 (require 'yatexsec) ;some case needs this
2083 (if (> (minibuffer-depth) 1)
2084 (error "Too many minibuffer levels for overview."))
2085 (let ((sw (selected-window))(enable-recursive-minibuffers t) sect)
2086 (unwind-protect
2087 (progn
2088 (select-window source-window)
2089 (setq sect (YaTeX-read-section-in-minibuffer
2090 "Sectioning(Up=C-p, Down=C-n, Help=?): "
2091 YaTeX-sectioning-level (YaTeX-section-overview))))
2092 (select-window sw))
2093 (if (eq (selected-window) (minibuffer-window))
2094 (erase-buffer))
2095 (insert sect)
2096 (exit-minibuffer)
2100 (defvar YaTeX-read-fontsize-history nil "Holds history of font designator.")
2101 (put 'YaTeX-read-fontsize-history 'no-default t)
2102 (defun YaTeX-read-fontsize (prompt &optional predicate must-match initial)
2103 "Read a LaTeX font changing command with completion."
2104 (YaTeX-sync-local-table 'tmp-fontsize-table)
2105 (completing-read-with-history
2106 prompt (append tmp-fontsize-table user-fontsize-table fontsize-table)
2107 predicate must-match initial 'YaTeX-read-fontsize-history)
2110 (defun YaTeX-change-environment ()
2111 "Change the name of environment."
2112 (interactive)
2113 (if (not (YaTeX-on-begin-end-p)) nil
2114 (save-excursion
2115 (let (p env (m1 (match-beginning 1)) (m2 (match-beginning 2)))
2116 (setq env (if m1 (buffer-substring m1 (match-end 1))
2117 (buffer-substring m2 (match-end 2))))
2118 (goto-char (match-beginning 0))
2119 (set-mark-command nil)
2120 (YaTeX-goto-corresponding-environment)
2121 (setq newenv (YaTeX-read-environment
2122 (format "Change environment `%s' to: " env)))
2123 (cond
2124 ((string= newenv "") (message "Change environment cancelled."))
2125 ((string= newenv env) (message "No need to change."))
2126 (t
2127 (search-forward (concat "{" env) (point-end-of-line) t)
2128 (replace-match (concat "{" newenv))
2129 (exchange-point-and-mark)
2130 (search-forward (concat "{" env) (point-end-of-line) t)
2131 (replace-match (concat "{" newenv))))
2132 t)))
2135 (defun YaTeX-change-section ()
2136 "Change section-type command."
2137 (interactive)
2138 (let*((where (YaTeX-on-section-command-p YaTeX-command-token-regexp))
2139 (p (point)) (cmd (YaTeX-match-string 1)) beg end old new)
2140 (if (null where) nil
2141 (cond
2143 ((equal where 0);;if point is on section command
2144 (setq beg (match-beginning 1)
2145 end (match-end 1))
2146 (goto-char beg) ;beginning of the command
2147 (setq new (YaTeX-read-section (format "Change `%s' to: " cmd) nil)))
2149 ((= where -1);;if point is on a optional parameter
2150 (setq beg (match-beginning 2))
2151 (skip-chars-forward "^{")
2152 (setq end (point))
2153 (goto-char p)
2154 (setq new
2155 (if (fboundp (intern-soft (concat YaTeX-addin-prefix cmd)))
2156 (YaTeX-addin cmd)
2157 (concat "["
2158 (read-string (format "Change `%s' to: "
2159 (buffer-substring
2160 (1+ beg) (1- end))))
2161 "]"))))
2163 ((> where 0);;if point is in arguments' braces
2164 (or (looking-at "{")
2165 (progn (skip-chars-backward "^{") (forward-char -1)))
2166 (setq beg (1+ (point)))
2167 (forward-list 1)
2168 (forward-char -1)
2169 (setq end (point)
2170 old (buffer-substring beg end))
2171 (goto-char p)
2172 (if (> (length old) 40)
2173 (setq old (concat (substring old 0 12) "..." (substring old -12))))
2174 (setq new
2175 (if (intern-soft (concat "YaTeX::" cmd))
2176 (funcall (intern-soft (concat "YaTeX::" cmd)) where)
2177 (read-string (format "Change `%s' to: " old)))))
2178 );cond
2179 (delete-region beg end)
2180 (goto-char beg)
2181 (insert-before-markers new)
2182 ;;(goto-char (marker-position p))
2183 new))
2186 (defun YaTeX-change-fontsize ()
2187 "Change large-type command."
2188 (let ((lt (append tmp-fontsize-table user-fontsize-table fontsize-table))
2189 (p (point)) large old new beg end)
2190 ;;(and (looking-at "}") (up-list -1))
2191 ;;(and (looking-at "{") (forward-char 1))
2192 ;;Is above convenient?
2193 (save-excursion
2194 (or (looking-at YaTeX-ec-regexp)
2195 (progn
2196 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
2197 (forward-char -1)))
2198 (cond
2199 ((and
2200 (looking-at
2201 (concat YaTeX-ec-regexp "\\(" YaTeX-TeX-token-regexp "\\)"))
2202 (< p (match-end 0))
2203 (assoc (setq old (YaTeX-match-string 1)) lt))
2204 (goto-char p)
2205 (setq beg (match-beginning 1) end (match-end 1) ;save match position
2206 new (completing-read
2207 (format "Change font/size `%s' to : " old) lt))
2208 (delete-region beg end)
2209 (goto-char beg)
2210 (insert-before-markers new)
2211 new)
2212 (t nil)
2213 )))
2216 (defun YaTeX-change-math-image ()
2217 "Change with image completion."
2218 (let (maketitle memberp beg end)
2219 (if (and (YaTeX-on-maketitle-p)
2220 (progn
2221 (setq maketitle (substring (YaTeX-match-string 0) 1))
2222 (setq memberp (YaTeX-math-member-p maketitle))))
2223 (let ((last-command-char (string-to-char (car memberp))))
2224 (setq beg (match-beginning 0) end (match-end 0))
2225 (delete-region beg end)
2226 (YaTeX-math-insert-sequence t (cdr memberp))))))
2228 (defun YaTeX-kill-* (&optional arg)
2229 "Parse current line and call suitable function.
2230 Non-nil for ARG kills its contents too."
2231 (interactive "P")
2232 (cond
2233 ((YaTeX-kill-some-pairs 'YaTeX-on-begin-end-p
2234 'YaTeX-goto-corresponding-environment arg))
2235 ((YaTeX-kill-some-pairs 'YaTeX-on-BEGIN-END-p
2236 'YaTeX-goto-corresponding-BEGIN-END arg))
2237 ((YaTeX-on-section-command-p YaTeX-command-token-regexp);on any command
2238 (YaTeX-kill-section-command (match-beginning 0) arg))
2239 ((YaTeX-kill-paren arg))
2240 (t (message "I don't know what to kill.")))
2243 (defun YaTeX-change-* ()
2244 "Parse current line and call suitable function."
2245 (interactive)
2246 (cond
2247 ((YaTeX-change-environment))
2248 ((YaTeX-change-section))
2249 ((YaTeX-change-fontsize))
2250 ((YaTeX-change-math-image))
2251 (t (message "I don't know what to change.")))
2254 ;;;
2255 ;Check availability of add-in functions
2256 ;;;
2257 (cond
2258 ((featurep 'yatexadd) nil) ;Already provided.
2259 ((progn (load "yatexadd" t) (featurep 'yatexadd)) nil)
2260 (t (message "YaTeX add-in functions not supplied.")))
2262 (defun YaTeX-addin (name)
2263 "Check availability of addin function and call it if exists."
2264 (if (and (not (get 'YaTeX-generate 'disabled))
2265 (intern-soft (concat YaTeX-addin-prefix name))
2266 (fboundp (intern-soft (concat YaTeX-addin-prefix name))))
2267 (let ((s (funcall (intern (concat YaTeX-addin-prefix name)))))
2268 (if (stringp s) s ""))
2269 "") ;Add in function is not bound.
2272 (defun YaTeX-on-item-p (&optional point)
2273 "Return t if POINT (default is (point)) is on \\item."
2274 (let ((p (or point (point))))
2275 (save-excursion
2276 (goto-char p)
2277 (end-of-line)
2278 (setq p (point))
2279 (re-search-backward YaTeX-paragraph-delimiter nil t)
2280 (re-search-forward YaTeX-item-regexp p t)))
2283 (defun YaTeX-in-verb-p (&optional point)
2284 "Check if POINT is in verb or verb*. Default of POINT is (point)."
2285 (setq point (or point (point)))
2286 (save-excursion
2287 (goto-char point)
2288 (if (not (re-search-backward
2289 (concat YaTeX-ec-regexp
2290 "\\(" YaTeX-verb-regexp "\\)"
2291 "\\([^-A-Za-z_*]\\)")
2292 (point-beginning-of-line) t))
2293 nil
2294 (goto-char (match-end 2))
2295 (skip-chars-forward
2296 (concat "^" (buffer-substring (match-beginning 2) (match-end 2))))
2297 (and (< (match-beginning 2) point) (< (1- point) (point)))))
2300 (defun YaTeX-literal-p (&optional point)
2301 "Check if POINT is in verb or verb* or verbatime environment family.
2302 Default of POINT is (point)."
2303 (cond
2304 ((equal YaTeX-ec "\\") ;maybe LaTeX
2305 (save-excursion
2306 (and point (goto-char point))
2307 (or (YaTeX-in-verb-p (point))
2308 (and (not (looking-at "\\\\end{verb"))
2309 (YaTeX-quick-in-environment-p YaTeX-verbatim-environments))))))
2312 (defun YaTeX-in-environment-p (env)
2313 "Return if current LaTeX environment is ENV.
2314 ENV is given in the form of environment's name or its list."
2315 (let ((md (match-data)) (nest 0) p envrx)
2316 (cond
2317 ((atom env)
2318 (setq envrx
2319 (concat "\\("
2320 (regexp-quote
2321 (YaTeX-replace-format-args
2322 YaTeX-struct-begin env "" ""))
2323 "\\)\\|\\("
2324 (regexp-quote
2325 (YaTeX-replace-format-args
2326 YaTeX-struct-end env "" ""))
2327 "\\)"))
2328 (save-excursion
2329 (setq p (catch 'open
2330 (while (YaTeX-re-search-active-backward
2331 envrx YaTeX-comment-prefix nil t)
2332 (if (match-beginning 2)
2333 (setq nest (1+ nest))
2334 (setq nest (1- nest)))
2335 (if (< nest 0) (throw 'open t)))))))
2336 ((listp env)
2337 (setq p
2338 (or (YaTeX-in-environment-p (car env))
2339 (and (cdr env) (YaTeX-in-environment-p (cdr env)))))))
2340 (store-match-data md)
2341 p;(or p (YaTeX-in-verb-p (match-beginning 0)))
2345 (defun YaTeX-quick-in-environment-p (env)
2346 "Check quickly but unsure if current environment is ENV.
2347 ENV is given in the form of environment's name or its list.
2348 This function returns correct result only if ENV is NOT nested."
2349 (save-excursion
2350 (let ((md (match-data)) (p (point)) rc clfound)
2351 (cond
2352 ((listp env)
2353 (or (YaTeX-quick-in-environment-p (car env))
2354 (and (cdr env) (YaTeX-quick-in-environment-p (cdr env)))))
2355 (t
2356 (if (YaTeX-search-active-backward
2357 (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
2358 YaTeX-comment-prefix nil t)
2359 (setq rc (not (YaTeX-search-active-forward
2360 (YaTeX-replace-format-args
2361 YaTeX-struct-end env)
2362 YaTeX-comment-prefix p t nil))))
2363 (store-match-data md)
2364 rc))))
2367 ;; Filling \item
2368 (defun YaTeX-remove-trailing-comment (start end)
2369 "Remove trailing comment from START to end."
2370 (save-excursion
2371 (let ((trcom (concat YaTeX-comment-prefix "+$")))
2372 (goto-char start)
2373 (while (re-search-forward trcom end t)
2374 (if (/= (char-after (1- (match-beginning 0))) ?\\ )
2375 (replace-match "")))))
2378 (defun YaTeX-get-item-info (&optional recent thisenv)
2379 "Return the list of the beginning of \\item and column of its item.
2380 If it seems to be outside of itemizing environment, just return nil.
2381 Non-nil for optional argument RECENT refers recent \\item.
2382 Optional second argument THISENV omits calling YaTeX-inner-environment."
2383 (save-excursion
2384 (let* ((p (point)) env e0 c
2385 (bndry (and (setq env (or thisenv (YaTeX-inner-environment t)))
2386 (get 'YaTeX-inner-environment 'point)
2387 )))
2388 (end-of-line)
2389 (if (if recent
2390 (YaTeX-re-search-active-backward
2391 YaTeX-item-regexp YaTeX-comment-prefix bndry t)
2392 (goto-char bndry)
2393 (YaTeX-re-search-active-forward
2394 YaTeX-item-regexp YaTeX-comment-prefix p t))
2395 (progn
2396 (goto-char (match-end 0))
2397 ;(setq c (current-column))
2398 (if (string-match "desc" env)
2399 (setq c 6)
2400 (if (equal (following-char) ?\[) (forward-list 1))
2401 (setq c 0))
2402 (skip-chars-forward " \t" (point-end-of-line))
2403 (list (point-beginning-of-line) (+ c (current-column)))))))
2406 (defun YaTeX-fill-item ()
2407 "Fill item in itemize environment."
2408 (interactive)
2409 (save-excursion
2410 (let* ((p (point))
2411 (item-term (concat
2412 "\\(^[ \t]*$\\)\\|" YaTeX-item-regexp "\\|\\("
2413 YaTeX-ec-regexp "\\(begin\\|end\\)\\)"))
2414 ;;This value depends on LaTeX.
2415 fill-prefix start col
2416 (info (YaTeX-get-item-info t)))
2417 (if (null info) nil ;not on \item, do nothing
2418 (setq start (car info)
2419 col (car (cdr info)))
2420 (save-excursion
2421 (if (re-search-backward "^\\s *$" start t)
2422 ;;if separated from \item line, isolate this block
2423 (progn
2424 (setq start (1+ (match-end 0)))
2425 (goto-char start)
2426 (skip-chars-forward " \t")
2427 (delete-region (point) start) ;is this your favor???
2428 (indent-to col))))
2429 (beginning-of-line)
2430 (if (<= (save-excursion
2431 (re-search-forward
2432 (concat "\\\\end{\\|\\\\begin{\\|^[ \t]*$") nil t)
2433 (match-beginning 0))
2434 p)
2435 (progn (message "Not on itemize.") nil)
2436 (end-of-line)
2437 (newline)
2438 (indent-to col)
2439 (setq fill-prefix
2440 (buffer-substring (point-beginning-of-line)(point)))
2441 (beginning-of-line)
2442 (delete-region (point) (progn (forward-line 1) (point)))
2443 (re-search-forward item-term nil 1)
2444 (YaTeX-remove-trailing-comment start (point))
2445 (beginning-of-line)
2446 (push-mark (point) t)
2447 (goto-char start)
2448 (forward-line 1)
2449 (while (< (point) (mark))
2450 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
2451 (forward-line 1))
2452 (fill-region-as-paragraph start (mark))
2453 (if NTT-jTeX
2454 (while (progn(forward-line -1)(end-of-line) (> (point) start))
2455 (insert ?%)))
2456 (pop-mark)))))
2459 (defun YaTeX-fill-paragraph (arg)
2460 "YaTeX adjustment function for fill-paragraph.
2461 *Protect \\verb from unexpected broken up."
2462 (interactive "P")
2463 (cond
2464 ((not (eq major-mode 'yatex-mode)) (fill-paragraph arg))
2465 ((YaTeX-quick-in-environment-p YaTeX-fill-inhibit-environments) nil)
2466 (t
2467 (save-excursion
2468 (let ((verbrex (concat YaTeX-ec-regexp
2469 "\\(" YaTeX-verb-regexp "\\)" ;match#1
2470 "\\(.\\).*\\(\\2\\)")) ;match #2 and #3
2471 (p (point)) ii end poslist spacelist (fill-prefix fill-prefix))
2472 (cond
2473 ((save-excursion (beginning-of-line) ;if point is on the first
2474 (setq end (point)) ;non-whitespace char
2475 (skip-chars-forward " \t")
2476 (equal (point) p))
2477 (setq fill-prefix (buffer-substring p end)))
2478 ((and ;;(not YaTeX-emacs-19)
2479 (string-match YaTeX-itemizing-env-regexp
2480 (or (YaTeX-inner-environment t) "document"))
2481 (setq ii (YaTeX-get-item-info)))
2482 (save-excursion
2483 (beginning-of-line)
2484 (indent-to-column (car (cdr ii)))
2485 (setq fill-prefix
2486 (buffer-substring (point) (point-beginning-of-line)))
2487 (delete-region (point) (progn (beginning-of-line) (point))))))
2488 (mark-paragraph)
2489 (save-restriction
2490 (narrow-to-region (region-beginning) (region-end))
2491 (YaTeX-remove-trailing-comment (point-min) (point-max))
2492 (goto-char (point-min))
2493 (while (YaTeX-re-search-active-forward
2494 verbrex YaTeX-comment-prefix (point-max) t)
2495 (setq end (match-beginning 3))
2496 (goto-char (match-beginning 2))
2497 (while (re-search-forward "\\s " end t)
2498 (setq poslist (cons (make-marker) poslist)
2499 spacelist (cons (preceding-char) spacelist))
2500 (replace-match "_")
2501 (set-marker (car poslist) (match-beginning 0))))
2502 ;;(fill-paragraph arg)
2503 (fill-region-as-paragraph (point-min) (point-max) arg)
2504 (while spacelist
2505 (goto-char (marker-position (car poslist)))
2506 (delete-char 1)
2507 (insert (car spacelist))
2508 (setq spacelist (cdr spacelist) poslist (cdr poslist)))
2509 (goto-char (point-min))
2510 (forward-word 1)
2511 (beginning-of-line)
2512 (while (re-search-forward "\\\\\\(\\(page\\)?ref\\|cite\\){" nil t)
2513 (if (< (point-end-of-line)
2514 (save-excursion (forward-char -1) (forward-list 1) (point)))
2515 (progn (end-of-line) (insert YaTeX-comment-prefix))))
2516 (goto-char (point-min))
2517 (if (and NTT-jTeX (looking-at "[ \t]"))
2518 (progn
2519 (goto-char (point-min))
2520 (while (not (eobp))
2521 (end-of-line)
2522 (or (bolp)
2523 (save-excursion
2524 (backward-word 1)
2525 (looking-at "\\sw+")) ;is not japanese string
2526 (progn (setq p (point)) (insert YaTeX-comment-prefix)))
2527 (forward-line 1))
2528 (goto-char p)
2529 (delete-char 1) ;remove last inserted `%'
2530 )))))))
2533 (if (fboundp 'YaTeX-saved-indent-new-comment-line) nil
2534 (fset 'YaTeX-saved-indent-new-comment-line
2535 (symbol-function 'indent-new-comment-line))
2536 (fset 'indent-new-comment-line 'YaTeX-indent-new-comment-line))
2538 (defun YaTeX-indent-new-comment-line (&optional soft)
2539 "Tuned `indent-new-comment-line' function for yatex.
2540 See the documentation of `YaTeX-saved-indent-new-comment-line'."
2541 (cond
2542 ((or (not (eq major-mode 'yatex-mode))
2543 (string-match
2544 "document"
2545 (or (and (boundp 'inenv) inenv)
2546 (or (YaTeX-inner-environment t) "document"))))
2547 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft))))
2548 (t (let (fill-prefix)
2549 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft)))))))
2551 (defun YaTeX-fill-* ()
2552 "Fill paragraph according to its condition."
2553 (interactive)
2554 (cond
2555 ((YaTeX-fill-item))
2559 ;; Accent completion
2560 (defun YaTeX-read-accent-char (x)
2561 "Read char in accent braces."
2562 (let ((c (read-char)))
2563 (concat
2564 (if (and (or (= c ?i) (= c ?j))
2565 (not (string-match (regexp-quote x) "cdb")))
2566 "\\" "")
2567 (char-to-string c)))
2570 (defun YaTeX-make-accent ()
2571 "Make accent usage."
2572 (interactive)
2573 (message "1:` 2:' 3:^ 4:\" 5:~ 6:= 7:. u v H t c d b")
2574 (let ((c (read-char))(case-fold-search nil))
2575 (setq c (cond ((and (> c ?0) (< c ?8))
2576 (substring "`'^\"~=." (1- (- c ?0)) (- c ?0)))
2577 ((= c ?h) "H")
2578 (t (char-to-string c))))
2579 (if (not (string-match c "`'^\"~=.uvHtcdb")) nil
2580 (insert "\\" c "{}")
2581 (backward-char 1)
2582 (insert (YaTeX-read-accent-char c))
2583 (if (string= c "t") (insert (YaTeX-read-accent-char c)))
2584 (forward-char 1)))
2587 ;; Indentation
2588 (defun YaTeX-current-indentation ()
2589 "Return the indentation of current environment."
2590 (save-excursion
2591 ;;(beginning-of-line)
2592 (if (YaTeX-beginning-of-environment t)
2593 (goto-char (get 'YaTeX-inner-environment 'point))
2594 (forward-line -1)
2595 (beginning-of-line)
2596 (skip-chars-forward " \t"))
2597 (current-column))
2600 (defun YaTeX-previous-line-indentation ()
2601 (save-excursion
2602 (forward-line -1)
2603 (skip-chars-forward " \t")
2604 (current-column)))
2606 (defun YaTeX-reindent (col)
2607 "Remove current indentation and reindento to COL column."
2608 (save-excursion
2609 (beginning-of-line)
2610 (skip-chars-forward " \t")
2611 (if (/= col (current-column))
2612 (progn
2613 (delete-region (point) (progn (beginning-of-line) (point)))
2614 (indent-to col))))
2615 (skip-chars-forward " \t" (point-end-of-line)))
2617 (defun YaTeX-indent-line ()
2618 "Indent corrent line referrin current environment."
2619 (interactive)
2620 (let ((indent-relative
2621 (function
2622 (lambda (&optional additional)
2623 (YaTeX-reindent
2624 (+ (YaTeX-current-indentation)
2625 (or additional 0)
2626 YaTeX-environment-indent)))))
2627 depth iteminfo (p (point)) pp (peol (point-end-of-line))
2628 ;;inenv below is sometimes defined in YaTeX-indent-new-comment-line
2629 (inenv (or (and (boundp 'inenv) inenv) (YaTeX-inner-environment t))))
2630 ;;(if NTT-jTeX ;;Do you need this section?
2631 ;; (save-excursion
2632 ;; (end-of-line)
2633 ;; (let ((p (point)))
2634 ;; (forward-line -1)
2635 ;; (end-of-line)
2636 ;; (or (= p (point))
2637 ;; (progn (backward-char (length YaTeX-comment-prefix))
2638 ;; (not (looking-at (regexp-quote YaTeX-comment-prefix))))
2639 ;; (progn
2640 ;; (skip-chars-backward YaTeX-comment-prefix)
2641 ;; (kill-line))))))
2642 (or inenv (setq inenv "document")) ;is the default environment
2643 (cond
2644 ((and (YaTeX-on-begin-end-p) (match-beginning 2)) ;if \end
2645 (save-excursion
2646 (beginning-of-line)
2647 (YaTeX-reindent (YaTeX-current-indentation))))
2648 ((string-match YaTeX-equation-env-regexp inenv)
2649 (YaTeX-indent-line-equation)) ;autoload-ed from yatex.env
2650 (;(YaTeX-in-environment-p '("itemize" "enumerate" "description" "list"))
2651 (string-match YaTeX-itemizing-env-regexp inenv)
2652 ;;(YaTeX-on-item-p) ??
2653 ;;(setq iteminfo (YaTeX-get-item-info t))
2654 (if (save-excursion
2655 (beginning-of-line)
2656 (re-search-forward YaTeX-item-regexp peol t))
2657 (save-excursion
2658 (goto-char (1+ (match-beginning 0)))
2659 (setq depth
2660 (* YaTeX-environment-indent
2661 (cond
2662 ((looking-at "subsubsub") 3)
2663 ((looking-at "subsub") 2)
2664 ((looking-at "sub") 1)
2665 (t 0))))
2666 (funcall indent-relative depth))
2667 (YaTeX-reindent (or (car (cdr (YaTeX-get-item-info nil inenv)))
2668 (+ (save-excursion
2669 (beginning-of-line)
2670 (YaTeX-current-indentation))
2671 YaTeX-environment-indent))))
2673 ((YaTeX-literal-p) ;verbatims
2674 (tab-to-tab-stop))
2675 ((and inenv (not (equal "document" inenv)))
2676 (funcall indent-relative))
2677 ((YaTeX-on-section-command-p YaTeX-sectioning-regexp)
2678 (require 'yatexsec) ;to know YaTeX-sectioning-level
2679 (YaTeX-reindent
2680 (* (max
2681 (1- ;I want chapter to have indentation 0
2682 (or (cdr (assoc (YaTeX-match-string 1) YaTeX-sectioning-level))
2683 0))
2684 0)
2685 YaTeX-environment-indent)))
2686 ;;Default movement
2687 ((and (bolp) fill-prefix) (insert fill-prefix))
2688 (t (save-excursion
2689 (beginning-of-line)
2690 (skip-chars-forward " \t")
2691 (indent-relative-maybe))
2692 (skip-chars-forward " \t")))
2693 ;;if current line is \begin, re-indent \end too
2694 (if (and (YaTeX-on-begin-end-p) (match-beginning 1))
2695 (save-excursion
2696 ;;(beginning-of-line)
2697 ;;(search-forward "\\begin")
2698 (goto-char (match-beginning 0))
2699 (setq depth (current-column))
2700 (YaTeX-goto-corresponding-environment)
2701 (YaTeX-reindent depth)))
2702 (if (or
2703 (and NTT-jTeX
2704 (save-excursion (beginning-of-line) (looking-at "[ \t]")))
2705 (save-excursion
2706 (beginning-of-line)
2707 (backward-char 1)
2708 (and
2709 (re-search-backward
2710 "\\\\\\(\\(page\\)?ref\\|cite\\){" (point-beginning-of-line) t)
2711 (goto-char (1- (match-end 0)))
2712 (> (save-excursion
2713 (condition-case ()
2714 (progn (forward-list 1) (point))
2715 (error (point-max))))
2716 (point-end-of-line)))))
2717 (save-excursion
2718 (end-of-line)
2719 (let ((p (point)))
2720 (forward-line -1)
2721 (end-of-line)
2722 (or (= p (point))
2723 (looking-at (regexp-quote YaTeX-comment-prefix))
2724 (bobp) (bolp)
2725 (save-excursion
2726 (backward-word 1)
2727 (looking-at "\\sw+")) ;is not japanese string
2728 (insert YaTeX-comment-prefix))))))
2731 (defun YaTeX-local-table-symbol (symbol)
2732 "Return the lisp symbol which keeps local completion table of SYMBOL."
2733 (intern (concat "YaTeX$"
2734 default-directory
2735 (symbol-name symbol)))
2738 (defun YaTeX-sync-local-table (symbol)
2739 "Synchronize local variable SYMBOL.
2740 Copy its corresponding directory dependent completion table to SYMBOL."
2741 (if (boundp (YaTeX-local-table-symbol symbol))
2742 (set symbol (symbol-value (YaTeX-local-table-symbol symbol))))
2745 (defun YaTeX-read-user-completion-table (&optional forcetoread)
2746 "Append user completion table of LaTeX macros"
2747 (let*((user-table (expand-file-name YaTeX-user-completion-table))
2748 (local-table (expand-file-name (file-name-nondirectory user-table)))
2749 var localvar localbuf (curbuf (current-buffer)) sexp)
2750 (if YaTeX-user-table-is-read nil
2751 (message "Loading user completion table")
2752 (if (file-exists-p user-table) (load-file user-table)
2753 (message "Personal completion table not found.")))
2754 (setq YaTeX-user-table-is-read t)
2755 (cond
2756 ((file-exists-p local-table)
2757 (set-buffer (setq localbuf (find-file-noselect local-table)))
2758 (widen)
2759 (goto-char (point-min))
2760 (while (re-search-forward "(setq \\([^ ]+\\)" nil t)
2761 (setq var (intern (buffer-substring
2762 (match-beginning 1) (match-end 1)))
2763 localvar (YaTeX-local-table-symbol var))
2764 (goto-char (match-beginning 0))
2765 (setq sexp (buffer-substring (point)
2766 (progn (forward-sexp) (point))))
2767 (set-buffer curbuf)
2768 (or (assq var (buffer-local-variables)) (make-local-variable var))
2769 (eval (read sexp))
2770 (or (and (boundp localvar)
2771 (symbol-value localvar)
2772 (not forcetoread))
2773 (set localvar (symbol-value var)))
2774 (set-buffer localbuf))
2775 (kill-buffer localbuf)))
2776 (set-buffer curbuf))
2779 (defun YaTeX-reload-dictionary ()
2780 "Reload local dictionary.
2781 Use this function after editing ./.yatexrc."
2782 (interactive)
2783 (let ((YaTeX-user-table-is-read nil))
2784 (YaTeX-read-user-completion-table t))
2787 (defun YaTeX-lookup-table (word type)
2788 "Lookup WORD in completion table whose type is TYPE.
2789 This function refers the symbol tmp-TYPE-table, user-TYPE-table, TYPE-table.
2790 Typically, TYPE is one of 'env, 'section, 'fontsize, 'singlecmd."
2791 (if (symbolp type) (setq type (symbol-name type)))
2792 (or (assoc word (symbol-value (intern (concat "tmp-" type "-table"))))
2793 (assoc word (symbol-value (intern (concat "user-" type "-table"))))
2794 (assoc word (symbol-value (intern (concat type "-table"))))))
2796 (defun YaTeX-update-table (vallist default-table user-table local-table)
2797 "Update completion table if the car of VALLIST is not in current tables.
2798 Second argument DEFAULT-TABLE is the quoted symbol of default completion
2799 table, third argument USER-TABLE is user table which will be saved in
2800 YaTeX-user-completion-table, fourth argument LOCAL-TABLE should have the
2801 completion which is valid during current Emacs's session. If you
2802 want to make LOCAL-TABLE valid longer span (but restrict in this directory)
2803 create the file in current directory which has the same name with
2804 YaTeX-user-completion-table."
2805 (let ((car-v (car vallist)) key answer
2806 (file (file-name-nondirectory YaTeX-user-completion-table)))
2807 (cond
2808 ((assoc car-v (symbol-value default-table))
2809 nil) ;Nothing to do
2810 ((setq key (assoc car-v (symbol-value user-table)))
2811 (if (equal (cdr vallist) (cdr key)) nil
2812 ;; if association hits, but contents differ.
2813 (message
2814 "%s's attributes turned into %s" (car vallist) (cdr vallist))
2815 (set user-table (delq key (symbol-value user-table)))
2816 (set user-table (cons vallist (symbol-value user-table)))
2817 (YaTeX-update-dictionary
2818 YaTeX-user-completion-table user-table "user")))
2819 ((setq key (assoc car-v (symbol-value local-table)))
2820 (if (equal (cdr vallist) (cdr key)) nil
2821 (message
2822 "%s's attributes turned into %s" (car vallist) (cdr vallist))
2823 (set local-table (delq key (symbol-value local-table)))
2824 (set local-table (cons vallist (symbol-value local-table)))
2825 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table))
2826 (YaTeX-update-dictionary file local-table)))
2827 ;; All of above cases, there are some completion in tables.
2828 ;; Then update tables.
2829 (t
2830 (if (not YaTeX-nervous)
2831 (setq answer "u")
2832 (message
2833 "`%s' is not in table. Register into: U)serDic L)ocalDic N)one D)iscard"
2834 (car vallist))
2835 (setq answer (char-to-string (read-char))))
2836 (cond
2837 ((string-match answer "uy")
2838 (set user-table (cons vallist (symbol-value user-table)))
2839 (YaTeX-update-dictionary YaTeX-user-completion-table user-table "user")
2841 ((string-match answer "tl")
2842 (set local-table (cons vallist (symbol-value local-table)))
2843 (set (YaTeX-local-table-symbol local-table) (symbol-value local-table))
2844 (YaTeX-update-dictionary file local-table))
2845 ((string-match answer "d") nil) ;discard it
2846 (t (set default-table
2847 (cons vallist (symbol-value default-table))))))))
2850 (defun YaTeX-cplread-with-learning
2851 (prom default-table user-table local-table
2852 &optional pred reqmatch init hsym)
2853 "Completing read with learning.
2854 Do a completing read with prompt PROM. Completion table is what
2855 DEFAULT-TABLE, USER-TABLE, LOCAL table are appended in reverse order.
2856 Note that these tables are passed by the symbol.
2857 Optional arguments PRED, REQMATH and INIT are passed to completing-read
2858 as its arguments PREDICATE, REQUIRE-MATCH and INITIAL-INPUT respectively.
2859 If optional 8th argument HSYM, history symbol, is passed, use it as
2860 history list variable."
2861 (YaTeX-sync-local-table local-table)
2862 (let*((table (append (symbol-value local-table)
2863 (symbol-value user-table)
2864 (symbol-value default-table)))
2865 (word (completing-read-with-history
2866 prom table pred reqmatch init hsym)))
2867 (if (and (string< "" word) (not (assoc word table)))
2868 (YaTeX-update-table (list word) default-table user-table local-table))
2869 word)
2872 (defun YaTeX-update-dictionary (file symbol &optional type)
2873 (let ((local-table-buf (find-file-noselect file))
2874 (name (symbol-name symbol))
2875 (value (symbol-value symbol)))
2876 (save-excursion
2877 (message "Updating %s dictionary..." (or type "local"))
2878 (set-buffer local-table-buf)
2879 (goto-char (point-max))
2880 (search-backward (concat "(setq " name) nil t)
2881 (delete-region (point) (progn (forward-sexp) (point)))
2882 (delete-blank-lines)
2883 (insert "(setq " name " '(\n")
2884 (mapcar '(lambda (s)
2885 (insert (format "%s\n" (prin1-to-string s))))
2886 value)
2887 (insert "))\n\n")
2888 (delete-blank-lines)
2889 (basic-save-buffer)
2890 (kill-buffer local-table-buf)
2891 (message "Updating %s dictionary...Done" (or type "local"))))
2894 ;; --------------- General sub functions ---------------
2895 (defun point-beginning-of-line ()
2896 (save-excursion (beginning-of-line)(point))
2899 (defun point-end-of-line ()
2900 (save-excursion (end-of-line)(point))
2904 (provide 'yatex)
2905 (defvar yatex-mode-load-hook nil
2906 "*List of functions to be called when yatex.el is loaded.")
2907 (if (and YaTeX-emacs-19 window-system (not (featurep 'yatex19)))
2908 (load "yatex19"))
2909 (load "yatexhks" t)
2911 ;;-------------------- Final hook jobs --------------------
2912 (substitute-all-key-definition
2913 'fill-paragraph 'YaTeX-fill-paragraph YaTeX-mode-map)
2914 (run-hooks 'yatex-mode-load-hook)
2916 ;; `History' was moved to ChangeLog
2917 ;----------------------------- End of yatex.el -----------------------------