yatex

view yatex.el @ 72:0aaebd07dad0

Support font-lock on XEmacs-21, Emacs-20, Emacs-21. Support Emacs-21.
author yuuji
date Mon, 25 Dec 2000 10:19:28 +0000
parents 44e3a5e1e883
children f41b01fef5d6
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; Yet Another tex-mode for emacs - //野鳥//
3 ;;; yatex.el rev. 1.69
4 ;;; (c )1991-2000 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Mon Dec 25 18:57:10 2000 on firestorm
6 ;;; $Id$
7 ;;; The latest version of this software is always available at;
8 ;;; http://www.yatex.org/
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING. If not, write to the
22 ;; Software Foundation Inc., 59 Temple Place - Suite 330, Boston, MA
23 ;; 02111-1307, USA.
25 (require 'comment)
26 (require 'yatexlib)
27 (defconst YaTeX-revision-number "1.69"
28 "Revision number of running yatex.el")
30 ;---------- Local variables ----------
31 (defvar YaTeX-prefix "\C-c"
32 "*Prefix key to call YaTeX functions.
33 You can select favorite prefix key by setq in your ~/.emacs.")
35 (defvar YaTeX-environment-indent 1
36 "*Indentation depth at column width in LaTeX environments.")
38 (defvar YaTeX-fill-prefix nil
39 "*fill-prefix used for auto-fill-mode.
40 The default value is nil.")
42 (defvar YaTeX-fill-column 72
43 "*fill-column used for auto-fill-mode.")
45 (defvar YaTeX-comment-prefix "%"
46 "TeX comment prefix.")
48 (defvar YaTeX-current-position-register ?3
49 "*Position register to keep where the last completion was done.
50 All of YaTeX completing input store the current position into
51 the register YaTeX-current-position-register. So every time you
52 make a trip to any other part of text other than you are writing, you can
53 return to the editing paragraph by calling register-to-point with argument
54 YaTeX-current-position-register.")
56 ;;(defvar YaTeX-tmp-dic-unit 'main-file
57 ;; "*Default switching unit of temporary dictionary.
58 ;;There are two switching unit:
59 ;;'main-file : switch tmp-dic according to main-file directory.
60 ;;'directory : switch tmp-dic dir by dir."
61 ;;)
62 (defvar YaTeX-use-LaTeX2e t "*Use LaTeX2e or not. Nil meas latex 2.09")
64 (defvar tex-command
65 (cond
66 (YaTeX-use-LaTeX2e "platex")
67 (YaTeX-japan "jlatex")
68 (t "latex"))
69 "*Default command for typesetting LaTeX text.")
71 (defvar bibtex-command (if YaTeX-japan "jbibtex" "bibtex")
72 "*Default command of BibTeX.")
74 (defvar dvi2-command ;previewer command for your site
75 (if YaTeX-dos "dviout -wait=0"
76 "xdvi -geo +0+0 -s 4")
77 "*Default previewer command including its option.
78 This default value is for X window system.")
80 (defvar makeindex-command (if YaTeX-dos "makeind" "makeindex")
81 "*Default makeindex command.")
83 (defvar dviprint-command-format
84 (if YaTeX-dos "dviprt %s %f%t"
85 "dvi2ps %f %t %s | lpr")
86 "*Command line string to print out current file.
87 Format string %s will be replaced by the filename. Do not forget to
88 specify the `from usage' and `to usage' with their option by format string
89 %f and %t.
90 See also documentation of dviprint-from-format and dviprint-to-format.")
92 (defvar dviprint-from-format
93 (if YaTeX-dos "%b-" "-f %b")
94 "*`From' page format of dvi filter. %b will turn to beginning page number.")
96 (defvar dviprint-to-format
97 (if YaTeX-dos "%e" "-t %e")
98 "*`To' page format of dvi filter. %e will turn to end page number.")
100 (defvar YaTeX-default-document-style
101 (concat (if YaTeX-japan "j") "article")
102 "*Default LaTeX Documentstyle for YaTeX-typeset-region.")
104 (defvar YaTeX-need-nonstop nil
105 "*T for adding `\\nonstopmode{}' to text before invoking latex command.")
107 (defvar latex-warning-regexp "line.* [0-9]*"
108 "*Regular expression of line number of warning message by latex command.")
110 (defvar latex-error-regexp "l\\.[1-9][0-9]*"
111 "*Regular expression of line number of latex error.
112 Perhaps your latex command stops at this error message with line number of
113 LaTeX source text.")
115 (defvar latex-dos-emergency-message
116 "Emergency stop" ;<- for Micro tex, ASCII-pTeX 1.6
117 "Message pattern of emergency stop of typesetting.
118 Because Demacs (GNU Emacs on DOS) cannot have concurrent process, the
119 latex command which is stopping on a LaTeX error, is terminated by Demacs.
120 Many latex command on DOS display some messages when it is terminated by
121 other process, user or OS. Define to this variable a message string of your
122 latex command on DOS shown at abnormal termination.
123 Remember Demacs's call-process function is not oriented for interactive
124 process.")
126 (defvar latex-message-kanji-code 2
127 "*Kanji coding system latex command types out.
128 1 = Shift JIS, 2 = JIS, 3 = EUC.")
130 (defvar NTT-jTeX nil
131 "*T for using NTT-jTeX for latex command.
132 More precisely, setting t to this variables inhibits inter-word break on
133 typeset document by line-break of source text. That is, YaTeX automatically
134 put % after each line at filling.
135 改行+インデントによって、タイプセット後の字間が空いてしまうのを抑制する場合に
136 tにする(古いNTT-jTeXで顕著に現れる)。具体的には、fillするときに各行の終わりに
137 %を付加する。")
140 (defvar YaTeX-item-regexp
141 (concat (regexp-quote "\\") "\\(sub\\|bib\\)*item")
142 "*Regular expression of item command.")
144 (defvar YaTeX-sectioning-regexp
145 "\\(part\\|chapter\\*?\\|\\(sub\\)*\\(section\\|paragraph\\)\\)\\(\\*\\|\\b\\)"
146 "*LaTeX sectioning commands regexp.")
148 (defvar YaTeX-paragraph-start
149 (concat "^[ \t]*%\\|^[ \t]*$\\|\\'\\|^\C-l\\|\\\\\\\\$\\|^[ \t]*\\\\\\("
150 YaTeX-sectioning-regexp ;sectioning commands
151 "\\|[A-z]*item\\|begin{\\|end{" ;special declaration
152 "\\|\\[\\|\\]"
153 "\\|newpage\\b\\|vspace\\b"
154 "\\)")
155 "*Paragraph starting regexp of common LaTeX source. Use this value
156 for YaTeX-uncomment-paragraph.")
158 (defvar YaTeX-paragraph-separate
159 (concat "^[ \t]*%\\|^[ \t]*$\\|^\C-l\\|\\\\\\\\$\\|^[ \t]*\\\\\\("
160 YaTeX-sectioning-regexp ;sectioning commands
161 "\\|begin{\\|end{" ;special declaration
162 "\\|\\[\\|\\]"
163 "\\|newpage\\b\\|vspace\\b"
164 "\\)")
165 "*Paragraph delimiter regexp of common LaTeX source. Use this value
166 for YaTeX-uncomment-paragraph.")
168 (defvar YaTeX-verbatim-environments
169 '("verbatim" "verbatim*")
170 "*Assume these environments of this variable disable LaTeX commands.")
171 (defvar YaTeX-verb-regexp "verb\\*?\\|path"
172 "*Regexp of verb family. Do not contain preceding \\\\ nor \\(\\).")
173 (defvar YaTeX-fill-inhibit-environments
174 (append '("tabular" "tabular*" "array" "picture" "eqnarray" "eqnarray*"
175 "equation" "equation*" "math" "displaymath")
176 YaTeX-verbatim-environments)
177 "*In these environments, YaTeX inhibits fill-paragraph from formatting.
178 Define those environments as a form of list.")
180 (defvar YaTeX-itemizing-env-regexp
181 "itemize\\|enumerate\\|description\\|list\\|thebibliography"
182 "*Regexp of itemizing environments")
183 (defvar YaTeX-equation-env-regexp
184 "array\\*?\\|equation\\*?"
185 "*Regexp of environments for equations")
186 (defvar YaTeX-array-env-regexp
187 (concat
188 "array\\*?\\|eqnarray\\*?\\|tabbing\\|tabular\\*?\\|" ;LaTeX
189 "matrix\\|pmatrix\\|bmatrix\\|vmatrix\\|Vmatrix\\|" ;AMS-LaTeX
190 "align\\*?\\|split\\*?\\|aligned\\*?\\|alignat\\*?\\|" ;AMS-LaTeX
191 "[bpvV]?matrix\\|smallmatrix\\|cases\\|" ;AMS-LaTeX
192 "xalignat\\*?\\|xxalignat\\*?") ;AMS-LaTeX
193 "*Regexp of environments where `&' becomes field delimiter.")
194 (defvar YaTeX-uncomment-once t
195 "*T for removing all continuous commenting character(%).
196 Nil for removing only one commenting character at the beginning-of-line.")
198 (defvar YaTeX-close-paren-always t
199 "*Close parenthesis always when YaTeX-modify-mode is nil.")
201 (defvar YaTeX-greek-by-maketitle-completion nil
202 "*T for greek letters completion by maketitle-type completion.")
204 (defvar YaTeX-auto-math-mode t
205 "*T for changing YaTeX-math mode automatically.")
206 (defvar YaTeX-use-AMS-LaTeX nil
207 "*T for using AMS-LaTeX")
209 (defvar yatex-mode-hook nil
210 "*List of functions to be called at the end of yatex-mode initializations.")
212 (defvar YaTeX-search-file-from-top-directory t
213 "*Non-nil means to search input-files from the directory where main file exists.")
215 (defvar YaTeX-use-font-lock (and (featurep 'font-lock)
216 (fboundp 'x-color-values)
217 (fboundp 'font-lock-fontify-region))
218 "*Use font-lock to fontify buffer or not.")
220 (defvar YaTeX-use-hilit19 (and (featurep 'hilit19) (fboundp 'x-color-values)
221 (fboundp 'hilit-translate))
222 "*Use hilit19 to highlight buffer or not.")
224 ;;-- Math mode values --
226 (defvar YaTeX-math-key-list-default
227 '((";" . YaTeX-math-sign-alist)
228 (":" . YaTeX-greek-key-alist))
229 "Default key sequence to invoke math-mode's image completion.")
231 (defvar YaTeX-math-key-list-private nil
232 "*User defined alist, math-mode-prefix vs completion alist.")
234 (defvar YaTeX-math-key-list
235 (append YaTeX-math-key-list-private YaTeX-math-key-list-default)
236 "Key sequence to invoke math-mode's image completion.")
238 (defvar YaTeX-skip-default-reader nil
239 "Non-nil skips default argument reader of section-type completion.")
241 (defvar YaTeX-simple-messages nil
242 "Non-nil makes minibuffer messages simpler.")
244 (defvar YaTeX-template-file "~/work/template.tex"
245 "*Template TeX source file. This will be inserted to empty file.")
247 (defvar YaTeX-addin-prefix "YaTeX:")
248 ;------------ Completion table ------------
249 ; Set tex-section-like command possible completion
250 (defvar section-table
251 (append
252 '(("part") ("chapter") ("chapter*") ("section") ("section*")
253 ("subsection") ("subsection*")
254 ("subsubsection") ("paragraph") ("subparagraph")
255 ("author") ("thanks") ("documentstyle") ("pagestyle") ("thispagestyle")
256 ("title") ("underline") ("label") ("makebox")
257 ("footnote") ("footnotetext") ("index")
258 ("hspace*") ("vspace*") ("bibliography") ("bibitem") ("cite")
259 ("input") ("include") ("includeonly") ("mbox") ("hbox") ("caption")
260 ("newlength") ("setlength" 2) ("addtolength" 2) ("settowidth" 2)
261 ("setcounter" 2) ("addtocounter" 2) ("stepcounter" 2)
262 ("newcommand" 2) ("renewcommand" 2)
263 ("setcounter" 2) ("newenvironment" 3) ("newtheorem" 2)
264 ("cline") ("framebox") ("savebox" 2) ("sbox" 2) ("newsavebox") ("usebox")
265 ("date") ("put") ("ref") ("pageref")
266 ("multicolumn" 3) ("shortstack")
267 ;; for mathmode accent
268 ("tilde") ("hat") ("check") ("bar") ("dot") ("ddot") ("vec")
269 ("widetilde") ("widehat") ("overline") ("overrightarrow")
270 ;; section types in mathmode
271 ("frac" 2) ("sqrt") ("mathrm") ("mathbf") ("mathit")
272 )
273 (if YaTeX-use-LaTeX2e
274 '(("documentclass") ("usepackage")
275 ("textbf") ("textgt") ("textit") ("textmc") ("textmd") ("textnormal")
276 ("textrm") ("textsc") ("textsf") ("textsl") ("texttt") ("textup")
277 ("mathbf") ("mathcal") ("mathit") ("mathnormal") ("mathrm")
278 ("mathsf") ("mathtt")
279 ("scalebox" 1) ;is faking of argument position
280 ("rotatebox" 2) ("resizebox" 2) ("reflectbox")
281 ("colorbox" 2) ("fcolorbox" 3) ("textcolor" 2) ("color")
282 ("includegraphics") ("includegraphics*")
283 )))
284 "Default completion table for section-type completion.")
286 (defvar user-section-table nil)
287 (defvar tmp-section-table nil)
289 ; Set tex-environment possible completion
290 (defvar env-table
291 '(("quote") ("quotation") ("center") ("verse") ("document")
292 ("verbatim") ("itemize") ("enumerate") ("description")
293 ("list") ("tabular") ("tabular*") ("table") ("tabbing") ("titlepage")
294 ("sloppypar") ("picture") ("displaymath")
295 ("eqnarray") ("figure") ("equation") ("abstract") ("array")
296 ("thebibliography") ("theindex") ("flushleft") ("flushright")
297 ("minipage")
298 )
299 "Default completion table for begin-type completion.")
301 (defvar user-env-table nil)
302 (defvar tmp-env-table nil)
304 ; Set {\Large }-like completion
305 (defvar fontsize-table
306 '(("rm") ("em") ("bf") ("boldmath") ("it") ("sl") ("sf") ("sc") ("tt")
307 ("dg") ("dm")
308 ("tiny") ("scriptsize") ("footnotesize") ("small")("normalsize")
309 ("large") ("Large") ("LARGE") ("huge") ("Huge")
310 ("rmfamily") ("sffamily") ("ttfamily")
311 ("mdseries") ("bfseries") ("upshape")
312 ("itshape") ("slshape") ("scshape")
313 )
314 "Default completion table for large-type completion.")
316 (defvar LaTeX2e-fontstyle-alist
317 '(("rm" . "rmfamily")
318 ("sf" . "sffamily")
319 ("tt" . "ttfamily")
320 ("md" . "mdseries")
321 ("bf" . "bfseries")
322 ("up" . "upshape")
323 ("it" . "itshape")
324 ("sl" . "slshape")
325 ("sc" . "scshape")))
327 (defvar user-fontsize-table nil)
328 (defvar tmp-fontsize-table nil)
330 (defvar singlecmd-table
331 (append
332 '(("maketitle") ("makeindex") ("sloppy") ("protect")
333 ("LaTeX") ("TeX") ("item") ("item[]") ("appendix") ("hline") ("kill")
334 ;;("rightarrow") ("Rightarrow") ("leftarrow") ("Leftarrow")
335 ("pagebreak") ("nopagebreak") ("tableofcontents")
336 ("newpage") ("clearpage") ("cleardoublepage")
337 ("footnotemark") ("verb") ("verb*")
338 ("linebreak") ("pagebreak") ("noindent") ("indent")
339 ("left") ("right") ("dots") ("smallskip") ("medskip") ("bigskip")
340 )
341 (if YaTeX-greek-by-maketitle-completion
342 '(("alpha") ("beta") ("gamma") ("delta") ("epsilon")
343 ("varepsilon") ("zeta") ("eta") ("theta")("vartheta")
344 ("iota") ("kappa") ("lambda") ("mu") ("nu") ("xi") ("pi")
345 ("varpi") ("rho") ("varrho") ("sigma") ("varsigma") ("tau")
346 ("upsilon") ("phi") ("varphi") ("chi") ("psi") ("omega")
347 ("Gamma") ("Delta") ("Theta") ("Lambda")("Xi") ("Pi")
348 ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega"))))
349 "Default completion table for maketitle-type completion.")
351 (defvar user-singlecmd-table nil)
352 (defvar tmp-singlecmd-table nil)
354 ;---------- Key mode map ----------
355 ;;;
356 ;; Create new key map: YaTeX-mode-map
357 ;; Do not change this section.
358 ;;;
359 (defvar YaTeX-mode-map nil
360 "Keymap used in YaTeX mode")
362 (defvar YaTeX-prefix-map nil
363 "Keymap used when YaTeX-prefix key pushed")
365 (defvar YaTeX-user-extensional-map (make-sparse-keymap)
366 "*Keymap used for the user's customization")
367 (defvar YaTeX-current-completion-type nil
368 "Has current completion type. This may be used in YaTeX addin functions.")
370 (defvar YaTeX-modify-mode nil
371 "*Current editing mode.
372 When non-nil, each opening parentheses only opens,
373 nil enters both open/close parentheses when opening parentheses key pressed.")
375 (defvar YaTeX-math-mode nil
376 "Holds whether current mode is math-mode.")
377 ;;;
378 ;; Define key table
379 ;;;
380 (if YaTeX-mode-map
381 nil
382 (setq YaTeX-mode-map (make-sparse-keymap))
383 (setq YaTeX-prefix-map (make-sparse-keymap))
384 (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
385 (define-key YaTeX-mode-map "{" 'YaTeX-insert-braces)
386 (define-key YaTeX-mode-map "(" 'YaTeX-insert-parens)
387 (define-key YaTeX-mode-map "$" 'YaTeX-insert-dollar)
388 (define-key YaTeX-mode-map "|" 'YaTeX-insert-bar)
389 (define-key YaTeX-mode-map "&" 'YaTeX-insert-amper)
390 (define-key YaTeX-mode-map "[" 'YaTeX-insert-brackets)
391 (define-key YaTeX-mode-map YaTeX-prefix YaTeX-prefix-map)
392 (define-key YaTeX-mode-map "\M-\C-@" 'YaTeX-mark-environment)
393 (define-key YaTeX-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
394 (define-key YaTeX-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
395 (define-key YaTeX-mode-map "\M-\C-m" 'YaTeX-intelligent-newline)
396 (define-key YaTeX-mode-map "\C-i" 'YaTeX-indent-line)
397 (YaTeX-define-key "%" 'YaTeX-%-menu)
398 (YaTeX-define-key "t" 'YaTeX-typeset-menu)
399 (YaTeX-define-key "w" 'YaTeX-switch-mode-menu)
400 (YaTeX-define-key "'" 'YaTeX-prev-error)
401 (YaTeX-define-key "^" 'YaTeX-visit-main)
402 (YaTeX-define-key "4^" 'YaTeX-visit-main-other-window)
403 (YaTeX-define-key "4g" 'YaTeX-goto-corresponding-*-other-window)
404 (YaTeX-define-key "44" 'YaTeX-switch-to-window)
405 (and YaTeX-emacs-19 window-system
406 (progn
407 (YaTeX-define-key "5^" 'YaTeX-visit-main-other-frame)
408 (YaTeX-define-key "5g" 'YaTeX-goto-corresponding-*-other-frame)
409 (YaTeX-define-key "55" 'YaTeX-switch-to-window)))
410 (YaTeX-define-key " " 'YaTeX-do-completion)
411 (YaTeX-define-key "v" 'YaTeX-version)
413 (YaTeX-define-key "}" 'YaTeX-insert-braces-region)
414 (YaTeX-define-key "]" 'YaTeX-insert-brackets-region)
415 (YaTeX-define-key ")" 'YaTeX-insert-parens-region)
416 (YaTeX-define-key "$" 'YaTeX-insert-dollars-region)
417 (YaTeX-define-key "i" 'YaTeX-fill-item)
418 (YaTeX-define-key
419 "\\" '(lambda () (interactive) (insert "$\\backslash$")))
420 (if YaTeX-no-begend-shortcut
421 (progn
422 (YaTeX-define-key "B" 'YaTeX-make-begin-end-region)
423 (YaTeX-define-key "b" 'YaTeX-make-begin-end))
424 (YaTeX-define-begend-key "bc" "center")
425 (YaTeX-define-begend-key "bd" "document")
426 (YaTeX-define-begend-key "bD" "description")
427 (YaTeX-define-begend-key "be" "enumerate")
428 (YaTeX-define-begend-key "bE" "equation")
429 (YaTeX-define-begend-key "bi" "itemize")
430 (YaTeX-define-begend-key "bl" "flushleft")
431 (YaTeX-define-begend-key "bm" "minipage")
432 (YaTeX-define-begend-key "bt" "tabbing")
433 (YaTeX-define-begend-key "bT" "tabular")
434 (YaTeX-define-begend-key "b\^t" "table")
435 (YaTeX-define-begend-key "bp" "picture")
436 (YaTeX-define-begend-key "bq" "quote")
437 (YaTeX-define-begend-key "bQ" "quotation")
438 (YaTeX-define-begend-key "br" "flushright")
439 (YaTeX-define-begend-key "bv" "verbatim")
440 (YaTeX-define-begend-key "bV" "verse")
441 (YaTeX-define-key "B " 'YaTeX-make-begin-end-region)
442 (YaTeX-define-key "b " 'YaTeX-make-begin-end))
443 (YaTeX-define-key "e" 'YaTeX-end-environment)
444 (YaTeX-define-key "S" 'YaTeX-make-section-region)
445 (YaTeX-define-key "s" 'YaTeX-make-section)
446 (YaTeX-define-key "L" 'YaTeX-make-fontsize-region)
447 (YaTeX-define-key "l" 'YaTeX-make-fontsize)
448 (YaTeX-define-key "m" 'YaTeX-make-singlecmd)
449 (YaTeX-define-key "." 'YaTeX-comment-paragraph)
450 (YaTeX-define-key "," 'YaTeX-uncomment-paragraph)
451 (YaTeX-define-key ">" 'YaTeX-comment-region)
452 (YaTeX-define-key "<" 'YaTeX-uncomment-region)
453 (YaTeX-define-key "g" 'YaTeX-goto-corresponding-*)
454 (YaTeX-define-key "k" 'YaTeX-kill-*)
455 (YaTeX-define-key "c" 'YaTeX-change-*)
456 (YaTeX-define-key "a" 'YaTeX-make-accent)
457 (YaTeX-define-key "?" 'YaTeX-help)
458 (YaTeX-define-key "/" 'YaTeX-apropos)
459 (YaTeX-define-key "&" 'YaTeX-what-column)
460 (YaTeX-define-key "d" 'YaTeX-display-hierarchy)
461 (YaTeX-define-key "x" YaTeX-user-extensional-map)
462 (YaTeX-define-key "n"
463 '(lambda () (interactive) (insert "\\\\")))
464 (if YaTeX-dos
465 (define-key YaTeX-prefix-map "\C-r"
466 '(lambda () (interactive)
467 (set-screen-height YaTeX-saved-screen-height) (recenter))))
468 (mapcar
469 (function
470 (lambda (key)
471 (define-key YaTeX-mode-map (car key) 'YaTeX-math-insert-sequence)))
472 YaTeX-math-key-list))
474 (defvar YaTeX-section-completion-map nil
475 "*Key map used at YaTeX completion in the minibuffer.")
476 (if YaTeX-section-completion-map nil
477 (setq YaTeX-section-completion-map
478 (copy-keymap (or (and (boundp 'gmhist-completion-map)
479 gmhist-completion-map)
480 minibuffer-local-completion-map)))
481 (define-key YaTeX-section-completion-map
482 " " 'YaTeX-minibuffer-complete)
483 (define-key YaTeX-section-completion-map
484 "\C-i" 'YaTeX-minibuffer-complete)
485 (define-key YaTeX-section-completion-map
486 "\C-v" 'YaTeX-read-section-with-overview))
488 (defvar YaTeX-recursive-map nil
489 "*Key map used at YaTeX reading arguments in the minibuffer.")
490 (if YaTeX-recursive-map nil
491 (setq YaTeX-recursive-map (copy-keymap global-map))
492 (define-key YaTeX-recursive-map YaTeX-prefix YaTeX-prefix-map))
494 ;---------- Define other variable ----------
495 (defvar YaTeX-env-name "document" "*Initial tex-environment completion")
496 (defvar YaTeX-section-name
497 (if YaTeX-use-LaTeX2e "documentclass" "documentstyle")
498 "*Initial tex-section completion")
499 (defvar YaTeX-fontsize-name "large" "*Initial fontsize completion")
500 (defvar YaTeX-single-command "maketitle" "*Initial LaTeX single command")
501 (defvar YaTeX-kanji-code (if YaTeX-dos 1 2)
502 "*File kanji code used by Japanese TeX.")
504 (defvar YaTeX-coding-system nil "File coding system used by Japanese TeX.")
505 (cond
506 (YaTeX-emacs-20
507 (setq YaTeX-coding-system
508 (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist))))
509 ((boundp 'MULE)
510 (setq YaTeX-coding-system
511 (symbol-value (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist)))))
512 ((boundp 'NEMACS)
513 (setq YaTeX-latex-message-code latex-message-kanji-code)))
515 (defvar YaTeX-mode-syntax-table nil
516 "*Syntax table for yatex-mode")
518 (if YaTeX-mode-syntax-table nil
519 (setq YaTeX-mode-syntax-table (make-syntax-table (standard-syntax-table)))
520 (modify-syntax-entry ?\n " " YaTeX-mode-syntax-table)
521 (modify-syntax-entry ?\{ "(}" YaTeX-mode-syntax-table)
522 (modify-syntax-entry ?\} "){" YaTeX-mode-syntax-table)
523 (modify-syntax-entry ?\t " " YaTeX-mode-syntax-table)
524 (modify-syntax-entry ?\f ">" YaTeX-mode-syntax-table)
525 (modify-syntax-entry ?\n ">" YaTeX-mode-syntax-table)
526 (modify-syntax-entry ?$ "$$" YaTeX-mode-syntax-table)
527 (modify-syntax-entry ?% "<" YaTeX-mode-syntax-table)
528 (modify-syntax-entry ?\\ "/" YaTeX-mode-syntax-table)
529 (modify-syntax-entry ?~ " " YaTeX-mode-syntax-table))
531 ;---------- Provide YaTeX-mode ----------
532 ;;;
533 ;; Major mode definition
534 ;;;
535 (defun yatex-mode ()
536 " Yet Another LaTeX mode: Major mode for editing input files of LaTeX.
537 -You can invoke processes concerning LaTeX typesetting by
538 \\[YaTeX-typeset-menu]
539 -Complete LaTeX environment form of `\\begin{env} ... \\end{env}' by
540 \\[YaTeX-make-begin-end]
541 -Enclose region into some environment by
542 \\[universal-argument] \\[YaTeX-make-begin-end]
543 -Complete LaTeX command which takes argument like `\\section{}' by
544 \\[YaTeX-make-section]
545 -Put LaTeX command which takes no arguments like `\\maketitle' by
546 \\[YaTeX-make-singlecmd]
547 -Complete font or character size descriptor like `{\\large }' by
548 \\[YaTeX-make-fontsize]
549 -Enclose region into those descriptors above by
550 \\[universal-argument] \\[YaTeX-make-fontsize]
551 -Enter European accent notations by
552 \\[YaTeX-make-accent]
553 -Toggle various modes of YaTeX by
554 \\[YaTeX-switch-mode-menu]
555 -Change environt name (on the begin/end line) by
556 \\[YaTeX-change-*]
557 -Kill LaTeX command/environment sequences by
558 \\[YaTeX-kill-*]
559 -Kill LaTeX command/environment with its contents
560 \\[universal-argument] \\[YaTeX-kill-*]
561 -Go to corresponding object (begin/end, file, labels) by
562 \\[YaTeX-goto-corresponding-*] or
563 \\[YaTeX-goto-corresponding-*-other-window] (in other window)
564 \\[YaTeX-goto-corresponding-*-other-frame] (in other frame)
565 -Go to main LaTeX source text by
566 \\[YaTeX-visit-main] or
567 \\[YaTeX-visit-main-other-window] (in other window)
568 \\[YaTeX-visit-main-other-frame] (in other frame)
569 -Comment out or uncomment region by
570 \\[YaTeX-comment-region] or \\[YaTeX-uncomment-region]
571 -Comment out or uncomment paragraph by
572 \\[YaTeX-comment-paragraph] or \\[YaTeX-uncomment-paragraph]
573 -Make an \\item entry hang-indented by
574 \\[YaTeX-fill-item]
575 -Enclose the region with parentheses by
576 \\[YaTeX-insert-parens-region]
577 \\[YaTeX-insert-braces-region]
578 \\[YaTeX-insert-brackets-region]
579 \\[YaTeX-insert-dollars-region]
580 -Look up the corresponding column header of tabular environment by
581 \\[YaTeX-what-column]
582 -Enter a newline and an entry suitable for environment by
583 \\[YaTeX-intelligent-newline]
584 -View the structure of file inclusion by
585 \\[YaTeX-display-hierarchy]
586 -Refer the online help of popular LaTeX commands by
587 \\[YaTeX-help] (help)
588 \\[YaTeX-apropos] (apropos)
589 -Edit `%# notation' by
590 \\[YaTeX-%-menu]
592 Those are enough for fastening your editing of LaTeX source. But further
593 more features are available and they are documented in the manual.
594 "
595 (interactive)
596 (kill-all-local-variables)
597 (setq major-mode 'yatex-mode)
598 (setq mode-name (if YaTeX-japan "やてふ" "YaTeX"))
599 (mapcar 'make-local-variable
600 '(dvi2-command fill-column fill-prefix
601 tmp-env-table tmp-section-table tmp-fontsize-table
602 tmp-singlecmd-table paragraph-start paragraph-separate
603 YaTeX-math-mode indent-line-function
604 comment-start comment-start-skip
605 ))
606 (cond ((boundp 'MULE)
607 (set-file-coding-system YaTeX-coding-system))
608 ((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system))
609 (setq buffer-file-coding-system
610 (or (and (fboundp 'set-auto-coding) buffer-file-name
611 (save-excursion
612 (set-auto-coding buffer-file-name 2000)))
613 YaTeX-coding-system)))
614 ((featurep 'mule)
615 (set-file-coding-system YaTeX-coding-system))
616 ((boundp 'NEMACS)
617 (make-local-variable 'kanji-fileio-code)
618 (setq kanji-fileio-code YaTeX-kanji-code)))
619 (setq fill-column YaTeX-fill-column
620 fill-prefix YaTeX-fill-prefix
621 paragraph-start YaTeX-paragraph-start
622 paragraph-separate YaTeX-paragraph-separate
623 indent-line-function 'YaTeX-indent-line
624 comment-start YaTeX-comment-prefix
625 comment-end ""
626 comment-start-skip "[^\\\\]%+[ \t]*"
627 )
628 (if (boundp 'kill-buffer-hook) ;For Recent Emacs
629 (set (make-local-variable 'kill-buffer-hook)
630 (cons 'YaTeX-kill-buffer-hook kill-buffer-hook)))
631 (if (and YaTeX-use-font-lock (featurep 'font-lock))
632 (progn
633 (YaTeX-font-lock-set-default-keywords)
634 (or (featurep 'xemacs)
635 (set (make-local-variable 'font-lock-defaults)
636 (get 'yatex-mode 'font-lock-defaults)))
637 ;;(font-lock-mode 1)
638 ))
639 (use-local-map YaTeX-mode-map)
640 (set-syntax-table YaTeX-mode-syntax-table)
641 (if YaTeX-dos (setq YaTeX-saved-screen-height (screen-height)))
642 (YaTeX-read-user-completion-table)
643 (and (fboundp 'YaTeX-19-collect-macros) (YaTeX-19-collect-macros))
644 (makunbound 'inenv)
645 (turn-on-auto-fill) ;1.63
646 (and (= 0 (buffer-size)) (file-exists-p YaTeX-template-file)
647 (y-or-n-p (format "Insert %s?" YaTeX-template-file))
648 (insert-file-contents (expand-file-name YaTeX-template-file)))
649 (run-hooks 'text-mode-hook 'yatex-mode-hook))
651 ;---------- Define YaTeX-mode functions ----------
652 (defvar YaTeX-ec "\\" "Escape character of current mark-up language.")
653 (defvar YaTeX-ec-regexp (regexp-quote YaTeX-ec))
654 (defvar YaTeX-struct-begin
655 (concat YaTeX-ec "begin{%1}%2")
656 "Keyword format of begin-environment.")
657 (defvar YaTeX-struct-end
658 (concat YaTeX-ec "end{%1}")
659 "Keyword format of end-environment.")
660 (defvar YaTeX-struct-name-regexp "[^}]+"
661 "Environment name regexp.")
662 (defvar YaTeX-TeX-token-regexp
663 (cond (YaTeX-japan "[A-Za-z*あ-ん亜-龠]+")
664 (t "[A-Za-z*]+"))
665 "Regexp of characters which can be a member of TeX command's name.")
666 (defvar YaTeX-command-token-regexp YaTeX-TeX-token-regexp
667 "Regexp of characters which can be a member of current mark up language's command name.")
669 ;;(defvar YaTeX-struct-section
670 ;; (concat YaTeX-ec "%1{%2}")
671 ;; "Keyword to make section.")
673 ;;;
674 ;; autoload section
675 ;;;
677 ;;autoload from yatexprc.el
678 (autoload 'YaTeX-visit-main "yatexprc" "Visit main LaTeX file." t)
679 (autoload 'YaTeX-visit-main-other-window "yatexprc"
680 "Visit main other window." t)
681 (autoload 'YaTeX-main-file-p "yatexprc" "Check if the file is main." t)
682 (autoload 'YaTeX-get-builtin "yatexprc" "Get %# built-in." t)
683 (autoload 'YaTeX-system "yatexprc" "Call system command" t)
684 (autoload 'YaTeX-save-buffers "yatexprc" "Save buffers of same major mode" t)
686 ;;autoload from yatexmth.el
687 (autoload 'YaTeX-math-insert-sequence "yatexmth" "Image input." t)
688 (autoload 'YaTeX-in-math-mode-p "yatexmth" "Check if in math-env." t)
689 (autoload 'YaTeX-toggle-math-mode "yatexmth" "YaTeX math-mode interfaces." t)
690 (autoload 'YaTeX-math-member-p "yatexmth" "Check if a word is math command." t)
691 (autoload 'YaTeX-insert-amsparens-region "yatexmth" "AMS parens region" t)
692 (autoload 'YaTeX-insert-amsbraces-region "yatexmth" "AMS braces region" t)
693 (autoload 'YaTeX-insert-amsbrackets-region "yatexmth" "AMS brackets region" t)
694 (autoload 'YaTeX-on-parenthesis-p "yatexmth" "Check if on math-parens" t)
695 (autoload 'YaTeX-goto-open-paren "yatexmth" "Goto opening paren" t)
696 (autoload 'YaTeX-change-parentheses "yatexmth" "Change corresponding parens" t)
698 ;;autoload from yatexhlp.el
699 (autoload 'YaTeX-help "yatexhlp" "YaTeX helper with LaTeX commands." t)
700 (autoload 'YaTeX-apropos "yatexhlp" "Apropos for (La)TeX commands." t)
702 ;;autoload from yatexgen.el
703 (autoload 'YaTeX-generate "yatexgen" "YaTeX add-in function generator." t)
704 (autoload 'YaTeX-generate-simple "yatexgen" "YaTeX add-in support." t)
706 ;;autoload from yatexsec.el
707 (autoload 'YaTeX-section-overview "yatexsec" "YaTeX sectioning(view)" t)
708 (autoload 'YaTeX-read-section-in-minibuffer "yatexsec" "YaTeX sectioning" t)
709 (autoload 'YaTeX-make-section-with-overview "yatexsec" "YaTeX sectioning" t)
711 ;;autoload from yatexenv.el
712 (autoload 'YaTeX-what-column "yatexenv" "YaTeX env. specific funcs" t)
713 (autoload 'YaTeX-intelligent-newline "yatexenv" "YaTeX env. specific funcs" t)
714 (autoload 'YaTeX-indent-line-equation "yatexenv" "Indent equation lines." t)
715 (autoload 'YaTeX-goto-corresponding-leftright "yatexenv" "\left\right jumps" t)
717 ;;autoload from yatexhie.el
718 (autoload 'YaTeX-display-hierarchy "yatexhie"
719 "YaTeX document hierarchy browser" t)
720 (autoload 'YaTeX-display-hierarchy-directly "yatexhie"
721 "Same as YaTeX-display-hierarchy. Call from mouse." t)
724 ;;;
725 ;; YaTeX-mode functions
726 ;;;
727 (defun YaTeX-insert-begin-end (env region-mode)
728 "Insert \\begin{mode-name} and \\end{mode-name}.
729 This works also for other defined begin/end tokens to define the structure."
730 (setq YaTeX-current-completion-type 'begin)
731 (let*((ccol (current-column)) beg beg2 exchange
732 (arg region-mode) ;for old compatibility
733 (indent-column (+ ccol YaTeX-environment-indent))(i 1) func)
734 (if (and region-mode (> (point) (mark)))
735 (progn (exchange-point-and-mark)
736 (setq exchange t
737 ccol (current-column)
738 indent-column (+ ccol YaTeX-environment-indent))))
739 ;;VER2 (insert "\\begin{" env "}" (YaTeX-addin env))
740 (setq beg (point))
741 (YaTeX-insert-struc 'begin env)
742 (setq beg2 (point))
743 (insert "\n")
744 (indent-to indent-column)
745 (save-excursion
746 ;;indent optional argument of \begin{env}, if any
747 (while (> (point-beginning-of-line) beg)
748 (skip-chars-forward "\\s " (point-end-of-line))
749 (indent-to indent-column)
750 (forward-line -1)))
751 (require 'yatexenv)
752 (if region-mode
753 ;;if region-mode, indent all text in the region
754 (save-excursion
755 (if (fboundp (intern-soft (concat "YaTeX-enclose-" env)))
756 (funcall (intern-soft (concat "YaTeX-enclose-" env))
757 (point) (mark))
758 (while (< (progn (forward-line 1) (point)) (mark))
759 (if (eolp) nil
760 (skip-chars-forward " \t\n")
761 (indent-to indent-column))))))
762 (if region-mode (exchange-point-and-mark))
763 (indent-to ccol)
764 ;;VER2 (insert "\\end{" env "}\n")
765 (YaTeX-insert-struc 'end env)
766 (YaTeX-reindent ccol)
767 (if region-mode
768 (progn
769 (insert "\n")
770 (or exchange (exchange-point-and-mark)))
771 (goto-char beg2)
772 (YaTeX-intelligent-newline nil)
773 (YaTeX-indent-line))
774 (if YaTeX-current-position-register
775 (point-to-register YaTeX-current-position-register))))
777 (defun YaTeX-make-begin-end (arg)
778 "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
779 by completing read.
780 If you invoke this command with universal argument,
781 \(key binding for universal-argument is \\[universal-argument]\)
782 you can put REGION into that environment between \\begin and \\end."
783 (interactive "P")
784 (let*
785 ((mode (if arg " region" ""))
786 (env
787 (YaTeX-read-environment
788 (format "Begin environment%s(default %s): " mode YaTeX-env-name))))
789 (if (string= env "")
790 (setq env YaTeX-env-name))
791 (setq YaTeX-env-name env)
792 (YaTeX-update-table
793 (list YaTeX-env-name) 'env-table 'user-env-table 'tmp-env-table)
794 (YaTeX-insert-begin-end YaTeX-env-name arg)))
796 (defun YaTeX-make-begin-end-region ()
797 "Call YaTeX-make-begin-end with ARG to specify region mode."
798 (interactive)
799 (YaTeX-make-begin-end t))
801 (defun YaTeX-guess-section-type ()
802 (if (eq major-mode 'yatex-mode)
803 (save-excursion
804 (cond
805 ((save-excursion (not (search-backward YaTeX-ec nil t)))
806 (if YaTeX-use-LaTeX2e "documentclass" "documentstyle"))
807 ((progn (forward-char -1) (looking-at "表\\|図\\|式"))
808 "ref")
809 ((and (looking-at "[a-z \t]")
810 (progn (skip-chars-backward "a-z \t")
811 (looking-at "table\\|figure\\|formula")))
812 "ref")
813 ((save-excursion
814 (skip-chars-backward "[^ア-ン]")
815 (looking-at "プログラム\\|リスト"))
816 "ref")
817 ((YaTeX-re-search-active-backward
818 (concat YaTeX-ec-regexp "begin{\\([^}]+\\)}")
819 (regexp-quote YaTeX-comment-prefix)
820 (save-excursion (forward-line -1) (point))
821 t)
822 (let ((env (YaTeX-match-string 1)))
823 (cdr (assoc env
824 '(("table" . "caption"))))))
825 ))))
827 (defun YaTeX-make-section (arg &optional beg end cmd)
828 "Make LaTeX \\section{} type command with completing read.
829 With numeric ARG, you can specify the number of arguments of
830 LaTeX command.
831 For example, if you want to produce LaTeX command
833 \\addtolength{\\topmargin}{8mm}
835 which has two arguments. You can produce that sequence by typing...
836 ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
837 \(by default\)
838 Then yatex will automatically complete `addtolength' with two arguments
839 next time.
840 You can complete symbol at LaTeX command and the 1st argument.
842 If the optional 2nd and 3rd argument BEG END are specified, enclose
843 the region from BEG to END into the first argument of the LaTeX sequence.
844 Optional 4th arg CMD is LaTeX command name, for non-interactive use."
845 (interactive "P")
846 (setq YaTeX-current-completion-type 'section)
847 (if (equal arg '(4)) (setq beg (region-beginning) end (region-end)))
848 (unwind-protect
849 (let*
850 ((source-window (selected-window))
851 guess
852 (section
853 (or cmd
854 (progn
855 (setq guess
856 (or (YaTeX-guess-section-type) YaTeX-section-name))
857 (YaTeX-read-section
858 (if YaTeX-simple-messages
859 (format "Section-type (default %s): " guess)
860 (if (> (minibuffer-depth) 0)
861 (format "%s???{} (default %s)%s: "
862 YaTeX-ec guess
863 (format "[level:%d]" (minibuffer-depth)))
864 (format "(C-v for view-section) %s???{%s} (default %s): "
865 YaTeX-ec (if beg "region" "") guess)))
866 nil))))
867 (section (if (string= section "") guess section))
868 (numarg ;; The number of section-type command's argument
869 (or (and (numberp arg) arg)
870 (nth 1 (YaTeX-lookup-table section 'section))
871 1))
872 (arg-reader (intern-soft (concat "YaTeX::" section)))
873 (addin-args (and arg-reader (fboundp arg-reader)))
874 (title "")
875 (j 1)
876 (after-change-functions nil) ;inhibit font-locking temporarily
877 (enable-recursive-minibuffers t));;let
878 (setq YaTeX-section-name section)
879 (if beg
880 (let ((e (make-marker)))
881 (goto-char end)
882 (insert "}")
883 (set-marker e (point))
884 (goto-char beg)
885 (insert YaTeX-ec YaTeX-section-name "{")
886 (goto-char e)
887 (set-marker e nil))
888 (use-global-map YaTeX-recursive-map)
889 (if (= numarg 0) (YaTeX-make-singlecmd YaTeX-section-name)
890 (progn (insert YaTeX-ec YaTeX-section-name)
891 (insert (YaTeX-addin YaTeX-section-name))))
892 (while (<= j numarg)
893 (insert
894 "{"
895 (setq title
896 (cond
897 (addin-args (funcall arg-reader j))
898 (YaTeX-skip-default-reader "")
899 (t
900 (read-string (format "Argument %d of %s: " j section)))))
901 "}")
902 (setq j (1+ j))))
903 (YaTeX-update-table
904 (if (/= numarg 1) (list section numarg)
905 (list section))
906 'section-table 'user-section-table 'tmp-section-table)
907 (if YaTeX-current-position-register
908 (point-to-register YaTeX-current-position-register))
909 (if (string= (buffer-substring (- (point) 2) (point)) "{}")
910 (forward-char -1))
911 (while (string= (buffer-substring (- (point) 3) (1- (point))) "{}")
912 (forward-char -2)))
913 (if (<= (minibuffer-depth) 0) (use-global-map global-map))
914 (insert ""))) ;insert dummy string to fontify(Emacs20)
916 (defun YaTeX-make-section-region (args beg end)
917 "Call YaTeX-make-section with arguments to specify region mode."
918 (interactive "P\nr")
919 (YaTeX-make-section args beg end))
921 (defun YaTeX-make-fontsize (arg &optional fontsize)
922 "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
923 If you invoke this command with universal argument, you can put region
924 into {\\xxx } braces.
925 \(key binding for universal-argument is \\[universal-argument]\)"
926 (interactive "P")
927 (YaTeX-sync-local-table 'tmp-fontsize-table)
928 (let* ((mode (if arg "region" ""))
929 (fontsize
930 (or fontsize
931 (YaTeX-read-fontsize
932 (if YaTeX-simple-messages
933 (format "Font or size (default %s): " YaTeX-fontsize-name)
934 (format "{\\??? %s} (default %s)%s: " mode YaTeX-fontsize-name
935 (if (> (minibuffer-depth) 0)
936 (format "[level:%d]" (minibuffer-depth)) "")))
937 nil nil))))
938 (if (string= fontsize "")
939 (setq fontsize YaTeX-fontsize-name))
940 (setq YaTeX-current-completion-type 'large)
941 (setq YaTeX-fontsize-name fontsize)
942 (YaTeX-update-table
943 (list YaTeX-fontsize-name)
944 'fontsize-table 'user-fontsize-table 'tmp-fontsize-table)
945 (and YaTeX-use-LaTeX2e
946 (YaTeX-latex2e-p)
947 (setq fontsize
948 (cdr (assoc YaTeX-fontsize-name LaTeX2e-fontstyle-alist)))
949 (setq YaTeX-fontsize-name fontsize))
950 (if arg
951 (save-excursion
952 (if (> (point) (mark)) (exchange-point-and-mark))
953 (insert "{\\" YaTeX-fontsize-name " ")
954 (exchange-point-and-mark)
955 (insert "}"))
956 (insert (concat "{\\" YaTeX-fontsize-name " }"))
957 (forward-char -1)
958 (if YaTeX-current-position-register
959 (point-to-register YaTeX-current-position-register))
960 (save-excursion
961 (insert (YaTeX-addin YaTeX-fontsize-name))))))
963 (defun YaTeX-make-fontsize-region ()
964 "Call function:YaTeX-make-fontsize with ARG to specify region mode."
965 (interactive)
966 (YaTeX-make-fontsize t))
968 (defvar YaTeX-singlecmd-suffix "" "*Suffix for maketitle-type commands.")
969 (defvar YaTeX-read-singlecmd-history nil "Holds maketitle-type history.")
970 (put 'YaTeX-read-singlecmd-history 'no-default t)
971 (defun YaTeX-make-singlecmd (single)
972 (interactive
973 (list (YaTeX-cplread-with-learning
974 (if YaTeX-simple-messages
975 (format "maketitle-type (default %s): " YaTeX-single-command)
976 (format "%s??? (default %s)%s: " YaTeX-ec YaTeX-single-command
977 (if (> (minibuffer-depth) 0)
978 (format "[level:%d]" (minibuffer-depth)) "")))
979 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table
980 nil nil nil 'YaTeX-read-singlecmd-history)))
981 (if (string= single "")
982 (setq single YaTeX-single-command))
983 (setq YaTeX-single-command single)
984 (setq YaTeX-current-completion-type 'maketitle)
985 (let ((dollar (and (not (YaTeX-in-math-mode-p))
986 (YaTeX-math-member-p YaTeX-single-command)))
987 p q)
988 (if dollar (insert "$"))
989 (insert YaTeX-ec YaTeX-single-command)
990 (setq p (point))
991 (insert (YaTeX-addin single) YaTeX-singlecmd-suffix)
992 (if dollar (insert "$"))
993 (setq q (point))
994 (goto-char p)
995 (forward-char -2)
996 (if (looking-at "\\[\\]") (forward-char 1) (goto-char q)))
997 (if YaTeX-current-position-register
998 (point-to-register YaTeX-current-position-register)))
1000 (defvar YaTeX-completion-begin-regexp "[{\\]"
1001 "Regular expression of limit where LaTeX command's completion begins.")
1003 (defun YaTeX-do-completion ()
1004 "Try completion on LaTeX command preceding point."
1005 (interactive)
1006 (if
1007 (or (eq (preceding-char) ? )
1008 (eq (preceding-char) ?\t)
1009 (eq (preceding-char) ?\n)
1010 (bobp))
1011 (message "Nothing to complete.") ;Do not complete
1012 (let* ((end (point))
1013 (limit (point-beginning-of-line))
1014 (completion-begin
1015 (progn (re-search-backward "[ \t\n]" limit 1) (point)))
1016 (begin (progn
1017 (goto-char end)
1018 (if (re-search-backward YaTeX-completion-begin-regexp
1019 completion-begin t)
1020 (1+ (point))
1021 nil))))
1022 (goto-char end)
1023 (cond
1024 ((null begin)
1025 (message "I think it is not a LaTeX sequence."))
1026 (t
1027 (mapcar 'YaTeX-sync-local-table
1028 '(tmp-section-table tmp-env-table tmp-singlecmd-table))
1029 (let*((pattern (buffer-substring begin end))
1030 (all-table
1031 (append
1032 section-table user-section-table tmp-section-table
1033 env-table user-env-table tmp-env-table
1034 singlecmd-table user-singlecmd-table tmp-singlecmd-table))
1035 ;; First,
1036 ;; search completion without backslash.
1037 (completion (try-completion pattern all-table)))
1038 (if
1039 (eq completion nil)
1040 ;; Next,
1041 ;; search completion with backslash
1042 (setq completion
1043 (try-completion (buffer-substring (1- begin) end)
1044 all-table nil)
1045 begin (1- begin)))
1046 (cond
1047 ((null completion)
1048 (message (concat "Can't find completion for '" pattern "'"))
1049 (ding))
1050 ((eq completion t) (message "Sole completion."))
1051 ((not (string= completion pattern))
1052 (kill-region begin end)
1053 (insert completion)
1055 (t
1056 (message "Making completion list...")
1057 (with-output-to-temp-buffer "*Help*"
1058 (display-completion-list
1059 (all-completions pattern all-table)))))))))))
1061 (defun YaTeX-toggle-modify-mode (&optional arg)
1062 (interactive "P")
1063 (or (memq 'YaTeX-modify-mode mode-line-format)
1064 (setq mode-line-format
1065 (append (list "" 'YaTeX-modify-mode) mode-line-format)))
1066 (if (or arg (null YaTeX-modify-mode))
1067 (progn
1068 (setq YaTeX-modify-mode "*m*")
1069 (message "Modify mode"))
1070 (setq YaTeX-modify-mode nil)
1071 (message "Cancel modify mode."))
1072 (set-buffer-modified-p (buffer-modified-p))) ;redraw mode-line
1074 (defun YaTeX-switch-mode-menu (arg &optional char)
1075 (interactive "P")
1076 (message "Toggle: (M)odify-mode ma(T)h-mode")
1077 (let ((c (or char (read-char))))
1078 (cond
1079 ((= c ?m) (YaTeX-toggle-modify-mode arg))
1080 ((or (= c ?$) (= c ?t))
1081 (if YaTeX-auto-math-mode
1082 (message "Makes no sense in YaTeX-auto-math-mode.")
1083 (YaTeX-toggle-math-mode arg))))))
1085 (defun YaTeX-insert-quote ()
1086 (interactive)
1087 (insert
1088 (cond
1089 ((YaTeX-literal-p) ?\")
1090 ((= (preceding-char) ?\\ ) ?\")
1091 ;((= (preceding-char) ?\( ) ?\")
1092 ((or (= (preceding-char) 32)
1093 (= (preceding-char) 9)
1094 (= (preceding-char) ?\n)
1095 (bobp)
1096 (string-match
1097 (regexp-quote (char-to-string (preceding-char)))
1098 "、。,.?!「」『』【】()"))
1099 "``")
1100 (t "''"))))
1102 (defun YaTeX-closable-p ()
1103 (and (not YaTeX-modify-mode)
1104 (not (eq YaTeX-close-paren-always 'never))
1105 (or YaTeX-close-paren-always (eolp))
1106 (not (input-pending-p))
1107 (not (YaTeX-literal-p)))
1108 ;;(or YaTeX-modify-mode
1109 ;; (and (not YaTeX-close-paren-always) (not (eolp)))
1110 ;; (input-pending-p)
1111 ;; (YaTeX-quick-in-environment-p "verbatim"))
1114 (defun YaTeX-insert-braces-region (beg end &optional open close)
1115 (interactive "r")
1116 (save-excursion
1117 (goto-char end)
1118 (insert (or close "}"))
1119 (goto-char beg)
1120 (insert (or open "{"))))
1122 (defun YaTeX-insert-braces (arg &optional open close)
1123 (interactive "p")
1124 (let (env)
1125 (cond
1126 ((YaTeX-jmode) (YaTeX-self-insert arg))
1127 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1128 ((save-excursion
1129 (and (> (- (point) (point-min)) 6)
1130 (condition-case () (forward-char -6) (error nil)))
1131 (looking-at "\\\\left\\\\"))
1132 (insert "{\\right\\}")
1133 (forward-char -8))
1134 ((save-excursion ;from matsu@math.s.chiba-u.ac.jp
1135 (and (> (- (point) (point-min)) 6) (forward-char -6))
1136 (looking-at "\\\\[bB]igl\\\\"))
1137 (insert
1138 (concat
1139 "{" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\}"))
1140 (forward-char -7))
1141 ((save-excursion
1142 (and (> (- (point) (point-min)) 7)
1143 (condition-case () (forward-char -7) (error nil)))
1144 (looking-at "\\\\[bB]iggl\\\\"))
1145 (insert
1146 (concat
1147 "{" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\}"))
1148 (forward-char -8))
1149 ((= (preceding-char) ?\\ )
1150 (insert "{\\}")
1151 (forward-char -2)) ;matsu's hack ends here
1152 ((and (> (point) (+ (point-min) 4))
1153 (save-excursion (backward-char 4) (looking-at "\\\\end"))
1154 (not (YaTeX-literal-p))
1155 (setq env (YaTeX-inner-environment)))
1156 (momentary-string-display
1157 (concat
1158 "{"
1159 (cond
1160 (YaTeX-japan
1161 (format "今度からはちゃんと %s b を使いましょう" YaTeX-prefix))
1162 (t (format "You don't understand Zen of `%s b':p" YaTeX-prefix)))
1163 "}")
1164 (point))
1165 (insert (or open "{") env (or close "}")))
1166 (t
1167 (insert (or open "{") (or close "}"))
1168 (forward-char -1)
1169 (if (and (eq (char-after (point)) ?\})
1170 (eq (char-after (- (point) 2)) ?\\ ))
1171 (progn (insert "\\") (forward-char -1)))
1172 ))))
1174 (defun YaTeX-jmode ()
1175 (or (and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
1176 (and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)))
1178 (defun YaTeX-jmode-off ()
1179 (cond
1180 ((and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
1181 (canna-toggle-japanese-mode))
1182 ((and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
1183 (egg:toggle-egg-mode-on-off))
1184 ((and (fboundp 'skk-mode) (boundp 'skk-mode) skk-mode)
1185 (cond
1186 ((fboundp 'skk-latin-mode) (skk-latin-mode t))
1187 ((fboundp 'skk-mode-off) (skk-mode-off))
1188 (t (j-mode-off))))
1189 ((and (fboundp 'toggle-input-method) current-input-method)
1190 (toggle-input-method))
1191 ((and (fboundp 'fep-force-off) (fep-force-off)))))
1193 (defun YaTeX-self-insert (arg)
1194 (call-interactively (global-key-binding (char-to-string last-command-char))))
1196 (defun YaTeX-insert-brackets (arg)
1197 "Insert Kagi-kakko or \\ [ \\] pair or simply \[."
1198 (interactive "p")
1199 (let ((col (1- (current-column))))
1200 (cond
1201 ((YaTeX-jmode) (YaTeX-self-insert arg))
1202 ((not (YaTeX-closable-p))
1203 (YaTeX-self-insert arg))
1204 ((save-excursion
1205 (and (> (- (point) (point-min)) 5) (forward-char -5))
1206 (looking-at "\\\\left"))
1207 (insert "[\\right]")
1208 (forward-char -7))
1209 ((save-excursion ;from matsu@math.s.chiba-u.ac.jp
1210 (and (> (- (point) (point-min)) 5) (forward-char -5))
1211 (looking-at "\\\\[bB]igl"))
1212 (insert
1213 (concat
1214 "[" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r]"))
1215 (forward-char -6))
1216 ((save-excursion
1217 (and (> (- (point) (point-min)) 6) (forward-char -6))
1218 (looking-at "\\\\[bB]iggl"))
1219 (insert
1220 (concat
1221 "[" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r]"))
1222 (forward-char -7)) ;matsu's hack ends here
1223 ((and (= (preceding-char) ?\\ )
1224 (/= (char-after (- (point) 2)) ?\\ )
1225 (not (YaTeX-in-math-mode-p)))
1226 (insert last-command-char "\n")
1227 (indent-to (max 0 col))
1228 (insert "\\]")
1229 (beginning-of-line)
1230 (open-line 1)
1231 (delete-region (point) (progn (beginning-of-line) (point)))
1232 (indent-to (+ YaTeX-environment-indent (max 0 col)))
1233 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1)))
1234 ((YaTeX-closable-p)
1235 (insert "[]")
1236 (backward-char 1))
1237 (t (YaTeX-self-insert arg)))))
1239 (defun YaTeX-insert-brackets-region (beg end)
1240 (interactive "r")
1241 (YaTeX-insert-braces-region beg end "[" "]"))
1243 (defun YaTeX-insert-parens (arg)
1244 "Insert parenthesis pair."
1245 (interactive "p")
1246 (cond
1247 ((YaTeX-jmode) (YaTeX-self-insert arg))
1248 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1249 ((save-excursion
1250 (and (> (- (point) (point-min)) 5) (forward-char -5))
1251 (looking-at "\\\\left"))
1252 (insert "(\\right)")
1253 (forward-char -7))
1254 ((save-excursion ;from matsu@math.s.chiba-u.ac.jp
1255 (and (> (- (point) (point-min)) 5) (forward-char -5))
1256 (looking-at "\\\\[bB]igl"))
1257 (insert
1258 (concat
1259 "(" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r)"))
1260 (forward-char -6))
1261 ((save-excursion
1262 (and (> (- (point) (point-min)) 6) (forward-char -6))
1263 (looking-at "\\\\[bB]iggl"))
1264 (insert
1265 (concat
1266 "(" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r)"))
1267 (forward-char -7))
1268 ((= (preceding-char) ?\\ ) ;matsu's hack ends here
1269 (insert "(\\)")
1270 (backward-char 2))
1271 ((YaTeX-closable-p)
1272 (insert "()")
1273 (backward-char 1))
1274 (t (YaTeX-self-insert arg))))
1276 (defun YaTeX-insert-parens-region (beg end)
1277 (interactive "r")
1278 (YaTeX-insert-braces-region beg end "(" ")"))
1280 (defun YaTeX-insert-bar (arg)
1281 "Insert bar pair."
1282 (interactive "p")
1283 (cond
1284 ((YaTeX-jmode) (YaTeX-self-insert arg))
1285 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1286 ((save-excursion
1287 (and (> (- (point) (point-min)) 5) (forward-char -5))
1288 (looking-at "\\\\left"))
1289 (insert "|\\right|")
1290 (forward-char -7))
1291 ((save-excursion ;from matsu@math.s.chiba-u.ac.jp
1292 (and (> (- (point) (point-min)) 5) (forward-char -5))
1293 (looking-at "\\\\[bB]igl"))
1294 (insert
1295 (concat
1296 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r|"))
1297 (forward-char -6))
1298 ((save-excursion
1299 (and (> (- (point) (point-min)) 6) (forward-char -6))
1300 (looking-at "\\\\[bB]iggl"))
1301 (insert
1302 (concat
1303 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r|"))
1304 (forward-char -7))
1305 ((save-excursion ; added by Jin <MAF01011@nifty.ne.jp>
1306 (and (> (- (point) (point-min)) 6) (forward-char -6))
1307 (looking-at "\\\\left\\\\"))
1308 (insert "|\\right\\|")
1309 (forward-char -8))
1310 ((save-excursion
1311 (and (> (- (point) (point-min)) 6) (forward-char -6))
1312 (looking-at "\\\\[bB]igl\\\\"))
1313 (insert
1314 (concat
1315 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\|"))
1316 (forward-char -7))
1317 ((save-excursion
1318 (and (> (- (point) (point-min)) 7) (forward-char -7))
1319 (looking-at "\\\\[bB]iggl\\\\"))
1320 (insert
1321 (concat
1322 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\|"))
1323 (forward-char -8)) ; added by Jin up to here.
1324 ((= (preceding-char) ?\\ )
1325 (insert "|\\|")
1326 (backward-char 2))
1327 ; ((and (YaTeX-closable-p)
1328 ; (/= (preceding-char) ?|)
1329 ; (/= (following-char) ?|))
1330 ; (insert "||")
1331 ; (backward-char 1))
1332 (t (YaTeX-self-insert arg))))
1334 (defun YaTeX-insert-dollar ()
1335 (interactive)
1336 (if (or (not (YaTeX-closable-p))
1337 (= (preceding-char) 92)
1338 (and (YaTeX-in-math-mode-p)
1339 (or (/= (preceding-char) ?$) (/= (following-char) ?$))))
1340 (insert "$")
1341 (insert "$$")
1342 (forward-char -1)
1343 (YaTeX-jmode-off)
1344 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1))))
1346 (defun YaTeX-insert-dollars-region (beg end)
1347 (interactive "r")
1348 (YaTeX-insert-braces-region beg end "$" "$"))
1350 (defun YaTeX-insert-amper ()
1351 (interactive)
1352 (if (or (string-match YaTeX-array-env-regexp
1353 (or (YaTeX-inner-environment t) "document"))
1354 (= (preceding-char) 92)
1355 (YaTeX-literal-p))
1356 (insert "&")
1357 (insert "\\&")))
1359 (defun YaTeX-version ()
1360 "Return string of the version of running YaTeX."
1361 (interactive)
1362 (message
1363 (concat "Yet Another tex-mode "
1364 (if YaTeX-japan "「野鳥」" "`Wild Bird'")
1365 " Revision "
1366 YaTeX-revision-number)))
1368 (defun YaTeX-typeset-menu (arg &optional char)
1369 "Typeset, preview, visit error and miscellaneous convenient menu.
1370 Optional second argument CHAR is for non-interactive call from menu."
1371 (interactive "P")
1372 (message
1373 (concat "J)latex R)egion B)ibtex mk(I)ndex "
1374 (if (fboundp 'start-process) "K)ill-latex ")
1375 "P)review "
1376 (and (boundp 'window-system) window-system "S)earch ")
1377 "V)iewerr L)pr"))
1378 (let ((sw (selected-window)) (c (or char (read-char))))
1379 (require 'yatexprc) ;for Nemacs's bug
1380 (select-window sw)
1381 (cond
1382 ((= c ?j) (YaTeX-typeset-buffer))
1383 ((= c ?r) (YaTeX-typeset-region))
1384 ((= c ?b) (YaTeX-call-command-on-file
1385 bibtex-command "*YaTeX-bibtex*"))
1386 ((= c ?i) (YaTeX-call-command-on-file
1387 makeindex-command "*YaTeX-makeindex*"))
1388 ((= c ?k) (YaTeX-kill-typeset-process YaTeX-typeset-process))
1389 ((= c ?p) (call-interactively 'YaTeX-preview))
1390 ((= c ?q) (YaTeX-system "lpq" "*Printer queue*"))
1391 ((= c ?v) (YaTeX-view-error))
1392 ((= c ?l) (YaTeX-lpr arg))
1393 ((= c ?m) (YaTeX-switch-mode-menu arg))
1394 ((= c ?b) (YaTeX-insert-string "\\"))
1395 ((= c ?s) (YaTeX-xdvi-remote-search arg)))))
1397 (if (fboundp 'wrap-function-to-control-ime)
1398 (wrap-function-to-control-ime 'YaTeX-typeset-menu t "P"))
1401 (defun YaTeX-%-menu (&optional beg end char)
1402 "Operate %# notation."
1403 ;;Do not use interactive"r" for the functions which require no mark
1404 (interactive)
1405 (message "!)Edit-%%#! B)EGIN-END-region L)Edit-%%#LPR")
1406 (let ((c (or char (read-char))) (string "") key
1407 (b (make-marker)) (e (make-marker)))
1408 (save-excursion
1409 (cond
1410 ((or (= c ?!) (= c ?l)) ;Edit `%#!'
1411 (goto-char (point-min))
1412 (setq key (cond ((= c ?!) "%#!")
1413 ((= c ?l) "%#LPR")))
1414 (if (re-search-forward key nil t)
1415 (progn
1416 (setq string (buffer-substring (point) (point-end-of-line)))
1417 (delete-region (point) (progn (end-of-line) (point))))
1418 (open-line 1)
1419 (delete-region (point) (progn (beginning-of-line)(point)));for 19 :-<
1420 (insert key))
1421 (unwind-protect
1422 (setq string (read-string (concat key ": ") string))
1423 (insert string)))
1425 ((= c ?b) ;%#BEGIN %#END region
1426 (or end (setq beg (min (point) (mark)) end (max (point) (mark))))
1427 (set-marker b beg)
1428 (set-marker e end)
1429 (goto-char (point-min))
1430 (while (re-search-forward "^%#\\(BEGIN\\)\\|\\(END\\)$" nil t)
1431 (beginning-of-line)
1432 (delete-region (point) (progn (forward-line 1) (point))))
1433 (goto-char b)
1434 (open-line 1)
1435 (delete-region (point) (progn (beginning-of-line)(point)));for 19 :-<
1436 (insert "%#BEGIN")
1437 (goto-char e)
1438 (insert "%#END\n")
1439 (set-marker b nil)
1440 (set-marker e nil))
1441 ))))
1443 (defun YaTeX-goto-corresponding-label (reverse &optional otherwin)
1444 "Jump to corresponding \\label{} and \\ref{} or \\cite and \\bibitem.
1445 The default search direction depends on the command at the cursor position.
1446 When the cursor is on \\ref(\\cite), YaTeX will try to search the
1447 corresponding \\label(\\bibitem) backward,
1448 and if it fails search forward again. And when the cursor is
1449 on \\label(\\bibitem), YaTeX will search the corresponding \\ref(\\cite)
1450 forward at first and secondary backward.
1451 Argument REVERSE non-nil makes the default
1452 direction rule reverse. Since Search string is automatically set in
1453 search-last-string, you can repeat search the same label/ref by typing
1454 \\[isearch-forward] or \\[isearch-backward].
1455 If optional second argument OTHERWIN is non-nil, move to other window."
1457 (let ((scmd "") label direc string blist (p (point)) (cb (current-buffer))
1458 (refcommands "label\\|\\(page\\)?ref\\|cite\\|bibitem")
1459 (func (function (lambda (string sfunc)
1460 (or
1461 (funcall sfunc string nil t)
1462 (funcall (if (eq sfunc 're-search-forward)
1463 're-search-backward 're-search-forward)
1464 string nil t))))))
1465 (cond
1466 ((YaTeX-on-section-command-p refcommands)
1467 (setq scmd (cdr (assoc (YaTeX-match-string 1)
1468 '(("label" . "\\(page\\)?ref") ("ref" . "label")
1469 ("pageref" . "label")
1470 ("cite" . "bibitem") ("bibitem" . "cite")))))
1471 (goto-char (match-end 0))
1472 (let ((label (buffer-substring
1473 (1- (point)) (progn (backward-list 1) (1+ (point))))))
1474 ;(setq string (concat "\\" scmd "{" label "}"))
1475 (setq string (concat "\\\\" scmd "{" (regexp-quote label) "}"))
1476 (setq direc (if (string-match "ref\\|cite" scmd)
1477 're-search-forward 're-search-backward))
1478 (if YaTeX-current-position-register
1479 (point-to-register YaTeX-current-position-register))
1480 (if reverse (setq direc (if (eq direc 're-search-forward)
1481 're-search-backward 're-search-forward)))
1482 (if (funcall func string direc) ;label/ref found!
1483 (progn
1484 (if otherwin
1485 (progn
1486 (goto-char p)
1487 (if (one-window-p)
1488 (split-window-calculate-height
1489 YaTeX-default-pop-window-height))
1490 (select-window (get-lru-window))
1491 (switch-to-buffer cb)))
1492 (goto-char (match-beginning 0))
1493 (push-mark p))
1494 ;;if label/ref not found, search through all yatex buffers.
1495 (goto-char p) ;resume position of current buffer
1496 (setq blist (YaTeX-yatex-buffer-list))
1497 (catch 'found
1498 (while blist
1499 (set-buffer (car blist))
1500 (if (YaTeX-on-section-command-p refcommands)
1501 (goto-char (match-beginning 0)))
1502 (if (funcall func string direc)
1503 (progn
1504 (cond
1505 (otherwin
1506 (set-buffer cb)
1507 (goto-char p)
1508 (if (one-window-p)
1509 (split-window-calculate-height
1510 YaTeX-default-pop-window-height))
1511 (select-window (get-lru-window))
1512 (switch-to-buffer (car blist)))
1513 ((or (get-buffer-window (car blist))
1514 (and YaTeX-emacs-19
1515 (get-buffer-window (car blist) t)))
1516 (goto-buffer-window (car blist)))
1517 (t
1518 (switch-to-buffer (car blist))
1519 (message
1520 (format "Type %s %c to return to original position."
1521 (key-description
1522 (car
1523 (or (where-is-internal 'register-to-point)
1524 (where-is-internal 'jump-to-register))))
1525 YaTeX-current-position-register))))
1526 (goto-char (match-beginning 0))
1527 (throw 'found t)))
1528 (setq blist (cdr blist)))))
1530 (if YaTeX-emacs-19
1531 (setq regexp-search-ring
1532 (cons string (delete string regexp-search-ring)))
1533 (setq search-last-regexp string)))
1534 (t nil))))
1536 (defun YaTeX-goto-corresponding-environment (&optional allow-mismatch noerr)
1537 "Go to corresponding begin/end enclosure.
1538 Optional argument ALLOW-MISMATCH allows mismatch open/clese. Use this
1539 for \left(, \right).
1540 Optional third argument NOERR causes no error for unballanced environment."
1541 (interactive)
1542 (if (not (YaTeX-on-begin-end-p)) nil
1543 (let ((p (match-end 0)) b0 b1 env (nest 0) regexp re-s (op (point))
1544 (m0 (match-beginning 0)) ;whole matching
1545 (m1 (match-beginning 1)) ;environment in \begin{}
1546 (m2 (match-beginning 2)) ;environment in \end{}
1547 (m3 (match-beginning 3))) ;environment in \[ \] \( \)
1548 ;(setq env (regexp-quote (buffer-substring p (match-beginning 0))))
1549 (if (cond
1550 (m1 ;if begin{xxx}
1551 (setq env
1552 (if allow-mismatch YaTeX-struct-name-regexp
1553 (regexp-quote (buffer-substring m1 (match-end 1)))))
1554 ; (setq regexp (concat "\\(\\\\end{" env "}\\)\\|"
1555 ; "\\(\\\\begin{" env "}\\)"))
1556 (setq regexp
1557 (concat
1558 "\\("
1559 (YaTeX-replace-format-args
1560 (regexp-quote YaTeX-struct-end) env "" "")
1561 "\\)\\|\\("
1562 (YaTeX-replace-format-args
1563 (regexp-quote YaTeX-struct-begin) env "" "")
1564 "\\)"))
1565 (setq re-s 're-search-forward))
1566 (m2 ;if end{xxx}
1567 (setq env
1568 (if allow-mismatch YaTeX-struct-name-regexp
1569 (regexp-quote (buffer-substring m2 (match-end 2)))))
1570 ; (setq regexp (concat "\\(\\\\begin{" env "}\\)\\|"
1571 ; "\\(\\\\end{" env "}\\)"))
1572 (setq regexp
1573 (concat
1574 "\\("
1575 (YaTeX-replace-format-args
1576 (regexp-quote YaTeX-struct-begin) env "" "")
1577 "\\)\\|\\("
1578 (YaTeX-replace-format-args
1579 (regexp-quote YaTeX-struct-end) env "" "")
1580 "\\)"))
1581 (setq re-s 're-search-backward))
1582 (m3 ;math environment
1583 (setq env (char-after (1+ m3))
1584 regexp (format "\\(%s%s\\)\\|\\(%s%s\\)"
1585 YaTeX-ec-regexp
1586 (regexp-quote
1587 (cdr (assq env '((?( . ")") (?) . "(")
1588 (?[ . "]") (?] . "[")))))
1589 YaTeX-ec-regexp
1590 (regexp-quote (char-to-string env)))
1591 re-s (if (memq env '(?\( ?\[))
1592 're-search-forward
1593 're-search-backward)))
1594 (t (if noerr nil (error "Corresponding environment not found."))))
1595 (progn
1596 (while (and (>= nest 0) (funcall re-s regexp nil t))
1597 (setq b0 (match-beginning 0) b1 (match-beginning 1))
1598 (if (or (equal b0 m0)
1599 (YaTeX-literal-p b0))
1600 nil
1601 (setq nest (if (equal b0 b1)
1602 (1- nest) (1+ nest)))))
1603 (if (< nest 0)
1604 (goto-char (match-beginning 0)) ;found.
1605 (goto-char op)
1606 (funcall
1607 (if noerr 'message 'error)
1608 "Corresponding environment `%s' not found." env)
1609 (sit-for 1)
1610 nil))))))
1612 (defun YaTeX-goto-corresponding-file (&optional other)
1613 "Visit or switch buffer of corresponding file,
1614 looking at \\input or \\include or \includeonly on current line."
1615 (if (not (YaTeX-on-includes-p)) nil
1616 (let ((parent buffer-file-name) input-file b)
1617 (save-excursion
1618 (if (search-forward "{" (point-end-of-line) t)
1619 nil
1620 (skip-chars-backward "^,{"))
1621 (setq input-file
1622 (buffer-substring
1623 (point) (progn (skip-chars-forward "^ ,}") (point))))
1624 (if (not (string-match "\\.\\(tex\\|sty\\)$" input-file))
1625 (setq input-file (concat input-file ".tex"))))
1626 (cond
1627 (other (YaTeX-switch-to-buffer-other-window input-file))
1628 ((setq b (YaTeX-get-file-buffer input-file))
1629 (goto-buffer-window b))
1630 (t (YaTeX-switch-to-buffer input-file)))
1631 (or (YaTeX-get-builtin "!")
1632 YaTeX-parent-file
1633 (setq YaTeX-parent-file parent)))))
1635 (defun YaTeX-goto-corresponding-BEGIN-END ()
1636 (if (not (YaTeX-on-BEGIN-END-p)) nil
1637 (if (cond
1638 ((equal (match-beginning 0) (match-beginning 1)) ;if on %#BEGIN
1639 (not (search-forward "%#END" nil t)))
1640 (t ; if on %#END
1641 (not (search-backward "%#BEGIN" nil t))))
1642 (error "Corresponding %%#BEGIN/END not found."))
1643 (beginning-of-line)
1644 t))
1646 (defvar YaTeX-processed-file-regexp-alist nil
1647 "Alist of regexp of processed file regexp vs. its file name part;
1648 For example, if you include image file with `\\epsfile{file=FILE}' where
1649 `FILE' is processed file. You might want to view FILE with other previewer
1650 such as ghostview, or want to preview its source which was drawn with
1651 other drawing tool, tgif for example. Then you should set entire regexp
1652 of including expression and enclose its file name part with \\\\( and \\\\).
1654 Ex. (\"\\\\\\\\epsfile{[^}]*file=\\\\([^,} ]+\\\\)\\\\(\\\\.e?ps\\\\)?[^}]*}\" 1)
1656 Where the first group surrounded by \\\\( and \\\\) is the file name part
1657 of expression. So you should set 1 to second element. And the first
1658 matching group is sent to (image) processor defined by the variable
1659 YaTeX-file-processor-alist. See also the documentation of
1660 YaTeX-file-processor-alist.
1662 ↑じゃ良くわかんないすね。例えば tgif hoge.obj して hoge.eps を
1663 \\epsfile{file=hoge.eps} でインクルードしているとしよう。その行で
1664 \[prefix\] g を押した時に tgif を起動して欲しかったら、まず上のような
1665 正規表現を設定する。\\\\(と\\\\)で囲んだところがファイル名になるように
1666 注意する。でファイル名部分が何番目の\\\\(\\\\)になるかをリストの2番目に書く。
1667 すると、その部分が変数 YaTeX-file-processor-alist で定義された
1668 処理プログラムに渡される。というわけ。
1669 ん〜やっぱりむずかしいね。分からない時は隣の Lisper に聞くか、
1670 fj野鳥の会で聞こう!
1671 ")
1673 (defvar YaTeX-processed-file-regexp-alist-default
1674 '(("\\\\epsfile\\(\\[[^]]+\\]\\)?{[^},]*file=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1675 ("\\\\epsfig{[^},]*fi\\(le\\|gure\\)=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1676 ("\\\\postscriptbox{[^}]*}{[^}]*}{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 1)
1677 ("\\\\\\(epsfbox\\|includegraphics\\|epsfig\\)\\*?{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 2) ;\epsfbox{hoge.ps} or \includegraphics{hoge.eps}
1678 ("\\\\\\(psbox\\)\\(\\[[^]]+\\]\\)?{\\(\\([^,} ]*/\\)?[^} ]+\\)\\(\\.e?ps\\)}" 3) ;\psbox[options...]{hoge.eps} (97/1/11)
1679 ("\\\\input{\\([^} ]+\\)\\(\\.tps\\)}" 1) ;tgif2tex (1998/9/16)
1681 "See the documentation of YaTeX-processed-file-regexp-alist.")
1683 (defvar YaTeX-file-processor-alist nil
1684 "*Alist of files' processor vs. its extension;
1685 See also the documentation of YaTeX-processed-file-regexp-alist.")
1687 (defvar YaTeX-file-processor-alist-default
1688 '(("tgif" . ".obj")
1689 ("ghostview" . ".ps")
1690 ("ghostview" . ".eps")
1691 (t . ".tex")
1692 (t . ".sty")
1693 (t . ""))
1694 "See the documentation of YaTeX-file-processor-alist.")
1696 (defun YaTeX-goto-corresponding-file-processor (&optional other)
1697 "Execute corresponding file processor."
1698 (save-excursion
1699 (or (looking-at YaTeX-ec-regexp)
1700 (skip-chars-backward (concat "^" YaTeX-ec) (point-beginning-of-line)))
1701 (let ((list (append YaTeX-processed-file-regexp-alist
1702 YaTeX-processed-file-regexp-alist-default))
1703 (p (point)) flist file
1704 (peol (point-end-of-line))
1705 (basedir
1706 (if YaTeX-search-file-from-top-directory
1707 (save-excursion (YaTeX-visit-main t) default-directory)
1708 ".")))
1709 (setq flist (catch 'found
1710 (while list
1711 (goto-char p)
1712 (if (re-search-forward (car (car list)) peol t)
1713 (progn
1714 (setq file (YaTeX-match-string
1715 (car (cdr (car list)))))
1716 (throw 'found (cdr (car list)))))
1717 (setq list (cdr list)))))
1718 (if flist ;if pattern and file name found
1719 (let*((plist (append YaTeX-file-processor-alist
1720 YaTeX-file-processor-alist-default))
1721 (plist0 plist)
1722 ext cmd src buf (alt (car (cdr flist))))
1723 (if (and (re-search-forward
1724 (concat YaTeX-comment-prefix "\\s *\\(.*\\)$") peol t)
1725 (assoc (setq cmd (YaTeX-match-string 1))
1726 YaTeX-file-processor-alist))
1727 (setq src ;if processor is specified
1728 (concat file
1729 (cdr (assoc cmd YaTeX-file-processor-alist))))
1730 (while plist ;if processor is not specified
1731 (setq ext (cdr (car plist)))
1732 (if (and (string< "" (concat file ext))
1733 (file-exists-p
1734 (expand-file-name (concat file ext) basedir)))
1735 (setq cmd (car (car plist))
1736 src (concat file ext) plist nil))
1737 (setq plist (cdr plist)))
1738 (if (and (null src) alt YaTeX-create-file-prefix-g)
1739 (setq cmd alt
1740 src (concat file (cdr (assoc alt plist0))))))
1741 (if src ;if processor and src file found
1742 (let ((default-directory basedir))
1743 (cond
1744 ((stringp cmd)
1745 (let ((buf (concat "* " cmd " " src " *")))
1746 (YaTeX-system (concat cmd " " src) buf)
1747 t))
1748 ((eq t cmd)
1749 (let ((parent buffer-file-name))
1750 (funcall
1751 (cond
1752 (other 'YaTeX-switch-to-buffer-other-window)
1753 ((get-file-buffer src) 'goto-buffer-window)
1754 (t 'YaTeX-switch-to-buffer))
1755 src)
1756 (or (YaTeX-get-builtin "!")
1757 YaTeX-parent-file
1758 (setq YaTeX-parent-file parent))
1759 t))
1760 ((symbolp cmd)
1761 (cond
1762 ((symbol-function cmd)
1763 (funcall cmd src other)))
1764 t)))))))))
1766 (defun YaTeX-on-section-command-p (command)
1767 "Check if point is on the LaTeX command: COMMAND(regexp).
1768 Return nil if point is not on it. Otherwise return the
1769 number of argument position.
1770 Section command name is stored in match-data #1."
1771 (let ((p (point)) md (parg 0) (argc 1) word (grouping 0) (i 0))
1772 (while (setq i (string-match "\\\\(" command i))
1773 (setq grouping (1+ grouping) i (+ i 2)))
1774 (save-excursion
1775 (if (looking-at YaTeX-ec-regexp) nil
1776 (catch 'found ;caught value has no meaning
1777 (while t
1778 (if (bobp) (throw 'found nil))
1779 (cond
1780 ((looking-at YaTeX-ec-regexp) (throw 'found t))
1781 ((looking-at "[[{]") nil)
1782 ((looking-at "[]}]")(condition-case nil (up-list -1) (error nil)))
1783 (t (skip-chars-backward " \t\r\n")))
1784 (skip-chars-backward (concat "^ \t\r\n{}[]" YaTeX-ec-regexp))
1785 (or (bobp) (forward-char -1)))))
1786 (if (and
1787 (looking-at (concat YaTeX-ec-regexp "\\(" command "\\)"
1788 "\\(\\(\\[[^]]+\\]\\)*\\)" ;optional arg
1789 ;"[ \t\n\r]*{[^}]+}")) ;arg braces
1790 "[ \t\n\r]*{[^}]*}")) ;arg braces
1791 (not (YaTeX-lookup-table
1792 (setq word (YaTeX-match-string 1)) 'singlecmd)))
1793 (progn
1794 (setq md (match-data))
1795 (skip-chars-forward "^{")
1796 (if (<= (point) p) (setq parg (1+ parg)))
1797 (setq argc
1798 (or (car (cdr (YaTeX-lookup-table word 'section)))
1799 argc))
1800 (while (and (>= (setq argc (1- argc)) 0)
1801 (progn (skip-chars-forward " \t\n\r")
1802 (looking-at "{")))
1803 (forward-list 1)
1804 (if (<= (point) p) (setq parg (1+ parg))))
1805 (store-match-data md)
1806 (setq i (+ 2 grouping))
1807 (if (and (match-beginning i)
1808 (>= p (match-beginning i)) (< p (match-end i)))
1809 -1 ;return -1 if point is on optional arg
1810 (if (< p (point)) parg))
1811 )))))
1813 (defun YaTeX-on-maketitle-p ()
1814 "Check if point is on maketitle type commands.
1815 Call this function after YaTeX-on-section-command-p."
1816 (let ((p (point)))
1817 (save-excursion
1818 (or (= (char-after (point)) ?\\ )
1819 (progn
1820 (skip-chars-backward
1821 (concat "^" YaTeX-ec-regexp) (point-beginning-of-line))
1822 (or (bobp) (bolp) (backward-char 1))))
1823 (and (looking-at (concat YaTeX-ec-regexp YaTeX-TeX-token-regexp))
1824 (<= (match-beginning 0) p)
1825 (> (match-end 0) p)))))
1827 (defun YaTeX-on-begin-end-p ()
1828 (save-excursion
1829 (beginning-of-line)
1830 (re-search-forward
1831 ;;"\\\\begin{\\([^}]+\\)}\\|\\\\end{\\([^}]+\\)}"
1832 (concat
1833 (YaTeX-replace-format-args
1834 (regexp-quote YaTeX-struct-begin)
1835 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" "")
1836 "\\|"
1837 (YaTeX-replace-format-args
1838 (regexp-quote YaTeX-struct-end)
1839 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" "")
1840 "\\|\\("
1841 YaTeX-ec-regexp ;;"[][()]\\)"
1842 "[][]\\)"
1844 (point-end-of-line) t)))
1846 (defun YaTeX-on-includes-p ()
1847 (save-excursion
1848 (beginning-of-line)
1849 (re-search-forward "\\(\\(include.*\\)\\|\\(input\\)\\){.*}"
1850 (point-end-of-line) t)))
1852 (defun YaTeX-on-comment-p (&optional sw)
1853 "Return t if current line is commented out.
1854 Optional argument SW t to treat all `%' lines as comment,
1855 even if on `%#' notation."
1856 (save-excursion
1857 (beginning-of-line)
1858 (skip-chars-forward "\\s ")
1859 (looking-at (if sw "%" "%[^#]"))))
1861 (defun YaTeX-on-BEGIN-END-p ()
1862 (save-excursion
1863 (let ((case-fold-search nil))
1864 (beginning-of-line)
1865 (re-search-forward
1866 "\\(%#BEGIN\\)\\|\\(%#END\\)" (point-end-of-line) t))))
1868 (defun YaTeX-goto-corresponding-* (arg)
1869 "Parse current line and call suitable function."
1870 (interactive "P")
1871 (cond
1872 ((YaTeX-goto-corresponding-label arg))
1873 ((YaTeX-goto-corresponding-environment))
1874 ((YaTeX-goto-corresponding-file-processor arg))
1875 ((YaTeX-goto-corresponding-file arg))
1876 ((YaTeX-goto-corresponding-BEGIN-END))
1877 ((and (string-match
1878 YaTeX-equation-env-regexp ;to delay loading
1879 (or (YaTeX-inner-environment t) "document"))
1880 (YaTeX-goto-corresponding-leftright)))
1881 (t (message "I don't know where to go."))))
1883 (defun YaTeX-goto-corresponding-*-other-window (arg)
1884 "Parse current line and call suitable function."
1885 (interactive "P")
1886 (cond
1887 ((YaTeX-goto-corresponding-label arg t))
1888 ;;((YaTeX-goto-corresponding-environment))
1889 ((YaTeX-goto-corresponding-file t))
1890 ;;((YaTeX-goto-corresponding-BEGIN-END))
1891 (t (message "I don't know where to go."))))
1893 (defun YaTeX-comment-region (alt-prefix)
1894 "Comment out region by '%'.
1895 If you call this function on the 'begin{}' or 'end{}' line,
1896 it comments out whole environment"
1897 (interactive "P")
1898 (if (not (YaTeX-on-begin-end-p))
1899 (comment-out-region
1900 (if alt-prefix
1901 (read-string "Insert prefix: ")
1902 YaTeX-comment-prefix))
1903 (YaTeX-comment-uncomment-env 'comment-out-region)))
1905 (defun YaTeX-uncomment-region (alt-prefix)
1906 "Uncomment out region by '%'."
1907 (interactive "P")
1908 (if (not (YaTeX-on-begin-end-p))
1909 (uncomment-region
1910 (if alt-prefix (read-string "Remove prefix: ")
1911 YaTeX-comment-prefix)
1912 (region-beginning) (region-end) YaTeX-uncomment-once)
1913 (YaTeX-comment-uncomment-env 'uncomment-region)))
1915 (defun YaTeX-comment-uncomment-env (func)
1916 "Comment or uncomment out one LaTeX environment switching function by FUNC."
1917 (let (beg (p (point)))
1918 (save-excursion
1919 (beginning-of-line)
1920 (setq beg (point))
1921 (YaTeX-goto-corresponding-environment)
1922 (beginning-of-line)
1923 (if (> p (point)) (setq beg (1+ beg)) (forward-char 1))
1924 (funcall func YaTeX-comment-prefix beg (point) YaTeX-uncomment-once)))
1925 (message "%sommented out current environment."
1926 (if (eq func 'comment-out-region) "C" "Un-c")))
1928 (defun YaTeX-comment-paragraph ()
1929 "Comment out current paragraph."
1930 (interactive)
1931 (save-excursion
1932 (cond
1933 ((YaTeX-on-begin-end-p)
1934 (beginning-of-line)
1935 (insert YaTeX-comment-prefix)
1936 (YaTeX-goto-corresponding-environment)
1937 (beginning-of-line)
1938 (insert YaTeX-comment-prefix))
1939 ((YaTeX-on-comment-p)
1940 (message "Already commented out."))
1941 (t
1942 (mark-paragraph)
1943 (if (looking-at paragraph-separate) (forward-line 1))
1944 (comment-out-region "%")))))
1946 (defun YaTeX-uncomment-paragraph ()
1947 "Uncomment current paragraph."
1948 (interactive)
1949 (save-excursion
1950 (if (YaTeX-on-begin-end-p)
1951 (let ((p (point-marker)))
1952 (YaTeX-goto-corresponding-environment)
1953 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once)
1954 (goto-char p)
1955 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once)
1956 (set-marker p nil))
1957 (if (YaTeX-on-comment-p)
1958 (let*((fill-prefix "")
1959 ;;append `^%' to head of paragraph delimiter.
1960 (paragraph-start
1961 (concat
1962 "^$\\|^%\\(" YaTeX-paragraph-separate "\\)"))
1963 (paragraph-separate paragraph-start))
1964 (mark-paragraph)
1965 (if (not (bobp)) (forward-line 1))
1966 (uncomment-region "%" nil nil YaTeX-uncomment-once))
1967 (message "This line is not a comment line.")))))
1969 (defun YaTeX-remove-prefix (prefix &optional once)
1970 "Remove prefix on current line as far as prefix detected. But
1971 optional argument ONCE makes deletion once."
1972 (interactive "sPrefix:")
1973 (beginning-of-line)
1974 (while (re-search-forward (concat "^" prefix) (point-end-of-line) t)
1975 (replace-match "")
1976 (if once (end-of-line))))
1978 (defun YaTeX-kill-some-pairs (predicate gofunc kill-contents)
1979 "Kill some matching pair.
1980 This function assumes that pairs occupy whole of each line where they resid."
1981 (if (not (funcall predicate)) nil
1982 (let ((b1 (match-beginning 0)) (e1 (match-end 0))
1983 b2 e2)
1984 (save-excursion
1985 (funcall gofunc)
1986 (funcall predicate) ;get match data
1987 (if (< (point) e1) ;if currently on begin-line
1988 (progn
1989 (setq b2 b1 e2 e1
1990 b1 (match-beginning 0) e1 (match-end 0))
1991 (goto-char e2)) ;goto end-line's end
1992 (setq b2 (match-beginning 0)
1993 e2 (match-end 0))
1994 (goto-char e2)) ;now e2 has surely end-line's end
1995 (skip-chars-forward " \t")
1996 (and (eolp)
1997 (not (eobp))
1998 (setq e2 (1+ (point))))
1999 (if (not kill-contents)
2000 (kill-region
2001 (progn
2002 (goto-char b2)
2003 (skip-chars-backward " \t%")
2004 (if (bolp) (point) b2))
2005 e2))
2006 (goto-char b1)
2007 (skip-chars-backward " \t%")
2008 (if (not kill-contents)
2009 (progn
2010 (kill-append
2011 (buffer-substring
2012 (setq b1 (if (bolp) (point) b1))
2013 (setq e1
2014 (progn
2015 (goto-char e1)
2016 (while (looking-at "{\\| \t")
2017 (forward-list 1))
2018 (skip-chars-forward " \t")
2019 (if (and (eolp) (not (eobp)))
2020 (1+ (point))
2021 (point)))))
2022 t)
2023 (delete-region b1 e1))
2024 (kill-region
2025 (if (bolp) (point) b1)
2026 e2)))
2027 t)))
2029 (defun YaTeX-kill-section-command (point kill-all)
2030 "Kill section-type command at POINT leaving its argument.
2031 Non-nil for the second argument kill its argument too."
2032 (let (beg (end (make-marker)))
2033 (save-excursion
2034 (goto-char point)
2035 (or (looking-at YaTeX-ec-regexp)
2036 (progn
2037 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
2038 (forward-char -1)))
2039 (setq beg (point))
2040 (skip-chars-forward "^{")
2041 (forward-list 1)
2042 (set-marker end (point))
2043 (if kill-all (kill-region beg end)
2044 (goto-char beg)
2045 (kill-region
2046 (point) (progn (skip-chars-forward "^{" end) (1+ (point))))
2047 (goto-char end)
2048 (set-marker end nil)
2049 (kill-append (buffer-substring (point) (1- (point))) nil)
2050 (delete-backward-char 1)))))
2052 (defun YaTeX-kill-paren (kill-contents)
2053 "Kill parentheses leaving its contents.
2054 But kill its contents if the argument KILL-CONTENTS is non-nil."
2055 (save-excursion
2056 (let (p)
2057 (if (looking-at "\\s(\\|\\(\\s)\\)")
2058 (progn
2059 (if (match-beginning 1)
2060 (up-list -1))
2061 (setq p (point))
2062 (forward-list 1)
2063 (if kill-contents (delete-region p (point))
2064 (backward-delete-char 1)
2065 (goto-char p)
2066 (if (looking-at
2067 (concat "{" YaTeX-ec-regexp
2068 YaTeX-command-token-regexp "+"
2069 "\\s +"))
2070 (delete-region
2071 (point)
2072 (progn (re-search-forward "\\s +" nil t) (point)))
2073 (delete-char 1)))
2074 t)))))
2076 (defvar YaTeX-read-environment-history nil "Holds history of environments.")
2077 (put 'YaTeX-read-environment-history 'no-default t)
2078 (defun YaTeX-read-environment (prompt &optional predicate must-match initial)
2079 "Read a LaTeX environment name with completion."
2080 (YaTeX-sync-local-table 'tmp-env-table)
2081 (completing-read-with-history
2082 prompt
2083 (append tmp-env-table user-env-table env-table)
2084 predicate must-match initial
2085 'YaTeX-read-environment-history))
2087 (defvar YaTeX-read-section-history nil "Holds history of section-types.")
2088 (put 'YaTeX-read-section-history 'no-default t)
2089 (defun YaTeX-read-section (prompt &optional predicate initial)
2090 "Read a LaTeX section-type command with completion."
2091 (YaTeX-sync-local-table 'tmp-section-table)
2092 (let ((minibuffer-completion-table
2093 (append tmp-section-table user-section-table section-table)))
2094 (read-from-minibuffer-with-history
2095 prompt initial YaTeX-section-completion-map nil
2096 'YaTeX-read-section-history)))
2098 (defun YaTeX-read-section-with-overview ()
2099 "Read sectioning command with overview.
2100 This function refers a local variable `source-window' in YaTeX-make-section"
2101 (interactive)
2102 (require 'yatexsec) ;some case needs this
2103 (if (> (minibuffer-depth) 1)
2104 (error "Too many minibuffer levels for overview."))
2105 (let ((sw (selected-window))
2106 (minibuffer-max-depth nil) ; for XEmacs20
2107 (enable-recursive-minibuffers t) sect)
2108 (unwind-protect
2109 (progn
2110 (select-window source-window)
2111 (setq sect (YaTeX-read-section-in-minibuffer
2112 "Sectioning(Up=C-p, Down=C-n, Help=?): "
2113 YaTeX-sectioning-level (YaTeX-section-overview))))
2114 (select-window sw))
2115 (YaTeX-minibuffer-erase)
2116 (insert sect)
2117 (exit-minibuffer)))
2119 (defvar YaTeX-read-fontsize-history nil "Holds history of font designator.")
2120 (put 'YaTeX-read-fontsize-history 'no-default t)
2121 (defun YaTeX-read-fontsize (prompt &optional predicate must-match initial)
2122 "Read a LaTeX font changing command with completion."
2123 (YaTeX-sync-local-table 'tmp-fontsize-table)
2124 (completing-read-with-history
2125 prompt (append tmp-fontsize-table user-fontsize-table fontsize-table)
2126 predicate must-match initial 'YaTeX-read-fontsize-history))
2128 (defun YaTeX-change-environment ()
2129 "Change the name of environment."
2130 (interactive)
2131 (if (not (YaTeX-on-begin-end-p)) nil
2132 (save-excursion
2133 (let (p env (m1 (match-beginning 1)) (m2 (match-beginning 2)))
2134 (setq env (if m1 (buffer-substring m1 (match-end 1))
2135 (buffer-substring m2 (match-end 2))))
2136 (goto-char (match-beginning 0))
2137 (set-mark-command nil)
2138 (YaTeX-goto-corresponding-environment)
2139 (setq newenv (YaTeX-read-environment
2140 (format "Change environment `%s' to: " env)))
2141 (cond
2142 ((string= newenv "") (message "Change environment cancelled."))
2143 ((string= newenv env) (message "No need to change."))
2144 (t
2145 (search-forward (concat "{" env) (point-end-of-line) t)
2146 (replace-match (concat "{" newenv) t)
2147 (exchange-point-and-mark)
2148 (search-forward (concat "{" env) (point-end-of-line) t)
2149 (replace-match (concat "{" newenv) t)))
2150 t))))
2152 (defun YaTeX-change-section ()
2153 "Change section-type command."
2154 (interactive)
2155 (let*((where (YaTeX-on-section-command-p YaTeX-command-token-regexp))
2156 (p (point)) (cmd (YaTeX-match-string 1))
2157 (beg (make-marker)) (end (make-marker)) old new)
2158 (if (null where) nil
2159 (unwind-protect
2160 (progn
2161 (cond
2162 ((equal where 0);;if point is on section command
2163 (set-marker beg (match-beginning 1))
2164 (set-marker end (match-end 1))
2165 (goto-char beg) ;beginning of the command
2166 (setq new (YaTeX-read-section
2167 (format "Change `%s' to: " cmd) nil)))
2169 ((= where -1);;if point is on a optional parameter
2170 (set-marker beg (match-beginning 2))
2171 (skip-chars-forward "^{")
2172 (set-marker end (point))
2173 (goto-char p)
2174 (setq new
2175 (if (fboundp (intern-soft (concat YaTeX-addin-prefix cmd)))
2176 (YaTeX-addin cmd)
2177 (concat "["
2178 (read-string (format "Change `%s' to: "
2179 (buffer-substring
2180 (1+ beg) (1- end))))
2181 "]"))))
2183 ((> where 0);;if point is in arguments' braces
2184 (or (looking-at "{")
2185 (progn (skip-chars-backward "^{") (forward-char -1)))
2186 (set-marker beg (1+ (point)))
2187 (forward-list 1)
2188 (forward-char -1)
2189 (set-marker end (point))
2190 (setq old (buffer-substring beg end))
2191 (goto-char p)
2192 (if (> (length old) 40)
2193 (setq old (concat (substring old 0 12) "..."
2194 (substring old -12))))
2195 (setq new
2196 (if (intern-soft (concat "YaTeX::" cmd))
2197 (funcall (intern-soft (concat "YaTeX::" cmd)) where)
2198 (read-string (format "Change `%s' to: " old)))))
2199 ) ;cond
2200 (delete-region beg end)
2201 (goto-char beg)
2202 (insert-before-markers new))
2203 (set-marker beg nil)
2204 (set-marker end nil))
2205 ;;(goto-char (marker-position p))
2206 new)))
2208 (defun YaTeX-change-fontsize ()
2209 "Change large-type command."
2210 (let ((lt (append tmp-fontsize-table user-fontsize-table fontsize-table))
2211 (p (point)) large old new beg end)
2212 ;;(and (looking-at "}") (up-list -1))
2213 ;;(and (looking-at "{") (forward-char 1))
2214 ;;Is above convenient?
2215 (save-excursion
2216 (or (looking-at YaTeX-ec-regexp)
2217 (progn
2218 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
2219 (forward-char -1)))
2220 (cond
2221 ((and
2222 (looking-at
2223 (concat YaTeX-ec-regexp "\\(" YaTeX-TeX-token-regexp "\\)"))
2224 (< p (match-end 0))
2225 (assoc (setq old (YaTeX-match-string 1)) lt))
2226 (goto-char p)
2227 (setq beg (match-beginning 1) end (match-end 1) ;save match position
2228 new (completing-read
2229 (format "Change font/size `%s' to : " old) lt))
2230 (delete-region beg end)
2231 (goto-char beg)
2232 (insert-before-markers new)
2233 new)
2234 (t nil)
2235 ))))
2237 (defun YaTeX-change-math-image ()
2238 "Change with image completion."
2239 (let (maketitle memberp beg end)
2240 (if (and (YaTeX-on-maketitle-p)
2241 (progn
2242 (setq maketitle (substring (YaTeX-match-string 0) 1))
2243 (setq memberp (YaTeX-math-member-p maketitle))))
2244 (let ((last-command-char (string-to-char (car memberp))))
2245 (setq beg (match-beginning 0) end (match-end 0))
2246 (delete-region beg end)
2247 (YaTeX-math-insert-sequence t (cdr memberp))))))
2249 (defun YaTeX-kill-* (&optional arg)
2250 "Parse current line and call suitable function.
2251 Non-nil for ARG kills its contents too."
2252 (interactive "P")
2253 (cond
2254 ((YaTeX-kill-some-pairs 'YaTeX-on-begin-end-p
2255 'YaTeX-goto-corresponding-environment arg))
2256 ((YaTeX-kill-some-pairs 'YaTeX-on-BEGIN-END-p
2257 'YaTeX-goto-corresponding-BEGIN-END arg))
2258 ((YaTeX-on-section-command-p YaTeX-command-token-regexp);on any command
2259 (YaTeX-kill-section-command (match-beginning 0) arg))
2260 ((YaTeX-kill-paren arg))
2261 (t (message "I don't know what to kill."))))
2263 (defun YaTeX-change-* ()
2264 "Parse current line and call suitable function."
2265 (interactive)
2266 (cond
2267 ((YaTeX-change-environment))
2268 ((YaTeX-change-section))
2269 ((YaTeX-change-fontsize))
2270 ((YaTeX-change-math-image))
2271 ((YaTeX-change-parentheses))
2272 (t (message "I don't know what to change."))))
2274 ;;;
2275 ;Check availability of add-in functions
2276 ;;;
2277 (cond
2278 ((featurep 'yatexadd) nil) ;Already provided.
2279 ((progn (load "yatexadd" t) (featurep 'yatexadd)) nil)
2280 (t (message "YaTeX add-in functions not supplied.")))
2282 (defun YaTeX-addin (name)
2283 "Check availability of addin function and call it if exists."
2284 (if (and (not (get 'YaTeX-generate 'disabled))
2285 (intern-soft (concat YaTeX-addin-prefix name))
2286 (fboundp (intern-soft (concat YaTeX-addin-prefix name))))
2287 (let ((s (funcall (intern (concat YaTeX-addin-prefix name)))))
2288 (if (stringp s) s ""))
2289 "")) ;Add in function is not bound.
2292 (defun YaTeX-on-item-p (&optional point)
2293 "Return t if POINT (default is (point)) is on \\item."
2294 (let ((p (or point (point))))
2295 (save-excursion
2296 (goto-char p)
2297 (end-of-line)
2298 (setq p (point))
2299 (re-search-backward YaTeX-paragraph-delimiter nil t)
2300 (re-search-forward YaTeX-item-regexp p t))))
2302 (defun YaTeX-in-verb-p (&optional point)
2303 "Check if POINT is in verb or verb*. Default of POINT is (point)."
2304 (setq point (or point (point)))
2305 (save-excursion
2306 (let ((md (match-data)))
2307 (goto-char point)
2308 (unwind-protect
2309 (if (not (re-search-backward
2310 (concat YaTeX-ec-regexp
2311 "\\(" YaTeX-verb-regexp "\\)"
2312 "\\([^-A-Za-z_*]\\)")
2313 (point-beginning-of-line) t))
2314 nil
2315 (goto-char (match-end 2))
2316 (skip-chars-forward
2317 (concat "^" (buffer-substring (match-beginning 2) (match-end 2))))
2318 (and (< (match-beginning 2) point) (< (1- point) (point))))
2319 (store-match-data md)))))
2321 (defun YaTeX-literal-p (&optional point)
2322 "Check if POINT is in verb or verb* or verbatime environment family.
2323 Default of POINT is (point)."
2324 (let ((md (match-data)))
2325 (unwind-protect
2326 (cond
2327 ((equal YaTeX-ec "\\") ;maybe LaTeX
2328 (save-excursion
2329 (and point (goto-char point))
2330 (or (YaTeX-in-verb-p (point))
2331 (and (not (looking-at "\\\\end{verb"))
2332 (YaTeX-quick-in-environment-p
2333 YaTeX-verbatim-environments))))))
2334 (store-match-data md))))
2336 (defun YaTeX-in-environment-p (env)
2337 "Return if current LaTeX environment is ENV.
2338 ENV is given in the form of environment's name or its list."
2339 (let ((md (match-data)) (nest 0) p envrx)
2340 (cond
2341 ((atom env)
2342 (setq envrx
2343 (concat "\\("
2344 (regexp-quote
2345 (YaTeX-replace-format-args
2346 YaTeX-struct-begin env "" ""))
2347 "\\)\\|\\("
2348 (regexp-quote
2349 (YaTeX-replace-format-args
2350 YaTeX-struct-end env "" ""))
2351 "\\)"))
2352 (save-excursion
2353 (setq p (catch 'open
2354 (while (YaTeX-re-search-active-backward
2355 envrx YaTeX-comment-prefix nil t)
2356 (if (match-beginning 2)
2357 (setq nest (1+ nest))
2358 (setq nest (1- nest)))
2359 (if (< nest 0) (throw 'open t)))))))
2360 ((listp env)
2361 (setq p
2362 (or (YaTeX-in-environment-p (car env))
2363 (and (cdr env) (YaTeX-in-environment-p (cdr env)))))))
2364 (store-match-data md)
2365 p;(or p (YaTeX-in-verb-p (match-beginning 0)))
2366 ))
2368 (defun YaTeX-quick-in-environment-p (env)
2369 "Check quickly but unsure if current environment is ENV.
2370 ENV is given in the form of environment's name or its list.
2371 This function returns correct result only if ENV is NOT nested."
2372 (save-excursion
2373 (let ((md (match-data)) (p (point)) rc clfound)
2374 (cond
2375 ((listp env)
2376 (or (YaTeX-quick-in-environment-p (car env))
2377 (and (cdr env) (YaTeX-quick-in-environment-p (cdr env)))))
2378 (t
2379 (if (YaTeX-search-active-backward
2380 (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
2381 YaTeX-comment-prefix nil t)
2382 (setq rc (not (YaTeX-search-active-forward
2383 (YaTeX-replace-format-args
2384 YaTeX-struct-end env)
2385 YaTeX-comment-prefix p t nil))))
2386 (store-match-data md)
2387 rc)))))
2389 ;; Filling \item
2390 (defun YaTeX-remove-trailing-comment (start end)
2391 "Remove trailing comment from START to end."
2392 (save-excursion
2393 (let ((trcom (concat YaTeX-comment-prefix "$")))
2394 (goto-char start)
2395 (while (re-search-forward trcom end t)
2396 (if (/= (char-after (1- (match-beginning 0))) ?\\ )
2397 (replace-match "\\1"))))))
2399 (defun YaTeX-get-item-info (&optional recent thisenv)
2400 "Return the list of the beginning of \\item and column of its item.
2401 If it seems to be outside of itemizing environment, just return nil.
2402 Non-nil for optional argument RECENT refers recent \\item.
2403 Optional second argument THISENV omits calling YaTeX-inner-environment."
2404 (save-excursion
2405 (let* ((p (point)) env e0 c
2406 (bndry (and (setq env (or thisenv (YaTeX-inner-environment t)))
2407 (get 'YaTeX-inner-environment 'point)
2408 )))
2409 (end-of-line)
2410 (if (if recent
2411 (YaTeX-re-search-active-backward
2412 YaTeX-item-regexp YaTeX-comment-prefix bndry t)
2413 (goto-char bndry)
2414 (YaTeX-re-search-active-forward
2415 YaTeX-item-regexp YaTeX-comment-prefix p t))
2416 (progn
2417 (goto-char (match-end 0))
2418 ;(setq c (current-column))
2419 (if (string-match "desc" env)
2420 (setq c 6)
2421 (if (equal (following-char) ?\[) (forward-list 1))
2422 (setq c 0))
2423 (skip-chars-forward " \t" (point-end-of-line))
2424 (list (point-beginning-of-line) (+ c (current-column))))))))
2426 (defun YaTeX-fill-item ()
2427 "Fill item in itemize environment."
2428 (interactive)
2429 (save-excursion
2430 (let* ((p (point))
2431 (item-term (concat
2432 "\\(^[ \t]*$\\)\\|" YaTeX-item-regexp "\\|\\("
2433 YaTeX-ec-regexp "\\(begin\\|end\\)\\)"))
2434 ;;This value depends on LaTeX.
2435 fill-prefix start col
2436 (info (YaTeX-get-item-info t)))
2437 (if (null info) nil ;not on \item, do nothing
2438 (setq start (car info)
2439 col (car (cdr info)))
2440 (save-excursion
2441 (if (re-search-backward "^\\s *$" start t)
2442 ;;if separated from \item line, isolate this block
2443 (progn
2444 (setq start (1+ (match-end 0)))
2445 (goto-char start)
2446 (skip-chars-forward " \t")
2447 (delete-region (point) start) ;is this your favor???
2448 (indent-to col))))
2449 (beginning-of-line)
2450 (if (<= (save-excursion
2451 (re-search-forward
2452 (concat "\\\\end{\\|\\\\begin{\\|^[ \t]*$") nil t)
2453 (match-beginning 0))
2454 p)
2455 (progn (message "Not on itemize.") nil)
2456 (end-of-line)
2457 (newline)
2458 (indent-to col)
2459 (setq fill-prefix
2460 (buffer-substring (point-beginning-of-line)(point)))
2461 (beginning-of-line)
2462 (delete-region (point) (progn (forward-line 1) (point)))
2463 (re-search-forward item-term nil 1)
2464 (YaTeX-remove-trailing-comment start (point))
2465 (beginning-of-line)
2466 (push-mark (point) t)
2467 (goto-char start)
2468 (forward-line 1)
2469 (while (< (point) (mark))
2470 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
2471 (forward-line 1))
2472 (fill-region-as-paragraph start (mark))
2473 (if NTT-jTeX
2474 (while (progn(forward-line -1)(end-of-line) (> (point) start))
2475 (insert ?%)))
2476 (pop-mark))))))
2478 (defun YaTeX-fill-paragraph (arg)
2479 "YaTeX adjustment function for fill-paragraph.
2480 *Protect \\verb from unexpected broken up."
2481 (interactive "P")
2482 (cond
2483 ((not (eq major-mode 'yatex-mode)) (fill-paragraph arg))
2484 ((YaTeX-quick-in-environment-p YaTeX-fill-inhibit-environments) nil)
2485 ((YaTeX-in-math-mode-p) nil)
2486 (t
2487 (save-excursion
2488 (let ((verbrex (concat YaTeX-ec-regexp
2489 "\\(" YaTeX-verb-regexp "\\)" ;match#1
2490 "\\(.\\).*\\(\\2\\)")) ;match #2 and #3
2491 (p (point)) ii end poslist spacelist (fill-prefix fill-prefix))
2492 (cond
2493 ((save-excursion (beginning-of-line) ;if point is on the first
2494 (setq end (point)) ;non-whitespace char
2495 (skip-chars-forward " \t")
2496 (equal (point) p))
2497 (setq fill-prefix (buffer-substring p end)))
2498 ((and ;;(not YaTeX-emacs-19)
2499 (string-match YaTeX-itemizing-env-regexp
2500 (or (YaTeX-inner-environment t) "document"))
2501 (setq ii (YaTeX-get-item-info)))
2502 (save-excursion
2503 (beginning-of-line)
2504 (indent-to-column (car (cdr ii)))
2505 (setq fill-prefix
2506 (buffer-substring (point) (point-beginning-of-line)))
2507 (delete-region (point) (progn (beginning-of-line) (point))))))
2508 (mark-paragraph)
2509 (save-restriction
2510 (narrow-to-region (region-beginning) (region-end))
2511 (YaTeX-remove-trailing-comment (point-min) (point-max))
2512 (goto-char (point-min))
2513 (while (YaTeX-re-search-active-forward
2514 verbrex YaTeX-comment-prefix (point-max) t)
2515 (setq end (match-beginning 3))
2516 (goto-char (match-beginning 2))
2517 (while (re-search-forward "\\s " end t)
2518 (setq poslist (cons (make-marker) poslist)
2519 spacelist (cons (preceding-char) spacelist))
2520 (replace-match "_")
2521 (set-marker (car poslist) (match-beginning 0))))
2522 ;;(fill-paragraph arg)
2523 (fill-region-as-paragraph (point-min) (point-max) arg)
2524 (while spacelist
2525 (goto-char (car poslist))
2526 (set-marker (car poslist) nil)
2527 (delete-char 1)
2528 (insert (car spacelist))
2529 (setq spacelist (cdr spacelist) poslist (cdr poslist)))
2530 (goto-char (point-min))
2531 (forward-word 1)
2532 (beginning-of-line)
2533 (while (re-search-forward "\\\\\\(\\(page\\)?ref\\|cite\\){" nil t)
2534 (if (< (point-end-of-line)
2535 (save-excursion (forward-char -1) (forward-list 1) (point)))
2536 (progn (end-of-line) (insert YaTeX-comment-prefix))))
2537 (goto-char (point-min))
2538 (if (and NTT-jTeX (looking-at "[ \t]"))
2539 (progn
2540 (goto-char (point-min))
2541 (while (not (eobp))
2542 (end-of-line)
2543 (or (bolp)
2544 (save-excursion
2545 (backward-word 1)
2546 (looking-at "\\sw+")) ;is not japanese string
2547 (progn (setq p (point)) (insert YaTeX-comment-prefix)))
2548 (forward-line 1))
2549 (goto-char p)
2550 (if (looking-at "%") (delete-char 1)) ;remove last inserted `%'
2551 ))))))))
2553 (if (fboundp 'YaTeX-saved-indent-new-comment-line) nil
2554 (fset 'YaTeX-saved-indent-new-comment-line
2555 (symbol-function 'indent-new-comment-line))
2556 (fset 'indent-new-comment-line 'YaTeX-indent-new-comment-line))
2558 (defun YaTeX-indent-new-comment-line (&optional soft)
2559 "Tuned `indent-new-comment-line' function for yatex.
2560 See the documentation of `YaTeX-saved-indent-new-comment-line'."
2561 (interactive)
2562 (cond
2563 ((or (not (memq major-mode '(yatex-mode yahtml-mode)))
2564 (string-match
2565 "document"
2566 (or (and (boundp 'inenv) inenv)
2567 (or (YaTeX-inner-environment t) "document"))))
2568 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft))))
2569 ; ((and (eq major-mode 'yahtml-mode)
2570 ; (string-match
2571 ; "^[Pp][Rr][Ee]" (yahtml-inner-environment-but "^[Aa]\\b" t)))
2572 ; (yahtml-indent-new-commnet-line))
2573 ((and (eq major-mode 'yatex-mode) ;1997/2/4
2574 (YaTeX-in-math-mode-p)) nil) ;1996/12/30
2575 (t (let (fill-prefix)
2576 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft)))))))
2578 (defun YaTeX-fill-* ()
2579 "Fill paragraph according to its condition."
2580 (interactive)
2581 (cond
2582 ((YaTeX-fill-item))
2583 ))
2585 ;; Accent completion
2586 (defun YaTeX-read-accent-char (x)
2587 "Read char in accent braces."
2588 (let ((c (read-char)))
2589 (concat
2590 (if (and (or (= c ?i) (= c ?j))
2591 (not (string-match (regexp-quote x) "cdb")))
2592 "\\" "")
2593 (char-to-string c))))
2595 (defun YaTeX-make-accent ()
2596 "Make accent usage."
2597 (interactive)
2598 (message "1:` 2:' 3:^ 4:\" 5:~ 6:= 7:. u v H t c d b")
2599 (let ((c (read-char))(case-fold-search nil))
2600 (setq c (cond ((and (> c ?0) (< c ?8))
2601 (substring "`'^\"~=." (1- (- c ?0)) (- c ?0)))
2602 ((= c ?h) "H")
2603 (t (char-to-string c))))
2604 (if (not (string-match c "`'^\"~=.uvHtcdb")) nil
2605 (insert "\\" c "{}")
2606 (backward-char 1)
2607 (insert (YaTeX-read-accent-char c))
2608 (if (string= c "t") (insert (YaTeX-read-accent-char c)))
2609 (forward-char 1))))
2611 ;; Indentation
2612 (defun YaTeX-current-indentation ()
2613 "Return the indentation of current environment."
2614 (save-excursion
2615 ;;(beginning-of-line)
2616 (if (YaTeX-beginning-of-environment t)
2617 (goto-char (get 'YaTeX-inner-environment 'point))
2618 (forward-line -1)
2619 (beginning-of-line)
2620 (skip-chars-forward " \t"))
2621 (current-column)))
2623 (defun YaTeX-previous-line-indentation ()
2624 (save-excursion
2625 (forward-line -1)
2626 (skip-chars-forward " \t")
2627 (current-column)))
2629 (defun YaTeX-indent-line ()
2630 "Indent corrent line referrin current environment."
2631 (interactive)
2632 (let ((indent-relative
2633 (function
2634 (lambda (&optional additional)
2635 (YaTeX-reindent
2636 (+ (YaTeX-current-indentation)
2637 (or additional 0)
2638 YaTeX-environment-indent)))))
2639 sect depth iteminfo (p (point)) pp (peol (point-end-of-line))
2640 ;;inenv below is sometimes defined in YaTeX-indent-new-comment-line
2641 (inenv (or (and (boundp 'inenv) inenv) (YaTeX-inner-environment t))))
2642 ;;(if NTT-jTeX ;;Do you need this section?
2643 ;; (save-excursion
2644 ;; (end-of-line)
2645 ;; (let ((p (point)))
2646 ;; (forward-line -1)
2647 ;; (end-of-line)
2648 ;; (or (= p (point))
2649 ;; (progn (backward-char (length YaTeX-comment-prefix))
2650 ;; (not (looking-at (regexp-quote YaTeX-comment-prefix))))
2651 ;; (progn
2652 ;; (skip-chars-backward YaTeX-comment-prefix)
2653 ;; (kill-line))))))
2654 (or inenv (setq inenv "document")) ;is the default environment
2655 (cond
2656 ((and (YaTeX-on-begin-end-p)
2657 (or
2658 (match-beginning 2) ;if \end
2659 (and (match-beginning 3) ;if \) \]
2660 (= (char-syntax (char-after (1+ (match-beginning 3)))) ?\)))))
2661 (YaTeX-reindent
2662 (save-excursion
2663 (YaTeX-goto-corresponding-environment)
2664 (current-column))))
2665 ((string-match YaTeX-equation-env-regexp inenv)
2666 (YaTeX-indent-line-equation)) ;autoload-ed from yatexenv
2667 (;(YaTeX-in-environment-p '("itemize" "enumerate" "description" "list"))
2668 (string-match YaTeX-itemizing-env-regexp inenv)
2669 ;;(YaTeX-on-item-p) ??
2670 ;;(setq iteminfo (YaTeX-get-item-info t))
2671 (if (save-excursion
2672 (beginning-of-line)
2673 (re-search-forward YaTeX-item-regexp peol t))
2674 (progn
2675 (save-excursion
2676 (goto-char (1+ (match-beginning 0)))
2677 (setq depth
2678 (* YaTeX-environment-indent
2679 (cond
2680 ((looking-at "subsubsub") 3)
2681 ((looking-at "subsub") 2)
2682 ((looking-at "sub") 1)
2683 (t 0)))))
2684 (funcall indent-relative depth))
2685 (YaTeX-reindent (or (car (cdr (YaTeX-get-item-info nil inenv)))
2686 (+ (save-excursion
2687 (beginning-of-line)
2688 (YaTeX-current-indentation))
2689 YaTeX-environment-indent))))
2691 ((YaTeX-literal-p) ;verbatims
2692 (tab-to-tab-stop))
2693 ((and inenv (not (equal "document" inenv)))
2694 (funcall indent-relative))
2695 ((YaTeX-on-section-command-p YaTeX-sectioning-regexp)
2696 (require 'yatexsec) ;to know YaTeX-sectioning-level
2697 (setq sect (YaTeX-match-string 1))
2698 (if (string-match "\\*$" sect)
2699 (setq sect (substring sect 0 -1)))
2700 (YaTeX-reindent
2701 (* (max
2702 (1- ;I want chapter to have indentation 0
2703 (or (cdr (assoc sect YaTeX-sectioning-level))
2704 0))
2705 0)
2706 YaTeX-environment-indent)))
2707 ;;Default movement
2708 ((and (bolp) fill-prefix) (insert fill-prefix))
2709 (t (save-excursion
2710 (beginning-of-line)
2711 (if fill-prefix
2712 (progn
2713 (delete-region (point)
2714 (progn (skip-chars-forward " \t")
2715 (point)))
2716 (insert fill-prefix))
2717 (skip-chars-forward " \t")
2718 (indent-relative-maybe)))
2719 (skip-chars-forward " \t")))
2720 ;;if current line is \begin, re-indent \end too
2721 (if (and (YaTeX-on-begin-end-p) (match-beginning 1))
2722 (save-excursion
2723 ;;(beginning-of-line)
2724 ;;(search-forward "\\begin")
2725 (goto-char (match-beginning 0))
2726 (setq depth (current-column))
2727 (YaTeX-goto-corresponding-environment)
2728 (YaTeX-reindent depth)))
2729 (if (or
2730 (and NTT-jTeX
2731 (save-excursion (beginning-of-line) (looking-at "[ \t]")))
2732 (save-excursion
2733 (beginning-of-line)
2734 (backward-char 1)
2735 (and
2736 (re-search-backward
2737 "\\\\\\(\\(page\\)?ref\\|cite\\){" (point-beginning-of-line) t)
2738 (goto-char (1- (match-end 0)))
2739 (> (save-excursion
2740 (condition-case ()
2741 (progn (forward-list 1) (point))
2742 (error (point-max))))
2743 (point-end-of-line)))))
2744 (save-excursion
2745 (end-of-line)
2746 (let ((p (point)))
2747 (forward-line -1)
2748 (end-of-line)
2749 (or (= p (point))
2750 (looking-at (regexp-quote YaTeX-comment-prefix))
2751 (bobp) (bolp)
2752 (save-excursion
2753 (backward-word 1)
2754 (looking-at "\\sw+")) ;is not japanese string
2755 (insert YaTeX-comment-prefix)))))))
2757 (defun YaTeX-latex2e-p ()
2758 (let ((b (current-buffer))
2759 (ptn (concat YaTeX-ec "documentclass")))
2760 (unwind-protect
2761 (or (save-excursion (search-backward ptn nil t))
2762 (progn
2763 (YaTeX-visit-main t)
2764 (save-excursion (search-backward ptn nil t))))
2765 (set-buffer b))))
2767 (provide 'yatex)
2768 (defvar yatex-mode-load-hook nil
2769 "*List of functions to be called when yatex.el is loaded.")
2770 (if (and YaTeX-emacs-19 YaTeX-display-color-p (not (featurep 'yatex19)))
2771 (load "yatex19"))
2772 (load "yatexhks" t)
2774 ;;-------------------- Final hook jobs --------------------
2775 (substitute-all-key-definition
2776 'fill-paragraph 'YaTeX-fill-paragraph YaTeX-mode-map)
2777 (substitute-all-key-definition
2778 'kill-buffer 'YaTeX-kill-buffer yahtml-mode-map)
2779 (run-hooks 'yatex-mode-load-hook)
2781 ;; `History' was moved to ChangeLog
2782 ;----------------------------- End of yatex.el -----------------------------
2785 ;;; Local variables:
2786 ;;; buffer-file-coding-system: sjis
2787 ;;; End: