yatex

view yatex.el @ 77:1b172d26b55e

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