yatex

view yatex.el @ 70:44e3a5e1e883

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