yatex

view yatex.el @ 197:3842e55025aa

Note on { after \begin.
author yuuji@gentei.org
date Tue, 10 Jan 2012 14:12:51 +0900
parents 701d87b607e0
children 768ff443ef84
line source
1 ;;; -*- Emacs-Lisp -*-
2 ;;; Yet Another tex-mode for emacs - //野鳥//
3 ;;; yatex.el rev. 1.74.7
4 ;;; (c)1991-2012 by HIROSE Yuuji.[yuuji@yatex.org]
5 ;;; Last modified Tue Jan 10 13:27:32 2012 on firestorm
6 ;;; $Id$
7 ;;; The latest version of this software is always available at;
8 ;;; http://www.yatex.org/
10 (require 'comment)
11 (require 'yatexlib)
12 (defconst YaTeX-revision-number "1.74.7"
13 "Revision number of running yatex.el")
15 ;---------- Local variables ----------
16 (defvar YaTeX-prefix "\C-c"
17 "*Prefix key to call YaTeX functions.
18 You can select favorite prefix key by setq in your ~/.emacs.")
20 (defvar YaTeX-environment-indent 1
21 "*Indentation depth at column width in LaTeX environments.")
23 (defvar YaTeX-fill-prefix nil
24 "*fill-prefix used for auto-fill-mode.
25 The default value is nil.")
27 (defvar YaTeX-fill-column 72
28 "*fill-column used for auto-fill-mode.")
30 (defvar YaTeX-comment-prefix "%"
31 "TeX comment prefix.")
33 (defvar YaTeX-current-position-register ?3
34 "*Position register to keep where the last completion was done.
35 All of YaTeX completing input store the current position into
36 the register YaTeX-current-position-register. So every time you
37 make a trip to any other part of text other than you are writing, you can
38 return to the editing paragraph by calling register-to-point with argument
39 YaTeX-current-position-register.")
41 ;;(defvar YaTeX-tmp-dic-unit 'main-file
42 ;; "*Default switching unit of temporary dictionary.
43 ;;There are two switching unit:
44 ;;'main-file : switch tmp-dic according to main-file directory.
45 ;;'directory : switch tmp-dic dir by dir."
46 ;;)
47 (defvar YaTeX-use-LaTeX2e t "*Use LaTeX2e or not. Nil meas latex 2.09")
49 (defvar tex-command
50 (cond
51 (YaTeX-use-LaTeX2e "platex")
52 (YaTeX-japan "jlatex")
53 (t "latex"))
54 "*Default command for typesetting LaTeX text.")
56 (defvar bibtex-command (if YaTeX-japan "jbibtex" "bibtex")
57 "*Default command of BibTeX.")
59 (defvar dvi2-command ;previewer command for your site
60 (if YaTeX-dos "dviout -wait=0"
61 "xdvi -geo +0+0 -s 4")
62 "*Default previewer command including its option.
63 This default value is for X window system.")
65 (defvar makeindex-command (if YaTeX-dos "makeind" "makeindex")
66 "*Default makeindex command.")
68 (defvar dviprint-command-format
69 (if YaTeX-dos "dviprt %s %f%t"
70 "dvi2ps %f %t %s | lpr")
71 "*Command line string to print out current file.
72 Format string %s will be replaced by the filename. Do not forget to
73 specify the `from usage' and `to usage' with their option by format string
74 %f and %t.
75 See also documentation of dviprint-from-format and dviprint-to-format.")
77 (defvar dviprint-from-format
78 (if YaTeX-dos "%b-" "-f %b")
79 "*`From' page format of dvi filter. %b will turn to beginning page number.")
81 (defvar dviprint-to-format
82 (if YaTeX-dos "%e" "-t %e")
83 "*`To' page format of dvi filter. %e will turn to end page number.")
85 (defvar YaTeX-dvipdf-command
86 "dvipdfmx"
87 "*Command name to convert dvi file to PDF.")
89 (defvar YaTeX-default-document-style
90 (concat (if YaTeX-japan "j") "article")
91 "*Default LaTeX Documentstyle for YaTeX-typeset-region.")
93 (defvar YaTeX-need-nonstop nil
94 "*T for adding `\\nonstopmode{}' to text before invoking latex command.")
96 (defvar latex-warning-regexp "line.* [0-9]*"
97 "*Regular expression of line number of warning message by latex command.")
99 (defvar latex-error-regexp "l\\.[1-9][0-9]*"
100 "*Regular expression of line number of latex error.
101 Perhaps your latex command stops at this error message with line number of
102 LaTeX source text.")
104 (defvar latex-dos-emergency-message
105 "Emergency stop" ;<- for Micro tex, ASCII-pTeX 1.6
106 "Message pattern of emergency stop of typesetting.
107 Because Demacs (GNU Emacs on DOS) cannot have concurrent process, the
108 latex command which is stopping on a LaTeX error, is terminated by Demacs.
109 Many latex command on DOS display some messages when it is terminated by
110 other process, user or OS. Define to this variable a message string of your
111 latex command on DOS shown at abnormal termination.
112 Remember Demacs's call-process function is not oriented for interactive
113 process.")
115 (defvar NTT-jTeX nil
116 "*T for using NTT-jTeX for latex command.
117 More precisely, setting t to this variables inhibits inter-word break on
118 typeset document by line-break of source text. That is, YaTeX automatically
119 put % after each line at filling.
120 改行+インデントによって、タイプセット後の字間が空いてしまうのを抑制する場合に
121 tにする(古いNTT-jTeXで顕著に現れる)。具体的には、fillするときに各行の終わりに
122 %を付加する。")
125 (defvar YaTeX-item-regexp
126 (concat (regexp-quote "\\") "\\(sub\\|bib\\)*item")
127 "*Regular expression of item command.")
129 (defvar YaTeX-sectioning-regexp
130 "\\(part\\|chapter\\*?\\|\\(sub\\)*\\(section\\|paragraph\\)\\)\\(\\*\\|\\b\\)"
131 "*LaTeX sectioning commands regexp.")
133 (defvar YaTeX-paragraph-start
134 (concat "^[ \t]*%\\|^[ \t]*$\\|\\'\\|^\C-l\\|\\\\\\\\$\\|^[ \t]*\\\\\\("
135 YaTeX-sectioning-regexp ;sectioning commands
136 "\\|[A-z]*item\\|begin{\\|end{" ;special declaration
137 "\\|\\[\\|\\]"
138 "\\|newpage\\b\\|vspace\\b"
139 "\\)")
140 "*Paragraph starting regexp of common LaTeX source. Use this value
141 for YaTeX-uncomment-paragraph.")
143 (defvar YaTeX-paragraph-separate
144 (concat "^[ \t]*%\\|^[ \t]*$\\|^\C-l\\|\\\\\\\\$\\|^[ \t]*\\\\\\("
145 YaTeX-sectioning-regexp ;sectioning commands
146 "\\|begin{\\|end{" ;special declaration
147 "\\|\\[\\|\\]"
148 "\\|newpage\\b\\|vspace\\b"
149 "\\)")
150 "*Paragraph delimiter regexp of common LaTeX source. Use this value
151 for YaTeX-uncomment-paragraph.")
153 (defvar YaTeX-verbatim-environments
154 '("verbatim" "verbatim*" "alltt")
155 "*Assume these environments of this variable disable LaTeX commands.")
156 (defvar YaTeX-verb-regexp "verb\\*?\\|path"
157 "*Regexp of verb family. Do not contain preceding \\\\ nor \\(\\).")
158 (defvar YaTeX-fill-inhibit-environments
159 (append '("tabular" "tabular*" "array" "picture" "eqnarray" "eqnarray*"
160 "equation" "equation*" "math" "displaymath")
161 YaTeX-verbatim-environments)
162 "*In these environments, YaTeX inhibits fill-paragraph from formatting.
163 Define those environments as a form of list.")
165 (defvar YaTeX-itemizing-env-regexp
166 "itemize\\|enumerate\\|description\\|list\\|thebibliography"
167 "*Regexp of itemizing environments")
168 (defvar YaTeX-equation-env-regexp
169 "array\\*?\\|equation\\*?"
170 "*Regexp of environments for equations")
171 (defvar YaTeX-array-env-regexp
172 (concat
173 "array\\*?\\|eqnarray\\*?\\|tabbing\\|tabular\\*?\\|" ;LaTeX
174 "matrix\\|pmatrix\\|bmatrix\\|vmatrix\\|Vmatrix\\|" ;AMS-LaTeX
175 "align\\*?\\|split\\*?\\|aligned\\*?\\|alignat\\*?\\|" ;AMS-LaTeX
176 "[bpvV]?matrix\\|smallmatrix\\|cases\\|" ;AMS-LaTeX
177 "xalignat\\*?\\|xxalignat\\*?") ;AMS-LaTeX
178 "*Regexp of environments where `&' becomes field delimiter.")
179 (defvar YaTeX-uncomment-once t
180 "*T for removing all continuous commenting character(%).
181 Nil for removing only one commenting character at the beginning-of-line.")
183 (defvar YaTeX-close-paren-always t
184 "*Close parenthesis always when YaTeX-modify-mode is nil.")
186 (defvar YaTeX-greek-by-maketitle-completion nil
187 "*T for greek letters completion by maketitle-type completion.")
189 (defvar YaTeX-auto-math-mode t
190 "*T for changing YaTeX-math mode automatically.")
191 (defvar YaTeX-use-AMS-LaTeX nil
192 "*T for using AMS-LaTeX")
194 (defvar yatex-mode-hook nil
195 "*List of functions to be called at the end of yatex-mode initializations.")
197 (defvar YaTeX-search-file-from-top-directory t
198 "*Non-nil means to search input-files from the directory where main file exists.")
200 (defvar YaTeX-use-font-lock (and (featurep 'font-lock)
201 (fboundp 'x-color-values)
202 (fboundp 'font-lock-fontify-region))
203 "*Use font-lock to fontify buffer or not.")
205 (defvar YaTeX-use-hilit19 (and (featurep 'hilit19) (fboundp 'x-color-values)
206 (fboundp 'hilit-translate)
207 (not YaTeX-use-font-lock))
208 "*Use hilit19 to highlight buffer or not.")
210 (defvar YaTeX-tabular-indentation 4
211 "*Indentation column-depth of continueing line in tabular environment.")
213 ;;-- Math mode values --
215 (defvar YaTeX-math-key-list-default
216 '((";" . YaTeX-math-sign-alist)
217 (":" . YaTeX-greek-key-alist))
218 "Default key sequence to invoke math-mode's image completion.")
220 (defvar YaTeX-math-key-list-private nil
221 "*User defined alist, math-mode-prefix vs completion alist.")
223 (defvar YaTeX-math-key-list
224 (append YaTeX-math-key-list-private YaTeX-math-key-list-default)
225 "Key sequence to invoke math-mode's image completion.")
227 (defvar YaTeX-skip-default-reader nil
228 "Non-nil skips default argument reader of section-type completion.")
230 (defvar YaTeX-simple-messages nil
231 "Non-nil makes minibuffer messages simpler.")
233 (defvar YaTeX-template-file "~/work/template.tex"
234 "*Template TeX source file. This will be inserted to empty file.")
236 (defvar YaTeX-addin-prefix "YaTeX:")
238 (defvar yatex-mode-abbrev-table nil
239 "*Abbrev table in use in yatex-mode buffers.")
240 (define-abbrev-table 'yatex-mode-abbrev-table ())
243 ;------------ Completion table ------------
244 ; Set tex-section-like command possible completion
245 (defvar section-table
246 (append
247 '(("part") ("chapter") ("chapter*") ("section") ("section*")
248 ("subsection") ("subsection*")
249 ("subsubsection") ("paragraph") ("subparagraph")
250 ("author") ("thanks") ("documentstyle") ("pagestyle") ("thispagestyle")
251 ("title") ("underline") ("label") ("makebox")
252 ("footnote") ("footnotetext") ("index")
253 ("hspace*") ("vspace*") ("bibliography") ("bibitem") ("cite")
254 ("input") ("include") ("includeonly") ("mbox") ("hbox") ("caption")
255 ("arabic")
256 ("newcounter")
257 ("newlength") ("setlength" 2) ("addtolength" 2) ("settowidth" 2)
258 ("setcounter" 2) ("addtocounter" 2) ("stepcounter" 2)
259 ("newcommand" 2) ("renewcommand" 2)
260 ("newenvironment" 3) ("newtheorem" 2)
261 ("cline") ("framebox") ("savebox" 2) ("sbox" 2) ("newsavebox") ("usebox")
262 ("date") ("put") ("ref") ("pageref") ("tabref") ("figref") ("raisebox" 2)
263 ("multicolumn" 3) ("shortstack") ("parbox" 2)
264 ;; for mathmode accent
265 ("tilde") ("hat") ("check") ("bar") ("dot") ("ddot") ("vec")
266 ("widetilde") ("widehat") ("overline") ("overrightarrow")
267 ;; section types in mathmode
268 ("frac" 2) ("sqrt") ("mathrm") ("mathbf") ("mathit")
270 )
271 (if YaTeX-use-LaTeX2e
272 '(("documentclass") ("usepackage")
273 ("textbf") ("textgt") ("textit") ("textmc") ("textmd") ("textnormal")
274 ("textrm") ("textsc") ("textsf") ("textsl") ("texttt") ("textup")
275 ("mathbf") ("mathcal") ("mathit") ("mathnormal") ("mathrm")
276 ("mathsf") ("mathtt")
277 ("textcircled")
278 ("scalebox" 1) ;is faking of argument position
279 ("rotatebox" 2) ("resizebox" 3) ("reflectbox")
280 ("colorbox" 2) ("fcolorbox" 3) ("textcolor" 2) ("color") ("pagecolor")
281 ("includegraphics") ("includegraphics*")
282 ("bou") ;defined in plext
283 ("url") ;defined in url
284 ("shadowbox") ("doublebox") ("ovalbox") ("Ovalbox")
285 ("fancyoval") ;defined in fancybox
286 ("keytop") ("mask" 2) ("maskbox" 5) ;defined in ascmac
287 ("bm") ;deined in bm
288 ("verbfile") ("listing") ;defined in misc
289 ("slashbox" 2) ("backslashbox" 2) ;defined in slashbox
290 ))
291 (if YaTeX-use-AMS-LaTeX
292 '(("DeclareMathOperator" 2) ("boldsymbol") ("pmb") ("eqref")
293 ("tag") ("tag*"))))
294 "Default completion table for section-type completion.")
296 (defvar user-section-table nil)
297 (defvar tmp-section-table nil)
298 (defvar YaTeX-ams-math-begin-alist
299 '(("align") ("align*") ("multline") ("multline*") ("gather") ("gather*")
300 ("alignat") ("alignat*") ("xalignat") ("xalignat*")
301 ("xxalignat") ("xxalignat*") ("flalign") ("flalign*") ("equation*")))
302 (defvar YaTeX-ams-math-gathering-alist
303 '(("matrix") ("pmatrix") ("bmatrix") ("Bmatrix") ("vmatrix") ("Vmatrix")
304 ("split") ("split*") ("aligned") ("aligned*") ("alignedat") ("gathered")
305 ("smallmatrix") ("cases") ("subequations")))
306 ;; Prepare list(not alist) for YaTeX::ref in yatexadd.el
307 (defvar YaTeX-math-begin-list
308 (mapcar 'car YaTeX-ams-math-begin-alist))
309 (defvar YaTeX-math-gathering-list ;used in yatexadd.el#yatex::ref
310 (mapcar 'car YaTeX-ams-math-gathering-alist))
313 (defvar YaTeX-ams-env-table
314 (append YaTeX-ams-math-begin-alist YaTeX-ams-math-gathering-alist)
315 "*Standard AMS-LaTeX(2e) environment completion table.")
317 ; Set tex-environment possible completion
318 (defvar env-table
319 (append
320 '(("quote") ("quotation") ("center") ("verse") ("document")
321 ("verbatim") ("itemize") ("enumerate") ("description")
322 ("list") ("tabular") ("tabular*") ("table") ("tabbing") ("titlepage")
323 ("sloppypar") ("picture") ("displaymath")
324 ("eqnarray") ("figure") ("equation") ("abstract") ("array")
325 ("thebibliography") ("theindex") ("flushleft") ("flushright")
326 ("minipage")
327 ("supertabular")
328 )
329 (if YaTeX-use-LaTeX2e
330 '(("comment") ;defined in version
331 ("longtable") ;defined in longtable
332 ("screen") ("boxnote") ("shadebox") ;; ("itembox") ;in ascmac
333 ("alltt") ;defined in alltt
334 ("multicols") ;defined in multicol
335 ("breakbox"))) ;defined in eclbkbox
336 (if YaTeX-use-AMS-LaTeX YaTeX-ams-env-table))
337 "Default completion table for begin-type completion.")
339 (defvar user-env-table nil)
340 (defvar tmp-env-table nil)
342 ; Set {\Large }-like completion
343 (defvar fontsize-table
344 '(("rm") ("em") ("bf") ("boldmath") ("it") ("sl") ("sf") ("sc") ("tt")
345 ("dg") ("dm")
346 ("tiny") ("scriptsize") ("footnotesize") ("small")("normalsize")
347 ("large") ("Large") ("LARGE") ("huge") ("Huge")
348 ("rmfamily") ("sffamily") ("ttfamily")
349 ("mdseries") ("bfseries") ("upshape")
350 ("itshape") ("slshape") ("scshape")
351 )
352 "Default completion table for large-type completion.")
354 (defvar LaTeX2e-fontstyle-alist
355 '(("rm" . "rmfamily")
356 ("sf" . "sffamily")
357 ("tt" . "ttfamily")
358 ("md" . "mdseries")
359 ("bf" . "bfseries")
360 ("up" . "upshape")
361 ("it" . "itshape")
362 ("sl" . "slshape")
363 ("sc" . "scshape")))
365 (defvar user-fontsize-table nil)
366 (defvar tmp-fontsize-table nil)
368 (defvar singlecmd-table
369 (append
370 '(("maketitle") ("makeindex") ("sloppy") ("protect") ("par")
371 ("LaTeX") ("TeX") ("item") ("item[]") ("appendix") ("hline") ("kill")
372 ;;("rightarrow") ("Rightarrow") ("leftarrow") ("Leftarrow")
373 ("pagebreak") ("nopagebreak") ("tableofcontents")
374 ("newpage") ("clearpage") ("cleardoublepage")
375 ("footnotemark") ("verb") ("verb*")
376 ("linebreak") ("pagebreak") ("noindent") ("indent")
377 ("left") ("right") ("dots") ("smallskip") ("medskip") ("bigskip")
378 ("displaystyle")
379 )
380 (if YaTeX-greek-by-maketitle-completion
381 '(("alpha") ("beta") ("gamma") ("delta") ("epsilon")
382 ("varepsilon") ("zeta") ("eta") ("theta")("vartheta")
383 ("iota") ("kappa") ("lambda") ("mu") ("nu") ("xi") ("pi")
384 ("varpi") ("rho") ("varrho") ("sigma") ("varsigma") ("tau")
385 ("upsilon") ("phi") ("varphi") ("chi") ("psi") ("omega")
386 ("Gamma") ("Delta") ("Theta") ("Lambda")("Xi") ("Pi")
387 ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")))
388 (if YaTeX-use-LaTeX2e
389 '(("return") ("Return") ("yen"))) ;defined in ascmac
390 (if YaTeX-use-AMS-LaTeX
391 '(("nonumber")))
392 )
393 "Default completion table for maketitle-type completion.")
395 (defvar user-singlecmd-table nil)
396 (defvar tmp-singlecmd-table nil)
398 ;---------- Key mode map ----------
399 ;;;
400 ;; Create new key map: YaTeX-mode-map
401 ;; Do not change this section.
402 ;;;
403 (defvar YaTeX-mode-map nil
404 "Keymap used in YaTeX mode")
406 (defvar YaTeX-prefix-map nil
407 "Keymap used when YaTeX-prefix key pushed")
409 (defvar YaTeX-user-extensional-map (make-sparse-keymap)
410 "*Keymap used for the user's customization")
411 (defvar YaTeX-current-completion-type nil
412 "Has current completion type. This may be used in YaTeX addin functions.")
414 (defvar YaTeX-modify-mode nil
415 "*Current editing mode.
416 When non-nil, each opening parentheses only opens,
417 nil enters both open/close parentheses when opening parentheses key pressed.")
419 (defvar YaTeX-math-mode nil
420 "Holds whether current mode is math-mode.")
421 ;;;
422 ;; Define key table
423 ;;;
424 (if YaTeX-mode-map
425 nil
426 (setq YaTeX-mode-map (make-sparse-keymap))
427 (setq YaTeX-prefix-map (make-sparse-keymap))
428 (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
429 (define-key YaTeX-mode-map "{" 'YaTeX-insert-braces)
430 (define-key YaTeX-mode-map "(" 'YaTeX-insert-parens)
431 (define-key YaTeX-mode-map "$" 'YaTeX-insert-dollar)
432 (define-key YaTeX-mode-map "|" 'YaTeX-insert-bar)
433 (define-key YaTeX-mode-map "&" 'YaTeX-insert-amper)
434 (define-key YaTeX-mode-map "[" 'YaTeX-insert-brackets)
435 (define-key YaTeX-mode-map YaTeX-prefix YaTeX-prefix-map)
436 (define-key YaTeX-mode-map "\M-\C-@" 'YaTeX-mark-environment)
437 (define-key YaTeX-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
438 (define-key YaTeX-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
439 (define-key YaTeX-mode-map "\M-\C-m" 'YaTeX-intelligent-newline)
440 (define-key YaTeX-mode-map "\C-i" 'YaTeX-indent-line)
441 (YaTeX-define-key "%" 'YaTeX-%-menu)
442 (YaTeX-define-key "t" 'YaTeX-typeset-menu)
443 (YaTeX-define-key "w" 'YaTeX-switch-mode-menu)
444 (YaTeX-define-key "'" 'YaTeX-prev-error)
445 (YaTeX-define-key "^" 'YaTeX-visit-main)
446 (YaTeX-define-key "4^" 'YaTeX-visit-main-other-window)
447 (YaTeX-define-key "4g" 'YaTeX-goto-corresponding-*-other-window)
448 (YaTeX-define-key "44" 'YaTeX-switch-to-window)
449 (and YaTeX-emacs-19 window-system
450 (progn
451 (YaTeX-define-key "5^" 'YaTeX-visit-main-other-frame)
452 (YaTeX-define-key "5g" 'YaTeX-goto-corresponding-*-other-frame)
453 (YaTeX-define-key "55" 'YaTeX-switch-to-window)))
454 (YaTeX-define-key " " 'YaTeX-do-completion)
455 (YaTeX-define-key "v" 'YaTeX-version)
457 (YaTeX-define-key "}" 'YaTeX-insert-braces-region)
458 (YaTeX-define-key "]" 'YaTeX-insert-brackets-region)
459 (YaTeX-define-key ")" 'YaTeX-insert-parens-region)
460 (YaTeX-define-key "$" 'YaTeX-insert-dollars-region)
461 (YaTeX-define-key "i" 'YaTeX-fill-item)
462 (YaTeX-define-key "\\"
463 '(lambda () (interactive)
464 (insert (if (YaTeX-in-math-mode-p) "\\backslash" "\\textbackslash"))))
465 (if YaTeX-no-begend-shortcut
466 (progn
467 (YaTeX-define-key "B" 'YaTeX-make-begin-end-region)
468 (YaTeX-define-key "b" 'YaTeX-make-begin-end))
469 (YaTeX-define-begend-key "bc" "center")
470 (YaTeX-define-begend-key "bd" "document")
471 (YaTeX-define-begend-key "bD" "description")
472 (YaTeX-define-begend-key "be" "enumerate")
473 (YaTeX-define-begend-key "bE" "equation")
474 (YaTeX-define-begend-key "bi" "itemize")
475 (YaTeX-define-begend-key "bl" "flushleft")
476 (YaTeX-define-begend-key "bm" "minipage")
477 (YaTeX-define-begend-key "bt" "tabbing")
478 (YaTeX-define-begend-key "bT" "tabular")
479 (YaTeX-define-begend-key "b\^t" "table")
480 (YaTeX-define-begend-key "bp" "picture")
481 (YaTeX-define-begend-key "bq" "quote")
482 (YaTeX-define-begend-key "bQ" "quotation")
483 (YaTeX-define-begend-key "br" "flushright")
484 (YaTeX-define-begend-key "bv" "verbatim")
485 (YaTeX-define-begend-key "bV" "verse")
486 (YaTeX-define-key "B " 'YaTeX-make-begin-end-region)
487 (YaTeX-define-key "b " 'YaTeX-make-begin-end))
488 (YaTeX-define-key "e" 'YaTeX-end-environment)
489 (YaTeX-define-key "S" 'YaTeX-make-section-region)
490 (YaTeX-define-key "s" 'YaTeX-make-section)
491 (YaTeX-define-key "L" 'YaTeX-make-fontsize-region)
492 (YaTeX-define-key "l" 'YaTeX-make-fontsize)
493 (YaTeX-define-key "m" 'YaTeX-make-singlecmd)
494 (YaTeX-define-key "." 'YaTeX-comment-paragraph)
495 (YaTeX-define-key "," 'YaTeX-uncomment-paragraph)
496 (YaTeX-define-key ">" 'YaTeX-comment-region)
497 (YaTeX-define-key "<" 'YaTeX-uncomment-region)
498 (YaTeX-define-key "g" 'YaTeX-goto-corresponding-*)
499 (YaTeX-define-key "k" 'YaTeX-kill-*)
500 (YaTeX-define-key "c" 'YaTeX-change-*)
501 (YaTeX-define-key "a" 'YaTeX-make-accent)
502 (YaTeX-define-key "?" 'YaTeX-help)
503 (YaTeX-define-key "/" 'YaTeX-apropos)
504 (YaTeX-define-key "&" 'YaTeX-what-column)
505 (YaTeX-define-key "d" 'YaTeX-display-hierarchy)
506 (YaTeX-define-key "x" YaTeX-user-extensional-map)
507 (YaTeX-define-key "n"
508 '(lambda () (interactive)
509 (insert "\\" (if (YaTeX-on-section-command-p "o?oalign") "crcr" "\\"))))
510 (if YaTeX-dos
511 (define-key YaTeX-prefix-map "\C-r"
512 '(lambda () (interactive)
513 (YaTeX-set-screen-height YaTeX-saved-screen-height) (recenter)))))
515 (defvar YaTeX-section-completion-map nil
516 "*Key map used at YaTeX completion in the minibuffer.")
517 (if YaTeX-section-completion-map nil
518 (setq YaTeX-section-completion-map
519 (copy-keymap (or (and (boundp 'gmhist-completion-map)
520 gmhist-completion-map)
521 minibuffer-local-completion-map)))
522 (define-key YaTeX-section-completion-map
523 " " 'YaTeX-minibuffer-complete)
524 (define-key YaTeX-section-completion-map
525 "\C-i" 'YaTeX-minibuffer-complete)
526 (define-key YaTeX-section-completion-map
527 "\C-v" 'YaTeX-read-section-with-overview))
529 (defvar YaTeX-recursive-map nil
530 "*Key map used at YaTeX reading arguments in the minibuffer.")
531 (if YaTeX-recursive-map nil
532 (setq YaTeX-recursive-map (copy-keymap global-map))
533 (define-key YaTeX-recursive-map YaTeX-prefix YaTeX-prefix-map)
534 (mapcar
535 (function
536 (lambda (key)
537 (define-key YaTeX-mode-map (car key) 'YaTeX-math-insert-sequence)
538 (define-key YaTeX-recursive-map (car key) 'YaTeX-math-insert-sequence)))
539 YaTeX-math-key-list))
540 ;---------- Define other variable ----------
541 (defvar YaTeX-env-name "document" "*Initial tex-environment completion")
542 (defvar YaTeX-section-name
543 (if YaTeX-use-LaTeX2e "documentclass" "documentstyle")
544 "*Initial tex-section completion")
545 (defvar YaTeX-fontsize-name "large" "*Initial fontsize completion")
546 (defvar YaTeX-single-command "maketitle" "*Initial LaTeX single command")
547 (defvar YaTeX-kanji-code (if YaTeX-dos 1 2)
548 "*File kanji code used by Japanese TeX.
549 nil: Do not care (Preserve coding-system)
550 0: no-converion (mule)
551 1: Shift JIS
552 2: JIS
553 3: EUC
554 4: UTF-8")
556 (defvar YaTeX-coding-system nil "File coding system used by Japanese TeX.")
557 (cond
558 (YaTeX-emacs-20
559 (setq YaTeX-coding-system
560 (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist))))
561 ((boundp 'MULE)
562 (setq YaTeX-coding-system
563 (symbol-value (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist))))))
565 (defvar YaTeX-mode-syntax-table nil
566 "*Syntax table for yatex-mode")
568 (if YaTeX-mode-syntax-table nil
569 (setq YaTeX-mode-syntax-table (make-syntax-table (standard-syntax-table)))
570 (modify-syntax-entry ?\n " " YaTeX-mode-syntax-table)
571 (modify-syntax-entry ?\{ "(}" YaTeX-mode-syntax-table)
572 (modify-syntax-entry ?\} "){" YaTeX-mode-syntax-table)
573 (modify-syntax-entry ?\t " " YaTeX-mode-syntax-table)
574 (modify-syntax-entry ?\f ">" YaTeX-mode-syntax-table)
575 (modify-syntax-entry ?\n ">" YaTeX-mode-syntax-table)
576 (modify-syntax-entry ?$ "$$" YaTeX-mode-syntax-table)
577 (modify-syntax-entry ?% "<" YaTeX-mode-syntax-table)
578 (modify-syntax-entry ?\\ "/" YaTeX-mode-syntax-table)
579 (modify-syntax-entry ?~ " " YaTeX-mode-syntax-table))
581 ;---------- Provide YaTeX-mode ----------
582 ;;;
583 ;; Major mode definition
584 ;;;
585 (defun yatex-mode ()
586 " Yet Another LaTeX mode: Major mode for editing input files of LaTeX.
587 -You can invoke processes concerning LaTeX typesetting by
588 \\[YaTeX-typeset-menu]
589 -Complete LaTeX environment form of `\\begin{env} ... \\end{env}' by
590 \\[YaTeX-make-begin-end]
591 -Enclose region into some environment by
592 \\[universal-argument] \\[YaTeX-make-begin-end]
593 -Complete LaTeX command which takes argument like `\\section{}' by
594 \\[YaTeX-make-section]
595 -Put LaTeX command which takes no arguments like `\\maketitle' by
596 \\[YaTeX-make-singlecmd]
597 -Complete font or character size descriptor like `{\\large }' by
598 \\[YaTeX-make-fontsize]
599 -Enclose region into those descriptors above by
600 \\[universal-argument] \\[YaTeX-make-fontsize]
601 -Enter European accent notations by
602 \\[YaTeX-make-accent]
603 -Toggle various modes of YaTeX by
604 \\[YaTeX-switch-mode-menu]
605 -Change environt name (on the begin/end line) by
606 \\[YaTeX-change-*]
607 -Kill LaTeX command/environment sequences by
608 \\[YaTeX-kill-*]
609 -Kill LaTeX command/environment with its contents
610 \\[universal-argument] \\[YaTeX-kill-*]
611 -Go to corresponding object (begin/end, file, labels) by
612 \\[YaTeX-goto-corresponding-*] or
613 \\[YaTeX-goto-corresponding-*-other-window] (in other window)
614 \\[YaTeX-goto-corresponding-*-other-frame] (in other frame)
615 -Go to main LaTeX source text by
616 \\[YaTeX-visit-main] or
617 \\[YaTeX-visit-main-other-window] (in other window)
618 \\[YaTeX-visit-main-other-frame] (in other frame)
619 -Comment out or uncomment region by
620 \\[YaTeX-comment-region] or \\[YaTeX-uncomment-region]
621 -Comment out or uncomment paragraph by
622 \\[YaTeX-comment-paragraph] or \\[YaTeX-uncomment-paragraph]
623 -Make an \\item entry hang-indented by
624 \\[YaTeX-fill-item]
625 -Enclose the region with parentheses by
626 \\[YaTeX-insert-parens-region]
627 \\[YaTeX-insert-braces-region]
628 \\[YaTeX-insert-brackets-region]
629 \\[YaTeX-insert-dollars-region]
630 -Look up the corresponding column header of tabular environment by
631 \\[YaTeX-what-column]
632 -Enter a newline and an entry suitable for environment by
633 \\[YaTeX-intelligent-newline]
634 -View the structure of file inclusion by
635 \\[YaTeX-display-hierarchy]
636 -Refer the online help of popular LaTeX commands by
637 \\[YaTeX-help] (help)
638 \\[YaTeX-apropos] (apropos)
639 -Edit `%# notation' by
640 \\[YaTeX-%-menu]
642 Those are enough for fastening your editing of LaTeX source. But further
643 more features are available and they are documented in the manual.
644 "
645 (interactive)
646 (kill-all-local-variables)
647 (setq major-mode 'yatex-mode)
648 (setq mode-name (if YaTeX-japan "やてふ" "YaTeX"))
649 (mapcar 'make-local-variable
650 '(dvi2-command fill-column fill-prefix
651 tmp-env-table tmp-section-table tmp-fontsize-table
652 tmp-singlecmd-table paragraph-start paragraph-separate
653 YaTeX-math-mode indent-line-function comment-line-break-function
654 comment-start comment-start-skip
655 ))
656 (cond ((null YaTeX-kanji-code)
657 nil)
658 ((boundp 'MULE)
659 (set-file-coding-system YaTeX-coding-system))
660 ((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system))
661 (setq buffer-file-coding-system
662 (or (and (fboundp 'set-auto-coding) buffer-file-name
663 (save-excursion
664 (goto-char (point-min))
665 (set-auto-coding buffer-file-name (buffer-size))))
666 YaTeX-coding-system)))
667 ((featurep 'mule)
668 (set-file-coding-system YaTeX-coding-system))
669 ((boundp 'NEMACS)
670 (make-local-variable 'kanji-fileio-code)
671 (setq kanji-fileio-code YaTeX-kanji-code)))
672 (setq fill-column YaTeX-fill-column
673 fill-prefix YaTeX-fill-prefix
674 paragraph-start YaTeX-paragraph-start
675 paragraph-separate YaTeX-paragraph-separate
676 indent-line-function 'YaTeX-indent-line
677 comment-start YaTeX-comment-prefix
678 comment-end ""
679 comment-start-skip "[^\\\\]%+[ \t]*"
680 local-abbrev-table yatex-mode-abbrev-table)
681 (if (fboundp 'comment-indent-new-line) ;for Emacs21
682 (setq comment-line-break-function 'YaTeX-comment-line-break))
684 (if (and YaTeX-use-font-lock (featurep 'font-lock))
685 (progn
686 (require 'yatex19)
687 (YaTeX-font-lock-set-default-keywords)
688 (or (featurep 'xemacs)
689 (set (make-local-variable 'font-lock-defaults)
690 (get 'yatex-mode 'font-lock-defaults)))
691 ;;(font-lock-mode 1)
692 ))
693 (use-local-map YaTeX-mode-map)
694 (set-syntax-table YaTeX-mode-syntax-table)
695 (if YaTeX-dos (setq YaTeX-saved-screen-height (YaTeX-screen-height)))
696 (YaTeX-read-user-completion-table)
697 (and (fboundp 'YaTeX-hilit-setup-alist) (YaTeX-hilit-setup-alist))
698 (makunbound 'inenv)
699 (turn-on-auto-fill) ;1.63
700 (and (= 0 (buffer-size)) (file-exists-p YaTeX-template-file)
701 (y-or-n-p (format "Insert %s?" YaTeX-template-file))
702 (insert-file-contents (expand-file-name YaTeX-template-file)))
703 (run-hooks 'text-mode-hook 'yatex-mode-hook))
705 ;---------- Define YaTeX-mode functions ----------
706 (defvar YaTeX-ec "\\" "Escape character of current mark-up language.")
707 (defvar YaTeX-ec-regexp (regexp-quote YaTeX-ec))
708 (defvar YaTeX-struct-begin
709 (concat YaTeX-ec "begin{%1}%2")
710 "Keyword format of begin-environment.")
711 (defvar YaTeX-struct-end
712 (concat YaTeX-ec "end{%1}")
713 "Keyword format of end-environment.")
714 (defvar YaTeX-struct-name-regexp "[^}]+"
715 "Environment name regexp.")
716 (defvar YaTeX-TeX-token-regexp
717 (cond (YaTeX-japan "[A-Za-z*ぁ-ん亜-龠]+")
718 (t "[A-Za-z*]+"))
719 "Regexp of characters which can be a member of TeX command's name.")
720 (defvar YaTeX-kanji-regexp "[ぁ-ん亜-龠]"
721 "Generic regexp of Japanese Kanji (and symbol) characters.")
722 (defvar YaTeX-command-token-regexp YaTeX-TeX-token-regexp
723 "Regexp of characters which can be a member of current mark up language's command name.")
725 ;;(defvar YaTeX-struct-section
726 ;; (concat YaTeX-ec "%1{%2}")
727 ;; "Keyword to make section.")
729 ;;;
730 ;; autoload section
731 ;;;
733 ;;autoload from yatexprc.el
734 (autoload 'YaTeX-visit-main "yatexprc" "Visit main LaTeX file." t)
735 (autoload 'YaTeX-visit-main-other-window "yatexprc"
736 "Visit main other window." t)
737 (autoload 'YaTeX-main-file-p "yatexprc" "Check if the file is main." t)
738 (autoload 'YaTeX-get-builtin "yatexprc" "Get %# built-in." t)
739 (autoload 'YaTeX-system "yatexprc" "Call system command" t)
740 (autoload 'YaTeX-save-buffers "yatexprc" "Save buffers of same major mode" t)
742 ;;autoload from yatexmth.el
743 (autoload 'YaTeX-math-insert-sequence "yatexmth" "Image input." t)
744 (autoload 'YaTeX-in-math-mode-p "yatexmth" "Check if in math-env." t)
745 (autoload 'YaTeX-toggle-math-mode "yatexmth" "YaTeX math-mode interfaces." t)
746 (autoload 'YaTeX-math-member-p "yatexmth" "Check if a word is math command." t)
747 (autoload 'YaTeX-insert-amsparens-region "yatexmth" "AMS parens region" t)
748 (autoload 'YaTeX-insert-amsbraces-region "yatexmth" "AMS braces region" t)
749 (autoload 'YaTeX-insert-amsbrackets-region "yatexmth" "AMS brackets region" t)
750 (autoload 'YaTeX-on-parenthesis-p "yatexmth" "Check if on math-parens" t)
751 (autoload 'YaTeX-goto-open-paren "yatexmth" "Goto opening paren" t)
752 (autoload 'YaTeX-change-parentheses "yatexmth" "Change corresponding parens" t)
753 (autoload 'YaTeX-goto-corresponding-paren "yatexmth" "\bigl\bigr jumps" t)
754 (autoload 'YaTeX-typeset-math-region "yatexmth" "Typeset math-region" t)
756 ;;autoload from yatexhlp.el
757 (autoload 'YaTeX-help "yatexhlp" "YaTeX helper with LaTeX commands." t)
758 (autoload 'YaTeX-apropos "yatexhlp" "Apropos for (La)TeX commands." t)
760 ;;autoload from yatexgen.el
761 (autoload 'YaTeX-generate "yatexgen" "YaTeX add-in function generator." t)
762 (autoload 'YaTeX-generate-simple "yatexgen" "YaTeX add-in support." t)
764 ;;autoload from yatexsec.el
765 (autoload 'YaTeX-section-overview "yatexsec" "YaTeX sectioning(view)" t)
766 (autoload 'YaTeX-read-section-in-minibuffer "yatexsec" "YaTeX sectioning" t)
767 (autoload 'YaTeX-make-section-with-overview "yatexsec" "YaTeX sectioning" t)
769 ;;autoload from yatexenv.el
770 (autoload 'YaTeX-what-column "yatexenv" "YaTeX env. specific funcs" t)
771 (autoload 'YaTeX-intelligent-newline "yatexenv" "YaTeX env. specific funcs" t)
772 (autoload 'YaTeX-indent-line-equation "yatexenv" "Indent equation lines." t)
773 (autoload 'YaTeX-goto-corresponding-leftright "yatexenv" "\left\right jumps" t)
775 ;;autoload from yatexhie.el
776 (autoload 'YaTeX-display-hierarchy "yatexhie"
777 "YaTeX document hierarchy browser" t)
778 (autoload 'YaTeX-display-hierarchy-directly "yatexhie"
779 "Same as YaTeX-display-hierarchy. Call from mouse." t)
781 ;;autoload from yatexpkg.el
782 (autoload 'YaTeX-package-auto-usepackage "yatexpkg" "Auto \\usepackage" t)
784 ;;;
785 ;; YaTeX-mode functions
786 ;;;
787 (defun YaTeX-insert-begin-end (env region-mode)
788 "Insert \\begin{mode-name} and \\end{mode-name}.
789 This works also for other defined begin/end tokens to define the structure."
790 (setq YaTeX-current-completion-type 'begin)
791 (let*((ccol (current-column)) beg beg2 exchange
792 (arg region-mode) ;for old compatibility
793 (indent-column (+ ccol YaTeX-environment-indent))(i 1) func)
794 (if (and region-mode (> (point) (mark)))
795 (progn (exchange-point-and-mark)
796 (setq exchange t
797 ccol (current-column)
798 indent-column (+ ccol YaTeX-environment-indent))))
799 ;;VER2 (insert "\\begin{" env "}" (YaTeX-addin env))
800 (setq beg (point))
801 (YaTeX-insert-struc 'begin env)
802 (setq beg2 (point))
803 (insert "\n")
804 (indent-to indent-column)
805 (save-excursion
806 ;;indent optional argument of \begin{env}, if any
807 (while (> (point-beginning-of-line) beg)
808 (skip-chars-forward "\\s " (point-end-of-line))
809 (indent-to indent-column)
810 (forward-line -1)))
811 (require 'yatexenv)
812 (if region-mode
813 ;;if region-mode, indent all text in the region
814 (save-excursion
815 (if (fboundp (intern-soft (concat "YaTeX-enclose-" env)))
816 (funcall (intern-soft (concat "YaTeX-enclose-" env))
817 (point) (mark))
818 (while (< (progn (forward-line 1) (point)) (mark))
819 (if (eolp) nil
820 (skip-chars-forward " \t\n")
821 (indent-to indent-column))))))
822 (if region-mode (exchange-point-and-mark))
823 (indent-to ccol)
824 ;;VER2 (insert "\\end{" env "}\n")
825 (YaTeX-insert-struc 'end env)
826 (YaTeX-reindent ccol)
827 (if region-mode
828 (progn
829 (insert "\n")
830 (or exchange (exchange-point-and-mark)))
831 (goto-char beg2)
832 (if (intern-soft (concat "YaTeX-intelligent-newline-" env))
833 (progn
834 (YaTeX-intelligent-newline nil)
835 (message
836 (cond
837 (YaTeX-japan "%s で次の行の入力に進みます。")
838 (t "`%s' produces the next line's template."))
839 (key-description
840 (car (where-is-internal 'YaTeX-intelligent-newline))))))
841 (YaTeX-indent-line))
842 (YaTeX-package-auto-usepackage env 'env)
843 (if YaTeX-current-position-register
844 (point-to-register YaTeX-current-position-register))))
846 (defun YaTeX-make-begin-end (arg)
847 "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
848 by completing read.
849 If you invoke this command with universal argument,
850 \(key binding for universal-argument is \\[universal-argument]\)
851 you can put REGION into that environment between \\begin and \\end."
852 (interactive "P")
853 (let*
854 ((mode (if arg " region" ""))
855 (env
856 (YaTeX-read-environment
857 (format "Begin environment%s(default %s): " mode YaTeX-env-name))))
858 (if (string= env "")
859 (setq env YaTeX-env-name))
860 (setq YaTeX-env-name env)
861 (YaTeX-update-table
862 (list YaTeX-env-name) 'env-table 'user-env-table 'tmp-env-table)
863 (YaTeX-insert-begin-end YaTeX-env-name arg)))
865 (defun YaTeX-make-begin-end-region ()
866 "Call YaTeX-make-begin-end with ARG to specify region mode."
867 (interactive)
868 (YaTeX-make-begin-end t))
870 (defun YaTeX-guess-section-type ()
871 (if (eq major-mode 'yatex-mode)
872 (save-excursion
873 (cond
874 ((save-excursion (not (search-backward YaTeX-ec nil t)))
875 (if YaTeX-use-LaTeX2e "documentclass" "documentstyle"))
876 ((progn
877 (if (= (char-after (1- (point))) ?~) (forward-char -1))
878 (forward-char -1) (looking-at "表\\|図\\|式\\|第"))
879 "ref")
880 ((and (looking-at "[a-z \t]")
881 (progn (skip-chars-backward "a-z \t")
882 (looking-at "table\\|figure\\|formula")))
883 "ref")
884 ((save-excursion
885 (skip-chars-backward "[^ア-ン]")
886 (looking-at "プログラム\\|リスト"))
887 "ref")
888 ((YaTeX-re-search-active-backward
889 (concat YaTeX-ec-regexp "begin{\\([^}]+\\)}")
890 (regexp-quote YaTeX-comment-prefix)
891 (save-excursion (forward-line -1) (point))
892 t)
893 (let ((env (YaTeX-match-string 1)))
894 (cdr (assoc env
895 '(("table" . "caption"))))))
896 ))))
898 (defun YaTeX-make-section (arg &optional beg end cmd)
899 "Make LaTeX \\section{} type command with completing read.
900 With numeric ARG, you can specify the number of arguments of
901 LaTeX command.
902 For example, if you want to produce LaTeX command
904 \\addtolength{\\topmargin}{8mm}
906 which has two arguments. You can produce that sequence by typing...
907 ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
908 \(by default\)
909 Then yatex will automatically complete `addtolength' with two arguments
910 next time.
911 You can complete symbol at LaTeX command and the 1st argument.
913 If the optional 2nd and 3rd argument BEG END are specified, enclose
914 the region from BEG to END into the first argument of the LaTeX sequence.
915 Optional 4th arg CMD is LaTeX command name, for non-interactive use."
916 (interactive "P")
917 (setq YaTeX-current-completion-type 'section)
918 (if (equal arg '(4)) (setq beg (region-beginning) end (region-end)))
919 (unwind-protect
920 (let*
921 ((source-window (selected-window))
922 guess
923 (section
924 (or cmd
925 (progn
926 (setq guess
927 (or (YaTeX-guess-section-type) YaTeX-section-name))
928 (YaTeX-read-section
929 (if YaTeX-simple-messages
930 (format "Section-type (default %s): " guess)
931 (if (> (minibuffer-depth) 0)
932 (format "%s???{} (default %s)%s: "
933 YaTeX-ec guess
934 (format "[level:%d]" (minibuffer-depth)))
935 (format "(C-v for view-section) %s???{%s} (default %s): "
936 YaTeX-ec (if beg "region" "") guess)))
937 nil))))
938 (section (if (string= section "") guess section))
939 (numarg ;; The number of section-type command's argument
940 (or (and (numberp arg) arg)
941 (nth 1 (YaTeX-lookup-table section 'section))
942 1))
943 (arg-reader (intern-soft (concat "YaTeX::" section)))
944 (addin-args (and arg-reader (fboundp arg-reader)))
945 (title "")
946 (j 1)
947 (after-change-functions nil) ;inhibit font-locking temporarily
948 (enable-recursive-minibuffers t)
949 (mkarg-func
950 (function
951 (lambda (n)
952 (while (<= j n)
953 (insert
954 (concat ;to allow nil return value
955 "{"
956 (setq title
957 (cond
958 (addin-args (funcall arg-reader j))
959 (YaTeX-skip-default-reader "")
960 (t
961 (read-string
962 (format "Argument %d of %s: " j section)))))
963 "}"))
964 (setq j (1+ j))))))
965 );;let
966 (setq YaTeX-section-name section)
967 (if beg
968 (let*((e (make-marker))
969 (ar2 (intern-soft (concat "YaTeX::" section "-region")))
970 (arp (and ar2 (fboundp ar2))))
971 (goto-char end)
972 (insert "}")
973 (set-marker e (point))
974 (goto-char beg)
975 (insert YaTeX-ec YaTeX-section-name
976 (YaTeX-addin YaTeX-section-name))
977 (if (> numarg 1) (funcall mkarg-func (1- numarg)))
978 (insert "{")
979 (if arp (funcall ar2 (point) e))
980 (goto-char e)
981 (set-marker e nil))
982 (use-global-map YaTeX-recursive-map)
983 (if (= numarg 0) (YaTeX-make-singlecmd YaTeX-section-name)
984 (progn (insert YaTeX-ec YaTeX-section-name)
985 (insert (YaTeX-addin YaTeX-section-name))))
986 ;;read arguments with add-in
987 (funcall mkarg-func numarg))
988 (YaTeX-update-table
989 (if (/= numarg 1) (list section numarg)
990 (list section))
991 'section-table 'user-section-table 'tmp-section-table)
992 (if YaTeX-current-position-register
993 (point-to-register YaTeX-current-position-register))
994 (if (string= (YaTeX-buffer-substring (- (point) 2) (point))
995 "{}")
996 (forward-char -1))
997 (while (string= (YaTeX-buffer-substring (- (point) 3) (1- (point)))
998 "{}")
999 (forward-char -2))
1000 (YaTeX-package-auto-usepackage section 'section))
1001 (if (<= (minibuffer-depth) 0) (use-global-map global-map))
1002 (insert ""))) ;insert dummy string to fontify(Emacs20)
1004 (defun YaTeX-make-section-region (args beg end)
1005 "Call YaTeX-make-section with arguments to specify region mode."
1006 (interactive "P\nr")
1007 (YaTeX-make-section args beg end))
1009 (defun YaTeX-make-fontsize (arg &optional fontsize)
1010 "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
1011 If you invoke this command with universal argument, you can put region
1012 into {\\xxx } braces.
1013 \(key binding for universal-argument is \\[universal-argument]\)"
1014 (interactive "P")
1015 (YaTeX-sync-local-table 'tmp-fontsize-table)
1016 (let* ((mode (if arg "region" ""))
1017 (fontsize
1018 (or fontsize
1019 (YaTeX-read-fontsize
1020 (if YaTeX-simple-messages
1021 (format "Font or size (default %s): " YaTeX-fontsize-name)
1022 (format "{\\??? %s} (default %s)%s: " mode YaTeX-fontsize-name
1023 (if (> (minibuffer-depth) 0)
1024 (format "[level:%d]" (minibuffer-depth)) "")))
1025 nil nil))))
1026 (if (string= fontsize "")
1027 (setq fontsize YaTeX-fontsize-name))
1028 (setq YaTeX-current-completion-type 'large)
1029 (setq YaTeX-fontsize-name fontsize)
1030 (YaTeX-update-table
1031 (list YaTeX-fontsize-name)
1032 'fontsize-table 'user-fontsize-table 'tmp-fontsize-table)
1033 (and YaTeX-use-LaTeX2e
1034 (YaTeX-latex2e-p)
1035 (setq fontsize
1036 (cdr (assoc YaTeX-fontsize-name LaTeX2e-fontstyle-alist)))
1037 (setq YaTeX-fontsize-name fontsize))
1038 (if arg
1039 (save-excursion
1040 (if (> (point) (mark)) (exchange-point-and-mark))
1041 (insert "{\\" YaTeX-fontsize-name " ")
1042 (exchange-point-and-mark)
1043 (insert "}"))
1044 (insert (concat "{\\" YaTeX-fontsize-name " }"))
1045 (forward-char -1)
1046 (if YaTeX-current-position-register
1047 (point-to-register YaTeX-current-position-register))
1048 (save-excursion
1049 (insert (YaTeX-addin YaTeX-fontsize-name)))
1050 (YaTeX-package-auto-usepackage YaTeX-fontsize-name 'large))))
1052 (defun YaTeX-make-fontsize-region ()
1053 "Call function:YaTeX-make-fontsize with ARG to specify region mode."
1054 (interactive)
1055 (YaTeX-make-fontsize t))
1057 (defvar YaTeX-singlecmd-suffix "" "*Suffix for maketitle-type commands.")
1058 (defvar YaTeX-read-singlecmd-history nil "Holds maketitle-type history.")
1059 (put 'YaTeX-read-singlecmd-history 'no-default t)
1060 (defun YaTeX-make-singlecmd (single)
1061 (interactive
1062 (list (YaTeX-cplread-with-learning
1063 (if YaTeX-simple-messages
1064 (format "maketitle-type (default %s): " YaTeX-single-command)
1065 (format "%s??? (default %s)%s: " YaTeX-ec YaTeX-single-command
1066 (if (> (minibuffer-depth) 0)
1067 (format "[level:%d]" (minibuffer-depth)) "")))
1068 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table
1069 nil nil nil 'YaTeX-read-singlecmd-history)))
1070 (if (string= single "")
1071 (setq single YaTeX-single-command))
1072 (setq YaTeX-single-command single)
1073 (setq YaTeX-current-completion-type 'maketitle)
1074 (let ((dollar (and (not (YaTeX-in-math-mode-p))
1075 (YaTeX-math-member-p YaTeX-single-command)))
1076 p q)
1077 (if dollar (insert "$"))
1078 (insert YaTeX-ec YaTeX-single-command)
1079 (setq p (point))
1080 (insert (YaTeX-addin single) YaTeX-singlecmd-suffix)
1081 (if dollar (insert "$"))
1082 (setq q (point))
1083 (goto-char p)
1084 (forward-char -2)
1085 (if (looking-at "\\[\\]") (forward-char 1) (goto-char q)))
1086 (YaTeX-package-auto-usepackage YaTeX-single-command 'maketitle)
1087 (if YaTeX-current-position-register
1088 (point-to-register YaTeX-current-position-register)))
1090 (defvar YaTeX-completion-begin-regexp "[{\\]"
1091 "Regular expression of limit where LaTeX command's completion begins.")
1093 (defun YaTeX-do-completion ()
1094 "Try completion on LaTeX command preceding point."
1095 (interactive)
1096 (if
1097 (or (eq (preceding-char) ? )
1098 (eq (preceding-char) ?\t)
1099 (eq (preceding-char) ?\n)
1100 (bobp))
1101 (message "Nothing to complete.") ;Do not complete
1102 (let* ((end (point))
1103 (limit (point-beginning-of-line))
1104 (completion-begin
1105 (progn (re-search-backward "[ \t\n]" limit 1) (point)))
1106 (begin (progn
1107 (goto-char end)
1108 (if (re-search-backward YaTeX-completion-begin-regexp
1109 completion-begin t)
1110 (1+ (point))
1111 nil))))
1112 (goto-char end)
1113 (cond
1114 ((null begin)
1115 (message "I think it is not a LaTeX sequence."))
1116 (t
1117 (mapcar 'YaTeX-sync-local-table
1118 '(tmp-section-table tmp-env-table tmp-singlecmd-table))
1119 (let*((pattern (YaTeX-buffer-substring begin end))
1120 (all-table
1121 (append
1122 section-table user-section-table tmp-section-table
1123 env-table user-env-table tmp-env-table
1124 singlecmd-table user-singlecmd-table tmp-singlecmd-table))
1125 ;; First,
1126 ;; search completion without backslash.
1127 (completion (try-completion pattern all-table)))
1128 (if
1129 (eq completion nil)
1130 ;; Next,
1131 ;; search completion with backslash
1132 (setq completion
1133 (try-completion
1134 (YaTeX-buffer-substring (1- begin) end)
1135 all-table nil)
1136 begin (1- begin)))
1137 (cond
1138 ((null completion)
1139 (message (concat "Can't find completion for '" pattern "'"))
1140 (ding))
1141 ((eq completion t) (message "Sole completion."))
1142 ((not (string= completion pattern))
1143 (delete-region begin end)
1144 (insert completion)
1146 (t
1147 (message "Making completion list...")
1148 (with-output-to-temp-buffer "*Help*"
1149 (display-completion-list
1150 (all-completions pattern all-table)))))))))))
1152 (defun YaTeX-toggle-modify-mode (&optional arg)
1153 (interactive "P")
1154 (or (memq 'YaTeX-modify-mode mode-line-format)
1155 (setq mode-line-format
1156 (append (list "" 'YaTeX-modify-mode) mode-line-format)))
1157 (if (or arg (null YaTeX-modify-mode))
1158 (progn
1159 (setq YaTeX-modify-mode "*m*")
1160 (message "Modify mode"))
1161 (setq YaTeX-modify-mode nil)
1162 (message "Cancel modify mode."))
1163 (set-buffer-modified-p (buffer-modified-p))) ;redraw mode-line
1165 (defun YaTeX-switch-mode-menu (arg &optional char)
1166 (interactive "P")
1167 (message "Toggle: (M)odify-mode ma(T)h-mode")
1168 (let ((c (or char (read-char))))
1169 (cond
1170 ((= c ?m) (YaTeX-toggle-modify-mode arg))
1171 ((or (= c ?$) (= c ?t))
1172 (if YaTeX-auto-math-mode
1173 (message "Makes no sense in YaTeX-auto-math-mode.")
1174 (YaTeX-toggle-math-mode arg))))))
1176 (defun YaTeX-insert-quote ()
1177 (interactive)
1178 (insert
1179 (cond
1180 ((YaTeX-literal-p) ?\")
1181 ((= (preceding-char) ?\\ ) ?\")
1182 ;((= (preceding-char) ?\( ) ?\")
1183 ((or (= (preceding-char) 32)
1184 (= (preceding-char) 9)
1185 (= (preceding-char) ?\n)
1186 (bobp)
1187 (string-match
1188 (regexp-quote (char-to-string (preceding-char)))
1189 "、。,.?!「」『』【】()"))
1190 "``")
1191 (t "''"))))
1193 (defun YaTeX-closable-p ()
1194 (and (not YaTeX-modify-mode)
1195 (not (eq YaTeX-close-paren-always 'never))
1196 (or YaTeX-close-paren-always (eolp))
1197 (not (input-pending-p))
1198 (not (YaTeX-literal-p)))
1199 ;;(or YaTeX-modify-mode
1200 ;; (and (not YaTeX-close-paren-always) (not (eolp)))
1201 ;; (input-pending-p)
1202 ;; (YaTeX-quick-in-environment-p "verbatim"))
1205 (defun YaTeX-insert-braces-region (beg end &optional open close)
1206 (interactive "r")
1207 (save-excursion
1208 (goto-char end)
1209 (YaTeX-insert-inherit (or close "}"))
1210 (goto-char beg)
1211 (YaTeX-insert-inherit (or open "{"))))
1213 (defun YaTeX-get-macro-at-point (&optional p)
1214 "Get (La)TeX macro around point P."
1215 (interactive "d")
1216 (save-excursion
1217 (goto-char (setq p (or p (point))))
1218 (cond
1219 ((and (not (bobp))
1220 (string-match "[a-zA-Z]" (char-to-string (preceding-char))))
1221 (skip-chars-backward "a-zA-Z")
1222 (if (and (= (preceding-char) ?\\)
1223 (looking-at "\\([a-z]+\\)"))
1224 (YaTeX-buffer-substring (point) p))))))
1226 (defun YaTeX-insert-braces (arg &optional open close)
1227 (interactive "p")
1228 (let ((begend-guide
1229 (function
1230 (lambda ()
1231 (if (equal (get 'YaTeX-insert-braces 'begend-guide) 2)
1232 nil ;if triggered thrice, do nothing
1233 (momentary-string-display
1234 (format
1235 (cond
1236 (YaTeX-japan "begin/end入力には %s を使いましょう")
1237 (t "You don't understand Zen of `%s'!"))
1238 (key-description
1239 (car (where-is-internal 'YaTeX-make-begin-end))))
1240 (point))
1241 (put 'YaTeX-insert-braces 'begend-guide
1242 (+ 1 (string-to-int ;increment counter of beg-end guidance
1243 (prin1-to-string
1244 (get 'YaTeX-insert-braces 'begend-guide)))))))))
1245 env macro not-literal b e)
1246 (cond
1247 ((YaTeX-jmode) (YaTeX-self-insert arg))
1248 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1249 ((save-excursion
1250 (and (> (- (point) (point-min)) 6)
1251 (condition-case () (forward-char -6) (error nil)))
1252 (looking-at "\\\\left\\\\"))
1253 (insert "{\\right\\}")
1254 (forward-char -8))
1255 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
1256 (and (> (- (point) (point-min)) 6) (forward-char -6))
1257 (looking-at "\\\\[bB]igl\\\\"))
1258 (insert
1259 (concat
1260 "{" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\}"))
1261 (forward-char -7))
1262 ((save-excursion
1263 (and (> (- (point) (point-min)) 7)
1264 (condition-case () (forward-char -7) (error nil)))
1265 (looking-at "\\\\[bB]iggl\\\\"))
1266 (insert
1267 (concat
1268 "{" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\}"))
1269 (forward-char -8))
1270 ((= (preceding-char) ?\\ )
1271 (insert "{\\}")
1272 (forward-char -2)) ;matsu's hack ends here
1273 ((and (setq not-literal (not (YaTeX-literal-p)))
1274 (equal "end" (setq macro (YaTeX-get-macro-at-point)))
1275 (setq env (YaTeX-inner-environment)))
1276 (funcall begend-guide)
1277 (insert "{" env "}"))
1278 ((and not-literal (equal "begin" macro))
1279 (insert "{")
1280 (save-excursion
1281 (indent-to (prog1 (- (current-column) 7) (insert "}\n")))
1282 (insert "\\end{}")
1283 (setq e (point)))
1284 (setq env
1285 (YaTeX-read-environment
1286 (format "Begin environment(default %s): " YaTeX-env-name)))
1287 (if (string= "" env) (setq env YaTeX-env-name))
1288 (setq YaTeX-env-name env)
1289 (funcall begend-guide)
1290 (delete-region (- (point) 7) e)
1291 (YaTeX-insert-begin-end env nil))
1292 (t
1293 (insert (or open "{") (or close "}"))
1294 (forward-char -1)
1295 (if (and (eq (char-after (point)) ?\}) ;; the case `\\{}'
1296 (eq (char-after (- (point) 2)) ?\\ ))
1297 (progn (insert "\\") (forward-char -1)))
1298 ))))
1300 (defun YaTeX-jmode ()
1301 (or (and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
1302 (and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
1303 (and (boundp 'skk-mode) skk-mode (not skk-latin-mode))
1304 (and (boundp 'default-input-method) default-input-method
1305 current-input-method)))
1307 (defun YaTeX-jmode-off ()
1308 (if (cond
1309 ((and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
1310 (canna-toggle-japanese-mode) t)
1311 ((and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
1312 (egg:toggle-egg-mode-on-off) t)
1313 ((and (fboundp 'skk-mode) (boundp 'skk-mode) skk-mode)
1314 (cond
1315 ((fboundp 'skk-latin-mode)
1316 (or (and (boundp 'skk-henkan-mode) skk-henkan-mode)
1317 (and (boundp 'skk-henkan-on)
1318 (or skk-henkan-mode skk-henkan-active))
1319 (and (boundp 'j-henkan-on)
1320 (or j-henkan-on j-henkan-active))
1321 ;; Deactivate jmode if henkan-mode is not running.
1322 ;; Suggested by tt.tetsuo.tsukamoto.
1323 (progn
1324 (put 'YaTeX-jmode-on 'skkkata skk-katakana)
1325 (skk-latin-mode t))))
1326 ((fboundp 'skk-mode-off) (skk-mode-off))
1327 (t (j-mode-off)))
1328 t)
1329 ((and (fboundp 'toggle-input-method) current-input-method)
1330 (toggle-input-method) t)
1331 ((and (fboundp 'fep-force-off) (fep-force-off))))
1332 (put 'YaTeX-jmode 'jmode t)))
1334 (defun YaTeX-jmode-on ()
1335 (cond
1336 ((boundp 'canna:*japanese-mode*)
1337 (if (not canna:*japanese-mode*) (canna-toggle-japanese-mode)))
1338 ((boundp 'egg:*mode-on*)
1339 (and (not egg:*mode-on*) (not egg:*input-mode*)
1340 (egg:toggle-egg-mode-on-off)))
1341 ((and (fboundp 'skk-mode) (boundp 'skk-mode))
1342 (if (get 'YaTeX-jmode-on 'skkkata)
1343 (skk-j-mode-on t)
1344 (skk-mode 1))
1345 (put 'YaTeX-jmode-on 'skkkata nil))
1346 ((fboundp 'toggle-input-method)
1347 (if (not current-input-method) (toggle-input-method)))
1348 ((and (fboundp 'fep-force-on) (fep-force-on)))))
1350 (defun YaTeX-jmode-back ()
1351 (if (get 'YaTeX-jmode 'jmode)
1352 (YaTeX-jmode-on))
1353 (setplist 'YaTeX-jmode nil))
1355 (defun YaTeX-self-insert (arg)
1356 (call-interactively (global-key-binding (char-to-string last-command-char))))
1357 (defun YaTeX-insert-inherit (&rest args)
1358 (apply (if (fboundp 'insert-and-inherit) 'insert-and-inherit 'insert)
1359 args))
1361 (defun YaTeX-insert-brackets (arg)
1362 "Insert Kagi-kakko or \\ [ \\] pair or simply \[."
1363 (interactive "p")
1364 (let ((col (1- (current-column))))
1365 (cond
1366 ((YaTeX-jmode) (YaTeX-self-insert arg))
1367 ((not (YaTeX-closable-p))
1368 (YaTeX-self-insert arg))
1369 ((save-excursion
1370 (and (> (- (point) (point-min)) 5) (forward-char -5))
1371 (looking-at "\\\\left"))
1372 (YaTeX-insert-inherit "[\\right]")
1373 (forward-char -7))
1374 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
1375 (and (> (- (point) (point-min)) 5) (forward-char -5))
1376 (looking-at "\\\\[bB]igl"))
1377 (YaTeX-insert-inherit
1378 (concat
1379 "[" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r]"))
1380 (forward-char -6))
1381 ((save-excursion
1382 (and (> (- (point) (point-min)) 6) (forward-char -6))
1383 (looking-at "\\\\[bB]iggl"))
1384 (YaTeX-insert-inherit
1385 (concat
1386 "[" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r]"))
1387 (forward-char -7)) ;matsu's hack ends here
1388 ((and (= (preceding-char) ?\\ )
1389 (/= (char-after (- (point) 2)) ?\\ )
1390 (not (YaTeX-in-math-mode-p)))
1391 (YaTeX-insert-inherit last-command-char "\n")
1392 (indent-to (max 0 col))
1393 (YaTeX-insert-inherit "\\]")
1394 (beginning-of-line)
1395 (open-line 1)
1396 (delete-region (point) (progn (beginning-of-line) (point)))
1397 (indent-to (+ YaTeX-environment-indent (max 0 col)))
1398 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1)))
1399 ((YaTeX-closable-p)
1400 (YaTeX-insert-inherit "[]")
1401 (backward-char 1))
1402 (t (YaTeX-self-insert arg)))))
1404 (defun YaTeX-insert-brackets-region (beg end)
1405 (interactive "r")
1406 (YaTeX-insert-braces-region beg end "[" "]"))
1408 (defun YaTeX-insert-parens (arg)
1409 "Insert parenthesis pair."
1410 (interactive "p")
1411 (cond
1412 ((YaTeX-jmode) (YaTeX-self-insert arg))
1413 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1414 ((save-excursion
1415 (and (> (- (point) (point-min)) 5) (forward-char -5))
1416 (looking-at "\\\\left"))
1417 (YaTeX-insert-inherit "(\\right)")
1418 (forward-char -7))
1419 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
1420 (and (> (- (point) (point-min)) 5) (forward-char -5))
1421 (looking-at "\\\\[bB]igl"))
1422 (YaTeX-insert-inherit
1423 (concat
1424 "(" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r)"))
1425 (forward-char -6))
1426 ((save-excursion
1427 (and (> (- (point) (point-min)) 6) (forward-char -6))
1428 (looking-at "\\\\[bB]iggl"))
1429 (YaTeX-insert-inherit
1430 (concat
1431 "(" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r)"))
1432 (forward-char -7))
1433 ((= (preceding-char) ?\\ ) ;matsu's hack ends here
1434 (YaTeX-insert-inherit "(\\)")
1435 (backward-char 2))
1436 ((YaTeX-closable-p)
1437 (YaTeX-insert-inherit "()")
1438 (backward-char 1))
1439 (t (YaTeX-self-insert arg))))
1441 (defun YaTeX-insert-parens-region (beg end)
1442 (interactive "r")
1443 (YaTeX-insert-braces-region beg end "(" ")"))
1445 (defun YaTeX-insert-bar (arg)
1446 "Insert bar pair."
1447 (interactive "p")
1448 (cond
1449 ((YaTeX-jmode) (YaTeX-self-insert arg))
1450 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1451 ((save-excursion
1452 (and (> (- (point) (point-min)) 5) (forward-char -5))
1453 (looking-at "\\\\left"))
1454 (YaTeX-insert-inherit "|\\right|")
1455 (forward-char -7))
1456 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
1457 (and (> (- (point) (point-min)) 5) (forward-char -5))
1458 (looking-at "\\\\[bB]igl"))
1459 (insert
1460 (concat
1461 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r|"))
1462 (forward-char -6))
1463 ((save-excursion
1464 (and (> (- (point) (point-min)) 6) (forward-char -6))
1465 (looking-at "\\\\[bB]iggl"))
1466 (insert
1467 (concat
1468 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r|"))
1469 (forward-char -7))
1470 ((save-excursion ; added by Jin <MAF01011<at>nifty.ne.jp>
1471 (and (> (- (point) (point-min)) 6) (forward-char -6))
1472 (looking-at "\\\\left\\\\"))
1473 (YaTeX-insert-inherit "|\\right\\|")
1474 (forward-char -8))
1475 ((save-excursion
1476 (and (> (- (point) (point-min)) 6) (forward-char -6))
1477 (looking-at "\\\\[bB]igl\\\\"))
1478 (insert
1479 (concat
1480 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\|"))
1481 (forward-char -7))
1482 ((save-excursion
1483 (and (> (- (point) (point-min)) 7) (forward-char -7))
1484 (looking-at "\\\\[bB]iggl\\\\"))
1485 (insert
1486 (concat
1487 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\|"))
1488 (forward-char -8)) ; added by Jin up to here.
1489 ((= (preceding-char) ?\\ )
1490 (YaTeX-insert-inherit "|\\|")
1491 (backward-char 2))
1492 ; ((and (YaTeX-closable-p)
1493 ; (/= (preceding-char) ?|)
1494 ; (/= (following-char) ?|))
1495 ; (YaTeX-insert-inherit "||")
1496 ; (backward-char 1))
1497 (t (YaTeX-self-insert arg))))
1499 (defvar YaTeX-use-jmode-hook (not (and (fboundp 'skk-mode) (boundp 'skk-mode)))
1500 "*Non-nil means activate automatic jmode switcher within/out math mode.
1501 Hopefully, change default to t in the next version of 1.75.")
1502 (defun YaTeX-jmode-hook (old new)
1503 "A hook controling jmode on/off."
1504 ;; This function is called via point-entered/leave hook, so that
1505 ;; codes in it is evaluated on such emacsen as having text-properties.
1506 (let ((inhibit-point-motion-hooks t)
1507 (oldp (plist-get (text-properties-at old) 'point-left))
1508 (newp (plist-get (text-properties-at new) 'point-left))
1509 (lnew (plist-get (text-properties-at new) 'last-new))
1510 (mjmode (plist-get (text-properties-at new) 'mjmode))
1511 (bmp (buffer-modified-p))
1512 (jm (YaTeX-jmode)) b e)
1513 (unwind-protect
1514 (cond
1515 ((eq lnew new) nil) ;Do nothing if continuous entry
1516 ((and (not (eq newp 'YaTeX-jmode-hook))
1517 (eq oldp 'YaTeX-jmode-hook)
1518 (plist-get (text-properties-at old) 'entered))
1519 ;; leave
1520 (remove-text-properties
1521 (setq b (1+ (or (previous-single-property-change old 'point-left)
1522 (1- (point)))))
1523 (setq e (1- (or (next-single-property-change old 'point-left)
1524 (1+ (point)))))
1525 (list 'last-new nil 'entered nil))
1526 (add-text-properties b e (list 'mjmode jm))
1527 (if (boundp 'skk-katakana)
1528 (put 'YaTeX-jmode-on 'skkkata skk-katakana))
1529 (if (plist-get (text-properties-at old) 'jmode)
1530 (YaTeX-jmode-on)))
1531 ((and (not (eq oldp 'YaTeX-jmode-hook))
1532 (eq newp 'YaTeX-jmode-hook)
1533 (not (plist-get (text-properties-at new) 'entered)))
1534 ;; enter
1535 (add-text-properties
1536 (1+ (or (previous-single-property-change new 'point-left)
1537 (1- (point))))
1538 (1- (or (next-single-property-change new 'point-left)
1539 (1+ (point))))
1540 (list 'jmode jm 'last-new new 'entered t))
1541 (if (boundp 'skk-katakana) ;care for skk katakana mode
1542 (put 'YaTeX-jmode-on 'skkkata skk-katakana))
1543 (if mjmode (YaTeX-jmode-on) (YaTeX-jmode-off))))
1544 ;;unwind job
1545 (set-buffer-modified-p bmp))))
1547 (defun YaTeX-insert-dollar ()
1548 (interactive)
1549 (if (or (not (YaTeX-closable-p))
1550 (= (preceding-char) 92)
1551 (and (YaTeX-in-math-mode-p)
1552 (or (/= (preceding-char) ?$) (/= (following-char) ?$))))
1553 (insert "$")
1554 (insert "$$")
1555 (forward-char -1)
1556 (and YaTeX-use-jmode-hook
1557 (fboundp 'add-text-properties)
1558 (add-text-properties
1559 (1- (point)) (1+ (point))
1560 (list 'point-left 'YaTeX-jmode-hook
1561 'point-entered 'YaTeX-jmode-hook
1562 'front-sticky t
1563 'rear-nonsticky t
1564 'mjmode nil
1565 'jmode (YaTeX-jmode))))
1566 (YaTeX-jmode-off)
1567 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1))))
1569 (defun YaTeX-insert-dollars-region (beg end)
1570 (interactive "r")
1571 (YaTeX-insert-braces-region beg end "$" "$"))
1573 (defun YaTeX-insert-amper ()
1574 (interactive)
1575 (if (or (string-match YaTeX-array-env-regexp
1576 (or (YaTeX-inner-environment t) "document"))
1577 (= (preceding-char) 92)
1578 (YaTeX-literal-p)
1579 (YaTeX-in-math-mode-p))
1580 (insert "&")
1581 (insert "\\&")))
1583 (defun YaTeX-version ()
1584 "Return string of the version of running YaTeX."
1585 (interactive)
1586 (message
1587 (concat "Yet Another tex-mode "
1588 (if YaTeX-japan "「野鳥」" "`Wild Bird'")
1589 " Revision "
1590 YaTeX-revision-number)))
1592 (defun YaTeX-typeset-menu (arg &optional char)
1593 "Typeset, preview, visit error and miscellaneous convenient menu.
1594 Optional second argument CHAR is for non-interactive call from menu."
1595 (interactive "P")
1596 (message
1597 (concat "J)latex R)egion E)nv B)ibtex mk(I)dx "
1598 "latex+p(D)f "
1599 (if (fboundp 'start-process) "K)ill ")
1600 "P)review "
1601 (and (boundp 'window-system) window-system "S)earch ")
1602 "V)iewErr L)pr"))
1603 (let ((sw (selected-window)) (c (or char (read-char))))
1604 (require 'yatexprc) ;for Nemacs's bug
1605 (select-window sw)
1606 (cond
1607 ((= c ?j) (YaTeX-typeset-buffer))
1608 ((= c ?r) (YaTeX-typeset-region))
1609 ((= c ?e) (YaTeX-typeset-environment))
1610 ((= c ?b) (YaTeX-call-command-on-file
1611 bibtex-command "*YaTeX-bibtex*" YaTeX-parent-file))
1612 ((= c ?i) (YaTeX-call-command-on-file
1613 makeindex-command "*YaTeX-makeindex*" YaTeX-parent-file))
1614 ((= c ?k) (YaTeX-kill-typeset-process YaTeX-typeset-process))
1615 ((= c ?p) (call-interactively 'YaTeX-preview))
1616 ((= c ?q) (YaTeX-system "lpq" "*Printer queue*"))
1617 ((= c ?d) (YaTeX-typeset-buffer YaTeX-dvipdf-command))
1618 ((= c ?v) (YaTeX-view-error))
1619 ((= c ?l) (YaTeX-lpr arg))
1620 ((= c ?m) (YaTeX-switch-mode-menu arg))
1621 ((= c ?b) (YaTeX-insert-string "\\"))
1622 ((= c ?s) (YaTeX-xdvi-remote-search arg)))))
1624 (if (fboundp 'wrap-function-to-control-ime)
1625 (wrap-function-to-control-ime 'YaTeX-typeset-menu t "P"))
1628 (defun YaTeX-%-menu (&optional beg end char)
1629 "Operate %# notation."
1630 ;;Do not use interactive"r" for the functions which require no mark
1631 (interactive)
1632 (message "!)Edit-%%#! B)EGIN-END-region L)Edit-%%#LPR")
1633 (let ((c (or char (read-char))) (string "") key
1634 (b (make-marker)) (e (make-marker)))
1635 (save-excursion
1636 (cond
1637 ((or (= c ?!) (= c ?l)) ;Edit `%#!'
1638 (goto-char (point-min))
1639 (setq key (cond ((= c ?!) "%#!")
1640 ((= c ?l) "%#LPR")))
1641 (if (re-search-forward key nil t)
1642 (progn
1643 (setq string (YaTeX-buffer-substring
1644 (point) (point-end-of-line)))
1645 (delete-region (point) (progn (end-of-line) (point))))
1646 (open-line 1)
1647 (delete-region (point) (progn (beginning-of-line)(point)));for 19 :-<
1648 (insert key))
1649 (unwind-protect
1650 (setq string (read-string (concat key ": ") string))
1651 (insert string)))
1653 ((= c ?b) ;%#BEGIN %#END region
1654 (or end (setq beg (min (point) (mark)) end (max (point) (mark))))
1655 (set-marker b beg)
1656 (set-marker e end)
1657 (goto-char (point-min))
1658 (while (re-search-forward "^%#\\(BEGIN\\)\\|\\(END\\)$" nil t)
1659 (beginning-of-line)
1660 (delete-region (point) (progn (forward-line 1) (point))))
1661 (goto-char b)
1662 (open-line 1)
1663 (delete-region (point) (progn (beginning-of-line)(point)));for 19 :-<
1664 (insert "%#BEGIN")
1665 (goto-char e)
1666 (insert "%#END\n")
1667 (set-marker b nil)
1668 (set-marker e nil))
1669 ))))
1671 (defvar YaTeX-refcommand-def-regexp-default
1672 "label\\|bibitem")
1673 (defvar YaTeX-refcommand-def-regexp-private nil
1674 "*Regexp of defining label commands")
1675 (defvar YaTeX-refcommand-def-regexp
1676 (concat (if YaTeX-refcommand-def-regexp-private
1677 (concat YaTeX-refcommand-def-regexp-private "\\|"))
1678 YaTeX-refcommand-def-regexp-default))
1680 (defvar YaTeX-refcommand-ref-regexp-default
1681 "\\(page\\|eq\\|fig\\)?ref\\|cite")
1682 (defvar YaTeX-refcommand-ref-regexp-private nil
1683 "*Regexp of referring label commands")
1684 (defvar YaTeX-refcommand-ref-regexp
1685 (concat (if YaTeX-refcommand-ref-regexp-private
1686 (concat YaTeX-refcommand-ref-regexp-private "\\|"))
1687 YaTeX-refcommand-ref-regexp-default))
1689 (defvar YaTeX-refcommand-regexp
1690 (concat YaTeX-refcommand-def-regexp
1691 "\\|" YaTeX-refcommand-ref-regexp)
1692 "Regexp of label defining/referring command name.")
1694 (defun YaTeX-goto-corresponding-label (reverse &optional otherwin)
1695 "Jump to corresponding \\label{} and \\ref{} or \\cite and \\bibitem.
1696 The default search direction depends on the command at the cursor position.
1697 When the cursor is on \\ref(\\cite), YaTeX will try to search the
1698 corresponding \\label(\\bibitem) backward,
1699 and if it fails search forward again. And when the cursor is
1700 on \\label(\\bibitem), YaTeX will search the corresponding \\ref(\\cite)
1701 forward at first and secondary backward.
1702 Argument REVERSE non-nil makes the default
1703 direction rule reverse. Since Search string is automatically set in
1704 search-last-string, you can repeat search the same label/ref by typing
1705 \\[isearch-forward] or \\[isearch-backward].
1706 If optional second argument OTHERWIN is non-nil, move to other window."
1708 (let ((scmd "") label direc string blist (p (point)) (cb (current-buffer))
1709 (refcommands YaTeX-refcommand-regexp)
1710 (foundmsg (format "Type %s %c to return to original position."
1711 (key-description
1712 (car
1713 (or (where-is-internal 'register-to-point)
1714 (where-is-internal 'jump-to-register))))
1715 YaTeX-current-position-register))
1716 (func (function (lambda (string sfunc)
1717 (or
1718 (funcall sfunc string nil t)
1719 (funcall (if (eq sfunc 're-search-forward)
1720 're-search-backward 're-search-forward)
1721 string nil t))))))
1722 (cond
1723 ((YaTeX-on-section-command-p refcommands)
1724 (setq scmd
1725 (cdr
1726 (assoc
1727 (YaTeX-match-string 1)
1728 '(("label" . "\\\\\\(page\\|eq\\)?ref{%k}")
1729 ("ref" . "\\\\label{%k}")
1730 ("eqref" . "\\\\label{%k}")
1731 ("pageref" . "\\\\label{%k}")
1732 ("cite" .
1733 "\\\\bibitem\\(\\[[^]]+\\]\\)?{%k}\\|^\\s *@[a-z]+{%k,")
1734 ("bibitem" . "\\\\cite\\(\\[[^]]+\\]\\)?")))))
1735 (goto-char (match-end 0))
1736 (let ((label (YaTeX-buffer-substring
1737 (1- (point)) (progn (backward-list 1) (1+ (point)))))
1738 (fp (make-marker))fl fn
1739 (goother (function (lambda (buffer point)
1740 (goto-char point)
1741 (if (one-window-p)
1742 (split-window-calculate-height
1743 YaTeX-default-pop-window-height))
1744 (select-window (get-lru-window))
1745 (switch-to-buffer buffer)))))
1746 ;(setq string (concat "\\" scmd "{" label "}"))
1747 ;(setq string (concat "\\\\" scmd "{" (regexp-quote label) "}"))
1748 (setq string (YaTeX-replace-format scmd "k" (regexp-quote label)))
1749 (setq direc (if (string-match "ref\\|cite" scmd)
1750 're-search-forward 're-search-backward))
1751 (if YaTeX-current-position-register
1752 (point-to-register YaTeX-current-position-register))
1753 (if reverse (setq direc (if (eq direc 're-search-forward)
1754 're-search-backward 're-search-forward)))
1755 (if (funcall func string direc) ;label/ref found!
1756 (progn
1757 (if otherwin (funcall goother cb p))
1758 (goto-char (match-beginning 0))
1759 (push-mark p))
1760 ;;if label/ref not found, search through all yatex buffers.
1761 (goto-char p) ;resume position of current buffer
1762 (catch 'found
1763 (setq blist (YaTeX-yatex-buffer-list))
1764 (while blist
1765 ;; search for corresponding keyword
1766 (set-buffer (car blist))
1767 (if (YaTeX-on-section-command-p refcommands)
1768 (goto-char (match-beginning 0)))
1769 (cond
1770 ; cond1
1771 ((funcall func string direc)
1772 (cond
1773 (otherwin
1774 (set-buffer cb)
1775 (funcall goother (car blist) p))
1776 ((or (get-buffer-window (car blist))
1777 (and YaTeX-emacs-19
1778 (get-buffer-window (car blist) t)))
1779 (goto-buffer-window (car blist)))
1780 (t
1781 (switch-to-buffer (car blist))
1782 (message foundmsg)))
1783 (goto-char (match-beginning 0))
1784 (throw 'found t))
1785 ; cond2
1786 ((and
1787 (string-match "bibitem" scmd)
1788 (catch 'found2
1789 (save-excursion
1790 (goto-char (point-min))
1791 (while (YaTeX-re-search-active-forward
1792 "\\\\bibliography{\\([^}]*\\)}" "%" nil t)
1793 (setq fl (YaTeX-split-string (YaTeX-match-string 1) ","))
1794 (while fl
1795 (if (or (file-exists-p (setq fn (car fl)))
1796 (file-exists-p (setq fn (concat fn ".bib"))))
1797 (progn
1798 (set-buffer (find-file-noselect fn))
1799 (save-excursion
1800 (goto-char (point-min))
1801 (if (YaTeX-re-search-active-forward
1802 string "%" nil t)
1803 (throw 'found2
1804 (set-marker fp (point)))))))
1805 (setq fl (cdr fl)))))))
1806 (if otherwin
1807 (funcall goother (marker-buffer fp) fp)
1808 (switch-to-buffer (marker-buffer fp))
1809 (goto-char fp))
1810 (set-marker fp nil)
1811 (message foundmsg)
1812 (throw 'found t)))
1813 (setq blist (cdr blist)))
1814 ;; search for bibliography
1815 )))
1816 (if YaTeX-emacs-19
1817 (setq regexp-search-ring
1818 (cons string (delete string regexp-search-ring)))
1819 (setq search-last-regexp string)))
1820 (t nil))))
1822 ;;YaTeX-goto-corresponding-environment was moved to yatexlib
1824 (defun YaTeX-goto-corresponding-file (&optional other)
1825 "Visit or switch buffer of corresponding file,
1826 looking at \\input or \\include or \\includeonly on current line."
1827 (if (not (YaTeX-on-includes-p)) nil
1828 (let ((parent buffer-file-name) input-file b)
1829 (save-excursion
1830 (if (and (re-search-forward "[{%]" (point-end-of-line) t)
1831 (= ?{ (char-after (match-beginning 0))))
1832 nil
1833 (skip-chars-backward "^,{"))
1834 (setq input-file
1835 (YaTeX-buffer-substring
1836 (point) (progn (skip-chars-forward "^ ,}") (point))))
1837 (if (not (string-match "\\.\\(tex\\|sty\\)$" input-file))
1838 (setq input-file (concat input-file ".tex"))))
1839 (cond
1840 (other (YaTeX-switch-to-buffer-other-window input-file))
1841 ((setq b (YaTeX-get-file-buffer input-file))
1842 (goto-buffer-window b))
1843 (t (YaTeX-switch-to-buffer input-file)))
1844 (or (YaTeX-get-builtin "!")
1845 YaTeX-parent-file
1846 (setq YaTeX-parent-file parent)))))
1848 (defun YaTeX-goto-corresponding-BEGIN-END ()
1849 (if (not (YaTeX-on-BEGIN-END-p)) nil
1850 (if (cond
1851 ((equal (match-beginning 0) (match-beginning 1)) ;if on %#BEGIN
1852 (not (search-forward "%#END" nil t)))
1853 (t ; if on %#END
1854 (not (search-backward "%#BEGIN" nil t))))
1855 (error "Corresponding %%#BEGIN/END not found."))
1856 (beginning-of-line)
1857 t))
1859 (defvar YaTeX-processed-file-regexp-alist nil
1860 "Alist of regexp of processed file regexp vs. its file name part;
1861 For example, if you include image file with `\\epsfile{file=FILE}' where
1862 `FILE' is processed file. You might want to view FILE with other previewer
1863 such as ghostview, or want to preview its source which was drawn with
1864 other drawing tool, tgif for example. Then you should set entire regexp
1865 of including expression and enclose its file name part with \\\\( and \\\\).
1867 Ex. (\"\\\\\\\\epsfile{[^}]*file=\\\\([^,} ]+\\\\)\\\\(\\\\.e?ps\\\\)?[^}]*}\" 1)
1869 Where the first group surrounded by \\\\( and \\\\) is the file name part
1870 of expression. So you should set 1 to second element. And the first
1871 matching group is sent to (image) processor defined by the variable
1872 YaTeX-file-processor-alist. See also the documentation of
1873 YaTeX-file-processor-alist.
1875 ↑じゃ良くわかんないすね。例えば tgif hoge.obj して hoge.eps を
1876 \\epsfile{file=hoge.eps} でインクルードしているとしよう。その行で
1877 \[prefix\] g を押した時に tgif を起動して欲しかったら、まず上のような
1878 正規表現を設定する。\\\\(と\\\\)で囲んだところがファイル名になるように
1879 注意する。でファイル名部分が何番目の\\\\(\\\\)になるかをリストの2番目に書く。
1880 すると、その部分が変数 YaTeX-file-processor-alist で定義された
1881 処理プログラムに渡される。というわけ。
1882 ん〜やっぱりむずかしいね。分からない時は隣の Lisper に聞くか、
1883 fj野鳥の会で聞こう!
1884 ")
1886 (defvar YaTeX-processed-file-regexp-alist-default
1887 '(("\\\\epsfile\\(\\[[^]]+\\]\\)?{[^},]*file=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1888 ("\\\\epsfig{[^},]*fi\\(le\\|gure\\)=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1889 ("\\\\postscriptbox{[^}]*}{[^}]*}{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 1)
1890 ("\\\\\\(epsfbox\\|includegraphics\\|epsfig\\)\\*?{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 2) ;\epsfbox{hoge.ps} or \includegraphics{hoge.eps}
1891 ("\\\\\\(psbox\\)\\(\\[[^]]+\\]\\)?{\\(\\([^,} ]*/\\)?[^} ]+\\)\\(\\.e?ps\\)}" 3) ;\psbox[options...]{hoge.eps} (97/1/11)
1892 ("\\\\input{\\([^} ]+\\)\\(\\.tps\\)}" 1) ;tgif2tex (1998/9/16)
1894 "See the documentation of YaTeX-processed-file-regexp-alist.")
1896 (defvar YaTeX-file-processor-alist nil
1897 "*Alist of files' processor vs. its extension;
1898 See also the documentation of YaTeX-processed-file-regexp-alist.")
1900 (defvar YaTeX-file-processor-alist-default
1901 '(("tgif" . ".obj")
1902 ("ghostview" . ".ps")
1903 ("ghostview" . ".eps")
1904 (t . ".tex")
1905 (t . ".sty")
1906 (t . ""))
1907 "See the documentation of YaTeX-file-processor-alist.")
1909 (defun YaTeX-goto-corresponding-file-processor (&optional other)
1910 "Execute corresponding file processor."
1911 (save-excursion
1912 (or (looking-at YaTeX-ec-regexp)
1913 (skip-chars-backward (concat "^" YaTeX-ec) (point-beginning-of-line)))
1914 (let ((list (append YaTeX-processed-file-regexp-alist
1915 YaTeX-processed-file-regexp-alist-default))
1916 (p (point)) flist file
1917 (peol (point-end-of-line))
1918 (basedir
1919 (if YaTeX-search-file-from-top-directory
1920 (save-excursion (YaTeX-visit-main t) default-directory)
1921 ".")))
1922 (setq flist (catch 'found
1923 (while list
1924 (goto-char p)
1925 (if (re-search-forward (car (car list)) peol t)
1926 (progn
1927 (setq file (YaTeX-match-string
1928 (car (cdr (car list)))))
1929 (throw 'found (cdr (car list)))))
1930 (setq list (cdr list)))))
1931 (if flist ;if pattern and file name found
1932 (let*((plist (append YaTeX-file-processor-alist
1933 YaTeX-file-processor-alist-default))
1934 (plist0 plist)
1935 ext cmd src buf (alt (car (cdr flist))))
1936 (if (and (re-search-forward
1937 (concat YaTeX-comment-prefix "\\s *\\(.*\\)$") peol t)
1938 (assoc (setq cmd (YaTeX-match-string 1))
1939 YaTeX-file-processor-alist))
1940 (setq src ;if processor is specified
1941 (concat file
1942 (cdr (assoc cmd YaTeX-file-processor-alist))))
1943 (while plist ;if processor is not specified
1944 (setq ext (cdr (car plist)))
1945 (if (and (string< "" (concat file ext))
1946 (file-exists-p
1947 (expand-file-name (concat file ext) basedir)))
1948 (setq cmd (car (car plist))
1949 src (concat file ext) plist nil))
1950 (setq plist (cdr plist)))
1951 (if (and (null src) alt YaTeX-create-file-prefix-g)
1952 (setq cmd alt
1953 src (concat file (cdr (assoc alt plist0))))))
1954 (if src ;if processor and src file found
1955 (let ((default-directory basedir))
1956 (cond
1957 ((stringp cmd)
1958 (let ((buf (concat "* " cmd " " src " *")))
1959 (YaTeX-system (concat cmd " " src) buf)
1960 t))
1961 ((eq t cmd)
1962 (let ((parent buffer-file-name))
1963 (funcall
1964 (cond
1965 (other 'YaTeX-switch-to-buffer-other-window)
1966 ((get-file-buffer src) 'goto-buffer-window)
1967 (t 'YaTeX-switch-to-buffer))
1968 src)
1969 (or (YaTeX-get-builtin "!")
1970 YaTeX-parent-file
1971 (setq YaTeX-parent-file parent))
1972 t))
1973 ((symbolp cmd)
1974 (cond
1975 ((symbol-function cmd)
1976 (funcall cmd src other)))
1977 t)))))))))
1979 (defun YaTeX-on-section-command-p (command)
1980 "Check if point is on the LaTeX command: COMMAND(regexp).
1981 Return nil if point is not on it. Otherwise return the
1982 number of argument position.
1983 Section command name is stored in match-data #1.
1984 Parsing information is stored to plist.
1985 Macros name stored to propname 'command.
1986 Macro's argument number stored to propname 'argc."
1987 (let ((p (point)) md (parg 0) (argc 1) word (grouping 0) (i 0)
1988 (ec+command (concat YaTeX-ec-regexp "\\(" command "\\)")))
1989 (setplist 'YaTeX-on-section-command-p nil)
1990 (while (setq i (string-match "\\\\(" command i))
1991 (setq grouping (1+ grouping) i (+ i 2)))
1992 (save-excursion
1993 (if (looking-at ec+command) nil
1994 (catch 'found ;caught value has no meaning
1995 ;;(1) looking at current position
1996 (and (looking-at command)
1997 (save-excursion
1998 (while (and (not (bobp)) (looking-at command))
1999 (forward-char -1))
2000 (looking-at ec+command))
2001 (goto-char (match-beginning 0))
2002 (throw 'found t))
2003 ;;(2) search command directly
2004 (skip-chars-forward "^{}[]")
2005 (and (YaTeX-re-search-active-backward
2006 ec+command
2007 YaTeX-comment-prefix nil t)
2008 (>= p (match-beginning 0))
2009 (throw 'found (goto-char (match-beginning 0))))
2010 ;;(3) search token
2011 (goto-char p)
2012 (while t
2013 (if (bobp) (throw 'found nil))
2014 (cond
2015 ((looking-at YaTeX-ec-regexp) (throw 'found t))
2016 ((looking-at "[[{]") nil)
2017 ((looking-at "[]}]")(condition-case nil (up-list -1) (error nil)))
2018 (t (skip-chars-backward " \t\r\n")))
2019 (skip-chars-backward (concat "^ \t\r\n{}[]" YaTeX-ec-regexp))
2020 (or (bobp) (forward-char -1)))))
2021 (if (and
2022 (looking-at (concat ec+command
2023 "\\(\\(\\[[^]]+\\]\\|([0-9,]+)\\)*\\)" ;optional arg
2024 ;"[ \t\n\r]*{[^}]+}")) ;arg braces
2025 "[ \t\n\r]*{[^}]*}")) ;arg braces
2026 (not (YaTeX-lookup-table
2027 (setq word (YaTeX-match-string 1)) 'singlecmd)))
2028 (progn
2029 (setq md (match-data))
2030 (skip-chars-forward "^{")
2031 (if (<= (point) p) (setq parg (1+ parg)))
2032 (setq argc
2033 (or (car (cdr (YaTeX-lookup-table word 'section)))
2034 argc))
2035 (put 'YaTeX-on-section-command-p 'argc argc)
2036 (put 'YaTeX-on-section-command-p 'command argc)
2037 (while (and (>= (setq argc (1- argc)) 0)
2038 (progn (skip-chars-forward " \t\n\r")
2039 (looking-at "{")))
2040 (forward-list 1)
2041 (if (<= (point) p) (setq parg (1+ parg))))
2042 (store-match-data md)
2043 (setq i (+ 2 grouping))
2044 (if (and (match-beginning i)
2045 (>= p (match-beginning i)) (< p (match-end i)))
2046 -1 ;return -1 if point is on optional arg
2047 (if (< p (point)) parg))
2048 )))))
2050 (defun YaTeX-on-maketitle-p ()
2051 "Check if point is on maketitle type commands.
2052 Call this function after YaTeX-on-section-command-p."
2053 (let ((p (point)))
2054 (save-excursion
2055 (or (= (char-after (point)) ?\\ )
2056 (progn
2057 (skip-chars-backward
2058 (concat "^" YaTeX-ec-regexp) (point-beginning-of-line))
2059 (or (bobp) (bolp) (backward-char 1))))
2060 (and (looking-at (concat YaTeX-ec-regexp YaTeX-TeX-token-regexp))
2061 (<= (match-beginning 0) p)
2062 (> (match-end 0) p)))))
2064 (defun YaTeX-on-begin-end-p ()
2065 (save-excursion
2066 (if (and (boundp 'in-leftright-p) in-leftright-p)
2067 ;; Dirty workaround for YaTeX-goto-corresponding-leftright 2003/3/28
2068 (let ((md (match-data))) ; for safety
2069 (if (looking-at YaTeX-ec-regexp)
2070 nil ; stay here
2071 (cond
2072 ((looking-at "\\w") (skip-chars-backward "A-Za-z"))
2073 ((looking-at "\\.()\\[\\]|") (forward-char -1)))
2074 (if (equal (char-after (1- (point)))
2075 (string-to-char YaTeX-ec))
2076 (forward-char -1))))
2077 ;(beginning-of-line)
2078 (if (equal (char-after (point)) ?\\) nil ;stay here
2079 (skip-chars-backward "^\n\\\\")
2080 (or (bolp) (forward-char -1))))
2081 (re-search-forward
2082 ;;"\\\\begin{\\([^}]+\\)}\\|\\\\end{\\([^}]+\\)}"
2083 (concat
2084 (YaTeX-replace-format-args
2085 (regexp-quote YaTeX-struct-begin)
2086 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" "")
2087 "\\|"
2088 (YaTeX-replace-format-args
2089 (regexp-quote YaTeX-struct-end)
2090 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" "")
2091 "\\|\\("
2092 YaTeX-ec-regexp ;;"[][()]\\)"
2093 "[][]\\)"
2095 (point-end-of-line) t)))
2097 (defun YaTeX-on-includes-p ()
2098 (save-excursion
2099 (beginning-of-line)
2100 (re-search-forward "\\(\\(include[^}]*\\)\\|\\(input\\)\\){[^}]*}"
2101 (point-end-of-line) t)))
2103 (defun YaTeX-on-comment-p (&optional sw)
2104 "Return t if current line is commented out.
2105 Optional argument SW t to treat all `%' lines as comment,
2106 even if on `%#' notation."
2107 (save-excursion
2108 (beginning-of-line)
2109 (skip-chars-forward "\\s ")
2110 (looking-at (if sw "%" "%[^#]"))))
2112 (defun YaTeX-on-BEGIN-END-p ()
2113 (save-excursion
2114 (let ((case-fold-search nil))
2115 (beginning-of-line)
2116 (re-search-forward
2117 "\\(%#BEGIN\\)\\|\\(%#END\\)" (point-end-of-line) t))))
2119 (defun YaTeX-goto-corresponding-* (arg)
2120 "Parse current line and call suitable function."
2121 (interactive "P")
2122 (let (mm)
2123 (cond
2124 ((YaTeX-goto-corresponding-label arg))
2125 ((YaTeX-goto-corresponding-environment))
2126 ((YaTeX-goto-corresponding-file-processor arg))
2127 ((YaTeX-goto-corresponding-file arg))
2128 ((YaTeX-goto-corresponding-BEGIN-END))
2129 ((and (setq mm (YaTeX-in-math-mode-p))
2130 (YaTeX-goto-corresponding-leftright)))
2131 ((and ;;mm YaTeX-use-AMS-LaTeX
2132 (YaTeX-goto-corresponding-paren)))
2133 ;;((and (string-match
2134 ;; YaTeX-equation-env-regexp ;to delay loading
2135 ;; (or (YaTeX-inner-environment t) "document"))
2136 ;; (YaTeX-goto-corresponding-leftright)))
2137 (t (message "I don't know where to go.")))))
2139 (defun YaTeX-goto-corresponding-*-other-window (arg)
2140 "Parse current line and call suitable function."
2141 (interactive "P")
2142 (cond
2143 ((YaTeX-goto-corresponding-label arg t))
2144 ;;((YaTeX-goto-corresponding-environment))
2145 ((YaTeX-goto-corresponding-file t))
2146 ;;((YaTeX-goto-corresponding-BEGIN-END))
2147 (t (message "I don't know where to go."))))
2149 (defun YaTeX-comment-region (alt-prefix)
2150 "Comment out region by '%'.
2151 If you call this function on the 'begin{}' or 'end{}' line,
2152 it comments out whole environment"
2153 (interactive "P")
2154 (if (not (YaTeX-on-begin-end-p))
2155 (comment-out-region
2156 (if alt-prefix
2157 (read-string "Insert prefix: ")
2158 YaTeX-comment-prefix))
2159 (YaTeX-comment-uncomment-env 'comment-out-region)))
2161 (defun YaTeX-uncomment-region (alt-prefix)
2162 "Uncomment out region by '%'."
2163 (interactive "P")
2164 (if (not (YaTeX-on-begin-end-p))
2165 (uncomment-out-region
2166 (if alt-prefix (read-string "Remove prefix: ")
2167 YaTeX-comment-prefix)
2168 (region-beginning) (region-end) YaTeX-uncomment-once)
2169 (YaTeX-comment-uncomment-env 'uncomment-out-region)))
2171 (defun YaTeX-comment-uncomment-env (func)
2172 "Comment or uncomment out one LaTeX environment switching function by FUNC."
2173 (let (beg (p (point)))
2174 (save-excursion
2175 (beginning-of-line)
2176 (setq beg (point))
2177 (YaTeX-goto-corresponding-environment)
2178 (beginning-of-line)
2179 (if (> p (point)) (setq beg (1+ beg)) (forward-char 1))
2180 (funcall func YaTeX-comment-prefix beg (point) YaTeX-uncomment-once)))
2181 (message "%sommented out current environment."
2182 (if (eq func 'comment-out-region) "C" "Un-c")))
2184 (defun YaTeX-comment-paragraph ()
2185 "Comment out current paragraph."
2186 (interactive)
2187 (save-excursion
2188 (cond
2189 ((YaTeX-on-begin-end-p)
2190 (beginning-of-line)
2191 (insert YaTeX-comment-prefix)
2192 (YaTeX-goto-corresponding-environment)
2193 (beginning-of-line)
2194 (insert YaTeX-comment-prefix))
2195 ((YaTeX-on-comment-p)
2196 (message "Already commented out."))
2197 (t
2198 (mark-paragraph)
2199 (if (looking-at paragraph-separate) (forward-line 1))
2200 (comment-out-region "%")))))
2202 (defun YaTeX-uncomment-paragraph ()
2203 "Uncomment current paragraph."
2204 (interactive)
2205 (save-excursion
2206 (if (YaTeX-on-begin-end-p)
2207 (let ((p (point-marker)))
2208 (YaTeX-goto-corresponding-environment)
2209 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once)
2210 (goto-char p)
2211 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once)
2212 (set-marker p nil))
2213 (if (YaTeX-on-comment-p)
2214 (let*((fill-prefix "")
2215 ;;append `^%' to head of paragraph delimiter.
2216 (paragraph-start
2217 (concat
2218 "^$\\|^%\\(" YaTeX-paragraph-separate "\\)"))
2219 (paragraph-separate paragraph-start))
2220 (mark-paragraph)
2221 (if (not (bobp)) (forward-line 1))
2222 (uncomment-out-region "%" nil nil YaTeX-uncomment-once))
2223 (message "This line is not a comment line.")))))
2225 (defun YaTeX-remove-prefix (prefix &optional once)
2226 "Remove prefix on current line as far as prefix detected. But
2227 optional argument ONCE makes deletion once."
2228 (interactive "sPrefix:")
2229 (beginning-of-line)
2230 (while (re-search-forward (concat "^" prefix) (point-end-of-line) t)
2231 (replace-match "")
2232 (if once (end-of-line))))
2234 (defun YaTeX-kill-some-pairs (predicate gofunc kill-contents)
2235 "Kill some matching pair.
2236 This function assumes that pairs occupy whole of each line where they resid."
2237 (if (not (funcall predicate)) nil
2238 (let ((b1 (match-beginning 0)) (e1 (match-end 0))
2239 b2 e2)
2240 (save-excursion
2241 (funcall gofunc)
2242 (funcall predicate) ;get match data
2243 (if (< (point) e1) ;if currently on begin-line
2244 (progn
2245 (setq b2 b1 e2 e1
2246 b1 (match-beginning 0) e1 (match-end 0))
2247 (goto-char e2)) ;goto end-line's end
2248 (setq b2 (match-beginning 0)
2249 e2 (match-end 0))
2250 (goto-char e2)) ;now e2 has surely end-line's end
2251 (skip-chars-forward " \t")
2252 (and (eolp)
2253 (not (eobp))
2254 (setq e2 (1+ (point))))
2255 (if (not kill-contents)
2256 (kill-region
2257 (progn
2258 (goto-char b2)
2259 (skip-chars-backward " \t%")
2260 (if (bolp) (point) b2))
2261 e2))
2262 (goto-char b1)
2263 (skip-chars-backward " \t%")
2264 (if (not kill-contents)
2265 (progn
2266 (kill-append
2267 (buffer-substring
2268 (setq b1 (if (bolp) (point) b1))
2269 (setq e1
2270 (progn
2271 (goto-char e1)
2272 (while (looking-at "{\\| \t")
2273 (forward-list 1))
2274 (skip-chars-forward " \t")
2275 (if (and (eolp) (not (eobp)))
2276 (1+ (point))
2277 (point)))))
2278 t)
2279 (delete-region b1 e1))
2280 (kill-region
2281 (if (bolp) (point) b1)
2282 e2)))
2283 t)))
2285 (defun YaTeX-kill-section-command (point kill-all)
2286 "Kill section-type command at POINT leaving its last argument.
2287 Non-nil for the second argument kill its last argument too."
2288 (let ((cmd (get 'YaTeX-on-section-command-p 'command))
2289 (argc (get 'YaTeX-on-section-command-p 'argc))
2290 beg (end (make-marker)))
2291 (save-excursion
2292 (goto-char point)
2293 (or (looking-at YaTeX-ec-regexp)
2294 (progn
2295 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
2296 (forward-char -1)))
2297 (setq beg (point))
2298 (skip-chars-forward "^{")
2299 (while (> (setq argc (1- argc)) 0)
2300 (skip-chars-forward "^{")
2301 (forward-list 1))
2302 (kill-region beg (point))
2303 (forward-list 1)
2304 (set-marker end (point))
2305 (if kill-all
2306 (progn
2307 (kill-append (buffer-substring beg end) nil)
2308 (delete-region beg end))
2309 (goto-char beg)
2310 (kill-append
2311 (buffer-substring
2312 (point) (progn (skip-chars-forward "^{" end) (1+ (point))))
2313 nil)
2314 (delete-region beg (1+ (point)))
2315 (goto-char end)
2316 (set-marker end nil)
2317 (kill-append (buffer-substring (point) (1- (point))) nil)
2318 (delete-backward-char 1)))))
2320 (defun YaTeX-kill-paren (kill-contents)
2321 "Kill parentheses leaving its contents.
2322 But kill its contents if the argument KILL-CONTENTS is non-nil."
2323 (interactive "P")
2324 (let (p bsl (backslash-syntax (char-to-string (char-syntax ?\\)))
2325 (md (match-data)))
2326 (unwind-protect
2327 (save-excursion
2328 (modify-syntax-entry ?\\ " ")
2329 (if (looking-at "\\s(\\|\\(\\s)\\)")
2330 (progn
2331 (if (match-beginning 1)
2332 (up-list -1))
2333 (if (and (> (point) (point-min))
2334 (= (char-after (1- (point))) ?\\ ))
2335 (setq p (1- (point)) bsl t)
2336 (setq p (point)))
2337 (forward-list 1)
2338 ;(YaTeX-goto-open-paren t)
2339 (if kill-contents (delete-region p (point))
2340 (backward-delete-char 1)
2341 (cond
2342 ((save-excursion
2343 (forward-char -2)
2344 (looking-at (concat YaTeX-ec-regexp "/")))
2345 (backward-delete-char 2))
2346 ((= (char-after (1- (point))) ?\\)
2347 (backward-delete-char 1)))
2348 (goto-char p)
2349 (if (looking-at
2350 (concat "{" YaTeX-ec-regexp
2351 YaTeX-command-token-regexp "+"
2352 "\\s +"))
2353 (delete-region (point) (match-end 0))
2354 (delete-char 1)
2355 (if bsl (delete-char 1))))
2356 t)))
2357 (modify-syntax-entry ?\\ backslash-syntax)
2358 (store-match-data md))))
2360 (defvar YaTeX-read-environment-history nil "Holds history of environments.")
2361 (put 'YaTeX-read-environment-history 'no-default t)
2362 (defun YaTeX-read-environment (prompt &optional predicate must-match initial)
2363 "Read a LaTeX environment name with completion."
2364 (YaTeX-sync-local-table 'tmp-env-table)
2365 (completing-read-with-history
2366 prompt
2367 (append tmp-env-table user-env-table env-table)
2368 predicate must-match initial
2369 'YaTeX-read-environment-history))
2371 (defvar YaTeX-read-section-history nil "Holds history of section-types.")
2372 (put 'YaTeX-read-section-history 'no-default t)
2373 (defun YaTeX-read-section (prompt &optional predicate initial)
2374 "Read a LaTeX section-type command with completion."
2375 (YaTeX-sync-local-table 'tmp-section-table)
2376 (let ((minibuffer-completion-table
2377 (append tmp-section-table user-section-table section-table)))
2378 (read-from-minibuffer-with-history
2379 prompt initial YaTeX-section-completion-map nil
2380 'YaTeX-read-section-history)))
2382 (defun YaTeX-read-section-with-overview ()
2383 "Read sectioning command with overview.
2384 This function refers a local variable `source-window' in YaTeX-make-section,
2385 because this function is called with no argument."
2386 (interactive)
2387 (require 'yatexsec) ;some case needs this
2388 (if (> (minibuffer-depth) 1)
2389 (error "Too many minibuffer levels for overview."))
2390 (let ((sw (selected-window))
2391 (minibuffer-max-depth nil) ; for XEmacs20
2392 (enable-recursive-minibuffers t) sect)
2393 (unwind-protect
2394 (progn
2395 (select-window source-window)
2396 (setq sect (YaTeX-read-section-in-minibuffer
2397 "Sectioning(Up=C-p, Down=C-n, Help=?): "
2398 YaTeX-sectioning-level (YaTeX-section-overview))))
2399 (select-window sw))
2400 (YaTeX-minibuffer-erase)
2401 (insert sect)
2402 (exit-minibuffer)))
2404 (defvar YaTeX-read-fontsize-history nil "Holds history of font designator.")
2405 (put 'YaTeX-read-fontsize-history 'no-default t)
2406 (defun YaTeX-read-fontsize (prompt &optional predicate must-match initial)
2407 "Read a LaTeX font changing command with completion."
2408 (YaTeX-sync-local-table 'tmp-fontsize-table)
2409 (completing-read-with-history
2410 prompt (append tmp-fontsize-table user-fontsize-table fontsize-table)
2411 predicate must-match initial 'YaTeX-read-fontsize-history))
2413 (defun YaTeX-change-environment ()
2414 "Change the name of environment."
2415 (interactive)
2416 (if (not (YaTeX-on-begin-end-p)) nil
2417 (save-excursion
2418 (let (p env newenv (m1 (match-beginning 1)) (m2 (match-beginning 2)))
2419 (setq env (if m1 (YaTeX-buffer-substring m1 (match-end 1))
2420 (YaTeX-buffer-substring m2 (match-end 2))))
2421 (goto-char (match-beginning 0))
2422 (set-mark-command nil)
2423 (YaTeX-goto-corresponding-environment)
2424 (setq newenv (YaTeX-read-environment
2425 (format "Change environment `%s' to: " env)))
2426 (cond
2427 ((string= newenv "") (message "Change environment cancelled."))
2428 ((string= newenv env) (message "No need to change."))
2429 (t
2430 (search-forward (concat "{" env) (point-end-of-line) t)
2431 (replace-match (concat "{" newenv) t)
2432 (exchange-point-and-mark)
2433 (search-forward (concat "{" env) (point-end-of-line) t)
2434 (replace-match (concat "{" newenv) t)))
2435 t))))
2437 (defun YaTeX-change-section ()
2438 "Change section-type command."
2439 (interactive)
2440 (let*((where (YaTeX-on-section-command-p YaTeX-command-token-regexp))
2441 (p (point)) (cmd (YaTeX-match-string 1))
2442 (beg (make-marker)) (end (make-marker)) old new)
2443 (if (null where) nil
2444 (unwind-protect
2445 (let ((source-window (selected-window)))
2446 (cond
2447 ((equal where 0);;if point is on section command
2448 (set-marker beg (match-beginning 1))
2449 (set-marker end (match-end 1))
2450 (goto-char beg) ;beginning of the command
2451 (setq new (YaTeX-read-section
2452 (format "Change `%s' to: " cmd) nil)
2453 old cmd))
2455 ((= where -1);;if point is on a optional parameter
2456 (set-marker beg (match-beginning 2))
2457 (skip-chars-forward "^{")
2458 (set-marker end (point))
2459 (goto-char p)
2460 (setq new
2461 (if (fboundp (intern-soft (concat YaTeX-addin-prefix cmd)))
2462 (YaTeX-addin cmd)
2463 (concat "["
2464 (read-string
2465 (format "Change `%s' to: "
2466 (setq old (YaTeX-buffer-substring
2467 (1+ beg) (1- end)))))
2468 "]"))))
2470 ((> where 0);;if point is in arguments' braces
2471 (or (looking-at "{")
2472 (progn (skip-chars-backward "^{") (forward-char -1)))
2473 (set-marker beg (1+ (point)))
2474 (forward-list 1)
2475 (forward-char -1)
2476 (set-marker end (point))
2477 (setq old (YaTeX-buffer-substring beg end))
2478 (goto-char p)
2479 (if (> (length old) 40)
2480 (setq old (concat (substring old 0 12) "..."
2481 (substring old -12))))
2482 (setq new
2483 (if (intern-soft (concat "YaTeX::" cmd))
2484 (funcall (intern-soft (concat "YaTeX::" cmd)) where)
2485 (read-string (format "Change `%s' to: " old)))))
2486 ) ;cond
2487 (if (string= old new)
2488 nil ;do not replace
2489 (delete-region beg end)
2490 (goto-char beg)
2491 (insert-before-markers new)))
2492 (set-marker beg nil)
2493 (set-marker end nil))
2494 ;;(goto-char (marker-position p))
2495 new)))
2497 (defun YaTeX-change-fontsize ()
2498 "Change large-type command."
2499 (let ((lt (append tmp-fontsize-table user-fontsize-table fontsize-table))
2500 (p (point)) large old new beg end)
2501 ;;(and (looking-at "}") (up-list -1))
2502 ;;(and (looking-at "{") (forward-char 1))
2503 ;;Is above convenient?
2504 (save-excursion
2505 (or (looking-at YaTeX-ec-regexp)
2506 (progn
2507 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
2508 (forward-char -1)))
2509 (cond
2510 ((and
2511 (looking-at
2512 (concat YaTeX-ec-regexp "\\(" YaTeX-TeX-token-regexp "\\)"))
2513 (< p (match-end 0))
2514 (assoc (setq old (YaTeX-match-string 1)) lt))
2515 (goto-char p)
2516 (setq beg (match-beginning 1) end (match-end 1) ;save match position
2517 new (completing-read
2518 (format "Change font/size `%s' to : " old) lt))
2519 (delete-region beg end)
2520 (goto-char beg)
2521 (insert-before-markers new)
2522 new)
2523 (t nil)
2524 ))))
2526 (defun YaTeX-change-math-image ()
2527 "Change with image completion."
2528 (let (maketitle memberp beg end)
2529 (if (and (YaTeX-on-maketitle-p)
2530 (progn
2531 (setq maketitle (substring (YaTeX-match-string 0) 1))
2532 (setq memberp (YaTeX-math-member-p maketitle))))
2533 (let ((last-command-char (string-to-char (car memberp))))
2534 (setq beg (match-beginning 0) end (match-end 0))
2535 (delete-region beg end)
2536 (YaTeX-math-insert-sequence t (cdr memberp))))))
2538 (defun YaTeX-kill-* (&optional arg)
2539 "Parse current line and call suitable function.
2540 Non-nil for ARG kills its contents too."
2541 (interactive "P")
2542 (cond
2543 ((YaTeX-kill-some-pairs 'YaTeX-on-begin-end-p
2544 'YaTeX-goto-corresponding-environment arg))
2545 ((YaTeX-kill-some-pairs 'YaTeX-on-BEGIN-END-p
2546 'YaTeX-goto-corresponding-BEGIN-END arg))
2547 ((YaTeX-on-section-command-p YaTeX-command-token-regexp);on any command
2548 (YaTeX-kill-section-command (match-beginning 0) arg))
2549 ((YaTeX-kill-paren arg))
2550 (t (message "I don't know what to kill."))))
2552 (defun YaTeX-change-* ()
2553 "Parse current line and call suitable function."
2554 (interactive)
2555 (cond
2556 ((YaTeX-change-parentheses))
2557 ((YaTeX-change-environment))
2558 ((YaTeX-change-section))
2559 ((YaTeX-change-fontsize))
2560 ((YaTeX-change-math-image))
2561 (t (message "I don't know what to change."))))
2563 ;;;
2564 ;Check availability of add-in functions
2565 ;;;
2566 (cond
2567 ((featurep 'yatexadd) nil) ;Already provided.
2568 ((progn (load "yatexadd" t) (featurep 'yatexadd)) nil)
2569 (t (message "YaTeX add-in functions not supplied.")))
2571 (defun YaTeX-addin (name)
2572 "Check availability of addin function and call it if exists."
2573 (if (and (not (get 'YaTeX-generate 'disabled))
2574 (intern-soft (concat YaTeX-addin-prefix name))
2575 (fboundp (intern-soft (concat YaTeX-addin-prefix name))))
2576 (let ((s (funcall (intern (concat YaTeX-addin-prefix name)))))
2577 (if (stringp s) s ""))
2578 "")) ;Add in function is not bound.
2581 (defun YaTeX-on-item-p (&optional point)
2582 "Return t if POINT (default is (point)) is on \\item."
2583 (let ((p (or point (point))))
2584 (save-excursion
2585 (goto-char p)
2586 (end-of-line)
2587 (setq p (point))
2588 (re-search-backward YaTeX-paragraph-delimiter nil t)
2589 (re-search-forward YaTeX-item-regexp p t))))
2591 (defun YaTeX-in-verb-p (&optional point)
2592 "Check if POINT is in verb or verb*. Default of POINT is (point)."
2593 (setq point (or point (point)))
2594 (save-excursion
2595 (let ((md (match-data)))
2596 (goto-char point)
2597 (unwind-protect
2598 (if (not (re-search-backward
2599 (concat YaTeX-ec-regexp
2600 "\\(" YaTeX-verb-regexp "\\)"
2601 "\\([^-A-Za-z_*]\\)")
2602 (point-beginning-of-line) t))
2603 nil
2604 (goto-char (match-end 2))
2605 (skip-chars-forward
2606 (concat "^" (YaTeX-buffer-substring
2607 (match-beginning 2) (match-end 2))))
2608 (and (< (match-beginning 2) point) (< (1- point) (point))))
2609 (store-match-data md)))))
2611 (defun YaTeX-literal-p (&optional point)
2612 "Check if POINT is in verb or verb* or verbatime environment family.
2613 Default of POINT is (point)."
2614 (let ((md (match-data)))
2615 (unwind-protect
2616 (cond
2617 ((equal YaTeX-ec "\\") ;maybe LaTeX
2618 (save-excursion
2619 (and point (goto-char point))
2620 (or (YaTeX-in-verb-p (point))
2621 (and (not (looking-at "\\\\end{verb"))
2622 (YaTeX-quick-in-environment-p
2623 YaTeX-verbatim-environments))))))
2624 (store-match-data md))))
2626 (defun YaTeX-in-environment-p (env)
2627 "Return if current LaTeX environment is ENV.
2628 ENV is given in the form of environment's name or its list."
2629 (let ((md (match-data)) (nest 0) p envrx)
2630 (cond
2631 ((atom env)
2632 (setq envrx
2633 (concat "\\("
2634 (regexp-quote
2635 (YaTeX-replace-format-args
2636 YaTeX-struct-begin env "" ""))
2637 "\\)\\|\\("
2638 (regexp-quote
2639 (YaTeX-replace-format-args
2640 YaTeX-struct-end env "" ""))
2641 "\\)"))
2642 (save-excursion
2643 (setq p (catch 'open
2644 (while (YaTeX-re-search-active-backward
2645 envrx YaTeX-comment-prefix nil t)
2646 (if (match-beginning 2)
2647 (setq nest (1+ nest))
2648 (setq nest (1- nest)))
2649 (if (< nest 0)
2650 (throw 'open (cons env (match-beginning 0)))))))))
2651 ((listp env)
2652 (setq p
2653 (or (YaTeX-in-environment-p (car env))
2654 (and (cdr env) (YaTeX-in-environment-p (cdr env)))))))
2655 (store-match-data md)
2656 p;(or p (YaTeX-in-verb-p (match-beginning 0)))
2657 ))
2659 (defun YaTeX-quick-in-environment-p (env)
2660 "Check quickly but unsure if current environment is ENV.
2661 ENV is given in the form of environment's name or its list.
2662 This function returns correct result only if ENV is NOT nested."
2663 (save-excursion
2664 (let ((md (match-data)) m0 (p (point)) rc clfound)
2665 (cond
2666 ((listp env)
2667 (or (YaTeX-quick-in-environment-p (car env))
2668 (and (cdr env) (YaTeX-quick-in-environment-p (cdr env)))))
2669 (t
2670 (unwind-protect
2671 (if (prog1
2672 (YaTeX-search-active-backward
2673 (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
2674 YaTeX-comment-prefix nil t)
2675 (setq m0 (match-beginning 0)))
2676 (if (YaTeX-search-active-forward
2677 (YaTeX-replace-format-args
2678 YaTeX-struct-end env)
2679 YaTeX-comment-prefix p t nil)
2680 nil ;if \end{env} found, return nil
2681 (cons env m0))) ;else, return meaningful values
2682 (store-match-data md)))))))
2684 ;; Filling \item
2685 (defun YaTeX-remove-trailing-comment (start end)
2686 "Remove trailing comment from START to end."
2687 (save-excursion
2688 (let ((trcom (concat YaTeX-comment-prefix "$")))
2689 (goto-char start)
2690 (while (re-search-forward trcom end t)
2691 (if (/= (char-after (1- (match-beginning 0))) ?\\ )
2692 (replace-match "\\1"))))))
2694 (defvar YaTeX-itemize-withlabel-max-indent-depth 8)
2695 (defun YaTeX-get-item-info (&optional recent thisenv)
2696 "Return the list of the beginning of \\item and column of its item.
2697 If it seems to be outside of itemizing environment, just return nil.
2698 Non-nil for optional argument RECENT refers recent \\item.
2699 Optional second argument THISENV omits calling YaTeX-inner-environment."
2700 (save-excursion
2701 (let* ((p (point)) env e0 c cc md
2702 (bndry (and (setq env (or thisenv (YaTeX-inner-environment t)))
2703 (get 'YaTeX-inner-environment 'point))))
2704 (end-of-line)
2705 (if (if recent
2706 (catch 'found
2707 (while (YaTeX-re-search-active-backward
2708 YaTeX-item-regexp YaTeX-comment-prefix bndry t)
2709 (setq md (match-data))
2710 (YaTeX-inner-environment t)
2711 (store-match-data md)
2712 (if (= bndry (get 'YaTeX-inner-environment 'point))
2713 (throw 'found t))))
2714 (goto-char bndry)
2715 (YaTeX-re-search-active-forward
2716 YaTeX-item-regexp YaTeX-comment-prefix p t))
2717 (progn
2718 (goto-char (match-end 0))
2719 ;(setq c (current-column))
2720 (if (string-match "desc" env)
2721 (setq c 6)
2722 (setq cc (current-column))
2723 (if (equal (following-char) ?\[) (forward-list 1))
2724 (if (< (- (current-column) cc)
2725 YaTeX-itemize-withlabel-max-indent-depth)
2726 (setq c 0)
2727 (move-to-column cc)
2728 (setq c YaTeX-itemize-withlabel-max-indent-depth)))
2729 (skip-chars-forward " \t" (point-end-of-line))
2730 (list (point-beginning-of-line) (+ c (current-column))))))))
2732 (defun YaTeX-fill-item ()
2733 "Fill item in itemize environment."
2734 (interactive)
2735 (save-excursion
2736 (let* ((p (point))
2737 (item-term (concat
2738 "\\(^[ \t]*$\\)\\|" YaTeX-item-regexp "\\|\\("
2739 YaTeX-ec-regexp "\\(begin\\|end\\)\\)"))
2740 ;;This value depends on LaTeX.
2741 fill-prefix start col
2742 (info (YaTeX-get-item-info t)))
2743 (if (null info) nil ;not on \item, do nothing
2744 (setq start (car info)
2745 col (car (cdr info)))
2746 (save-excursion
2747 (if (re-search-backward "^\\s *$" start t)
2748 ;;if separated from \item line, isolate this block
2749 (progn
2750 (setq start (1+ (match-end 0)))
2751 (goto-char start)
2752 (skip-chars-forward " \t")
2753 (delete-region (point) start) ;is this your favor???
2754 (indent-to col))))
2755 (beginning-of-line)
2756 (if (<= (save-excursion
2757 (re-search-forward
2758 (concat "\\\\end{\\|\\\\begin{\\|^[ \t]*$") nil t)
2759 (match-beginning 0))
2760 p)
2761 (progn (message "Not on itemize.") nil)
2762 (end-of-line)
2763 (newline)
2764 (indent-to col)
2765 (setq fill-prefix
2766 (YaTeX-buffer-substring (point-beginning-of-line)(point)))
2767 (beginning-of-line)
2768 (delete-region (point) (progn (forward-line 1) (point)))
2769 (re-search-forward item-term nil 1)
2770 (YaTeX-remove-trailing-comment start (point))
2771 (beginning-of-line)
2772 (push-mark (point) t)
2773 (goto-char start)
2774 (forward-line 1)
2775 (while (< (point) (mark))
2776 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
2777 (forward-line 1))
2778 (fill-region-as-paragraph start (mark))
2779 (if NTT-jTeX
2780 (while (progn(forward-line -1)(end-of-line) (> (point) start))
2781 (insert ?%)))
2782 (pop-mark))))))
2784 (defun YaTeX-fill-paragraph (arg)
2785 "YaTeX adjustment function for fill-paragraph.
2786 *Protect \\verb from unexpected broken up."
2787 (interactive "P")
2788 (cond
2789 ((not (eq major-mode 'yatex-mode)) (fill-paragraph arg))
2790 ((YaTeX-quick-in-environment-p YaTeX-fill-inhibit-environments) nil)
2791 ((YaTeX-in-math-mode-p) nil)
2792 (t
2793 (save-excursion
2794 (let*((verbrex (concat YaTeX-ec-regexp
2795 "\\(" YaTeX-verb-regexp "\\)" ;match#1
2796 "\\(.\\).*\\(\\2\\)")) ;match #2 and #3
2797 (tilderex (concat "\\("
2798 YaTeX-kanji-regexp "~"
2799 "\\)" YaTeX-ec-regexp
2800 "\\|\\("
2801 "~" YaTeX-kanji-regexp
2802 "\\)"))
2803 (p (point)) ii end poslist spacelist lenlist b e n
2804 (fill-prefix fill-prefix)
2805 (inenv (or (YaTeX-inner-environment t) "document"))
2806 (border (get 'YaTeX-inner-environment 'point)))
2807 (cond
2808 ((save-excursion (beginning-of-line) ;if point is on the first
2809 (setq end (point)) ;non-whitespace char
2810 (skip-chars-forward " \t")
2811 (equal (point) p))
2812 (setq fill-prefix (YaTeX-buffer-substring p end)))
2813 ((and ;;(not YaTeX-emacs-19)
2814 (string-match YaTeX-itemizing-env-regexp inenv)
2815 (setq ii (YaTeX-get-item-info)))
2816 (save-excursion
2817 (beginning-of-line)
2818 (indent-to-column (car (cdr ii)))
2819 (setq fill-prefix
2820 (YaTeX-buffer-substring (point) (point-beginning-of-line)))
2821 (delete-region (point) (progn (beginning-of-line) (point))))))
2822 (cond
2823 ((string-match "tabular" inenv)
2824 (let ((b (point-beginning-of-line))
2825 (e (point-end-of-line)))
2826 (if (re-search-backward
2827 "&\\|\\\\\\\\\\|\\\\\\(begin\\|end\\){" border t)
2828 (setq b (if (match-beginning 1)
2829 (progn (forward-line 1) (point))
2830 (point-beginning-of-line))))
2831 (goto-char p)
2832 (if (re-search-forward
2833 "&\\|\\\\\\\\\\|\\\\\\(end\\|begin\\){" nil t)
2834 (setq e (if (match-beginning 1)
2835 (progn (forward-line -1)
2836 (point-end-of-line))
2837 (match-beginning 0))))
2838 (set-mark e)
2839 (goto-char b)))
2840 (t
2841 (mark-paragraph)))
2842 (save-restriction
2843 (narrow-to-region (region-beginning) (region-end))
2844 (YaTeX-remove-trailing-comment (point-min) (point-max))
2845 ;; First, replace spaces in verb to _ temporarily.
2846 (goto-char (point-min))
2847 (while (YaTeX-re-search-active-forward
2848 verbrex YaTeX-comment-prefix (point-max) t)
2849 (setq end (match-beginning 3))
2850 (goto-char (match-beginning 2))
2851 (while (re-search-forward "\\s " end t)
2852 (setq poslist (cons (make-marker) poslist)
2853 spacelist (cons (preceding-char) spacelist)
2854 lenlist (cons 1 lenlist))
2855 (replace-match "_")
2856 (set-marker (car poslist) (match-beginning 0))))
2857 ;; Second, replace "表~\ref{...}" to "\\\ref{...}"
2858 (goto-char (point-min))
2859 (while (YaTeX-re-search-active-forward
2860 tilderex YaTeX-comment-prefix (point-max) t)
2861 (if (match-beginning 1)
2862 (setq b (match-beginning 1) e (match-end 1) n 1)
2863 (setq b (match-beginning 2) e (match-end 2) n 2))
2864 (setq poslist (cons (make-marker) poslist)
2865 spacelist (cons (YaTeX-match-string n) spacelist)
2866 lenlist (cons 2 lenlist))
2867 (goto-char (match-beginning 0))
2868 (delete-region (point) e)
2869 (insert YaTeX-ec YaTeX-ec) ;set-marker should be here
2870 (set-marker (car poslist) b))
2871 ;;(fill-paragraph arg)
2872 (fill-region-as-paragraph (point-min) (point-max) arg)
2873 (while spacelist
2874 (goto-char (car poslist))
2875 (set-marker (car poslist) nil)
2876 (and (eolp) (skip-chars-forward "\n\t "))
2877 (delete-char (car lenlist))
2878 (insert (car spacelist))
2879 (setq spacelist (cdr spacelist)
2880 poslist (cdr poslist)
2881 lenlist (cdr lenlist)))
2882 (goto-char (point-min))
2883 (forward-word 1)
2884 (beginning-of-line)
2885 (while (re-search-forward "\\\\\\([a-z]*ref\\|cite\\){" nil t)
2886 (if (< (point-end-of-line)
2887 (save-excursion (forward-char -1) (forward-list 1) (point)))
2888 (progn (end-of-line)
2889 (if (save-excursion
2890 (backward-word 1)
2891 (looking-at "[^0-9A-z!-)]"))
2892 (insert YaTeX-comment-prefix)))))
2893 ;; Nonbreak space `~'
2894 (goto-char (point-min))
2895 (while (YaTeX-re-search-active-forward
2896 "~\\(\\s *\\)$" YaTeX-comment-prefix (point-max) t)
2897 (delete-region (match-beginning 1) (match-end 1))
2898 (insert YaTeX-comment-prefix))
2899 (goto-char (point-min))
2900 (if (and NTT-jTeX (looking-at "[ \t]\\|^$"))
2901 (progn
2902 (goto-char (point-min))
2903 (while (not (eobp))
2904 (end-of-line)
2905 (or (bolp)
2906 (save-excursion
2907 (backward-word 1)
2908 (looking-at "[0-9A-z!-)]")) ;is not japanese string
2909 (progn (setq p (point)) (insert YaTeX-comment-prefix)))
2910 (forward-line 1))
2911 (goto-char p)
2912 (if (looking-at "%") (delete-char 1)) ;remove last inserted `%'
2913 ))))))))
2915 (if (fboundp 'YaTeX-saved-indent-new-comment-line) nil
2916 (fset 'YaTeX-saved-indent-new-comment-line
2917 (symbol-function 'indent-new-comment-line))
2918 (fset 'indent-new-comment-line 'YaTeX-indent-new-comment-line))
2920 (defun YaTeX-indent-new-comment-line (&optional soft)
2921 "Tuned `indent-new-comment-line' function for yatex.
2922 See the documentation of `YaTeX-saved-indent-new-comment-line'."
2923 (interactive)
2924 (cond
2925 ((or (not (memq major-mode '(yatex-mode yahtml-mode)))
2926 (string-match
2927 "document"
2928 (or (and (boundp 'inenv) inenv)
2929 (or (YaTeX-inner-environment t) "document"))))
2930 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft))))
2931 ; ((and (eq major-mode 'yahtml-mode)
2932 ; (string-match
2933 ; "^[Pp][Rr][Ee]" (yahtml-inner-environment-but "^[Aa]\\b" t)))
2934 ; (yahtml-indent-new-commnet-line))
2935 ((and (eq major-mode 'yatex-mode) ;1997/2/4
2936 (YaTeX-in-math-mode-p)) nil) ;1996/12/30
2937 (t (let (fill-prefix)
2938 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft)))))))
2940 (defun YaTeX-fill-* ()
2941 "Fill paragraph according to its condition."
2942 (interactive)
2943 (cond
2944 ((YaTeX-fill-item))
2945 ))
2947 ;; Accent completion
2948 (defun YaTeX-read-accent-char (x)
2949 "Read char in accent braces."
2950 (let ((c (read-char)))
2951 (concat
2952 (if (and (or (= c ?i) (= c ?j))
2953 (not (string-match (regexp-quote x) "cdb")))
2954 "\\" "")
2955 (char-to-string c))))
2957 (defun YaTeX-make-accent ()
2958 "Make accent usage."
2959 (interactive)
2960 (message "1:` 2:' 3:^ 4:\" 5:~ 6:= 7:. u v H t c d b")
2961 (let ((c (read-char))(case-fold-search nil))
2962 (setq c (cond ((and (> c ?0) (< c ?8))
2963 (substring "`'^\"~=." (1- (- c ?0)) (- c ?0)))
2964 ((= c ?h) "H")
2965 (t (char-to-string c))))
2966 (if (not (string-match c "`'^\"~=.uvHtcdb")) nil
2967 (insert "\\" c "{}")
2968 (backward-char 1)
2969 (insert (YaTeX-read-accent-char c))
2970 (if (string= c "t") (insert (YaTeX-read-accent-char c)))
2971 (forward-char 1))))
2973 ;; Indentation
2974 (defun YaTeX-current-indentation ()
2975 "Return the indentation of current environment."
2976 (save-excursion
2977 ;;(beginning-of-line)
2978 (if (YaTeX-beginning-of-environment t)
2979 (goto-char (get 'YaTeX-inner-environment 'point))
2980 (forward-line -1)
2981 (beginning-of-line)
2982 (skip-chars-forward " \t"))
2983 (current-column)))
2985 (defun YaTeX-previous-line-indentation ()
2986 (save-excursion
2987 (forward-line -1)
2988 (skip-chars-forward " \t")
2989 (current-column)))
2991 (defvar YaTeX-noindent-env-regexp "verbatim\\*?\\|alltt"
2992 "*Regexp of environment names that should begin with no indentation.
2993 All verbatime-like environment name should match with.")
2994 (defun YaTeX-indent-line ()
2995 "Indent corrent line referrin current environment."
2996 (interactive)
2997 (let ((indent-relative
2998 (function
2999 (lambda (&optional additional)
3000 (YaTeX-reindent
3001 (+ (YaTeX-current-indentation)
3002 (or additional 0)
3003 YaTeX-environment-indent)))))
3004 sect depth iteminfo (p (point)) pp (peol (point-end-of-line)) begend
3005 ;;inenv below is sometimes defined in YaTeX-indent-new-comment-line
3006 (inenv (or (and (boundp 'inenv) inenv) (YaTeX-inner-environment t))))
3007 ;;(if NTT-jTeX ;;Do you need this section?
3008 ;; (save-excursion
3009 ;; (end-of-line)
3010 ;; (let ((p (point)))
3011 ;; (forward-line -1)
3012 ;; (end-of-line)
3013 ;; (or (= p (point))
3014 ;; (progn (backward-char (length YaTeX-comment-prefix))
3015 ;; (not (looking-at (regexp-quote YaTeX-comment-prefix))))
3016 ;; (progn
3017 ;; (skip-chars-backward YaTeX-comment-prefix)
3018 ;; (kill-line))))))
3019 (or inenv (setq inenv "document")) ;is the default environment
3020 (cond
3021 ((and
3022 (prog1 (YaTeX-on-begin-end-p)
3023 (setq begend (match-beginning 0)))
3024 (or (match-beginning 2) ;if \end
3025 (and (match-beginning 3) ;if \) \]
3026 (= (char-syntax (char-after (1+ (match-beginning 3)))) ?\)))))
3027 (YaTeX-reindent
3028 (save-excursion
3029 (YaTeX-goto-corresponding-environment)
3030 (current-column))))
3031 ;; on the begining of verbatime line, remove all indentation
3032 ((and begend ;; match-beginning 0 of \begin
3033 YaTeX-noindent-env-regexp
3034 (stringp YaTeX-noindent-env-regexp)
3035 (save-excursion
3036 (and ;; if the \begin is the first declaration of this line
3037 (progn (beginning-of-line) (skip-chars-forward " \t")
3038 (= begend (point)))
3039 (progn
3040 (goto-char begend)
3041 (looking-at
3042 (concat YaTeX-ec-regexp
3043 "begin{\\(" YaTeX-noindent-env-regexp "\\)}"))))))
3044 (save-excursion
3045 (goto-char begend)
3046 (delete-region (point) (point-beginning-of-line))))
3047 ((string-match YaTeX-equation-env-regexp inenv)
3048 (YaTeX-indent-line-equation)) ;autoload-ed from yatexenv
3049 (;(YaTeX-in-environment-p '("itemize" "enumerate" "description" "list"))
3050 (string-match YaTeX-itemizing-env-regexp inenv)
3051 ;;(YaTeX-on-item-p) ??
3052 ;;(setq iteminfo (YaTeX-get-item-info t))
3053 (if (save-excursion
3054 (beginning-of-line)
3055 (re-search-forward YaTeX-item-regexp peol t))
3056 (progn
3057 (save-excursion
3058 (goto-char (1+ (match-beginning 0)))
3059 (setq depth
3060 (* YaTeX-environment-indent
3061 (cond
3062 ((looking-at "subsubsub") 3)
3063 ((looking-at "subsub") 2)
3064 ((looking-at "sub") 1)
3065 (t 0)))))
3066 (funcall indent-relative depth))
3067 (YaTeX-reindent (or (car (cdr (YaTeX-get-item-info t inenv)))
3068 (+ (save-excursion
3069 (beginning-of-line)
3070 (YaTeX-current-indentation))
3071 YaTeX-environment-indent))))
3073 ((YaTeX-literal-p) ;verbatims
3074 (tab-to-tab-stop))
3075 ((string-match "\\(tabular\\|array\\)" inenv) ;1.73
3076 (let ((n 1))
3077 (condition-case err
3078 (save-excursion
3079 (beginning-of-line)
3080 (skip-chars-forward "[ \t]")
3081 ;;(if (looking-at "&") (forward-char 1))
3082 (require 'yatexenv)
3083 (setq n (car (YaTeX-array-what-column-internal))))
3084 (error nil))
3085 (YaTeX-reindent
3086 (+ (YaTeX-current-indentation)
3087 YaTeX-environment-indent
3088 (* (1- n) YaTeX-tabular-indentation)))))
3089 ((and inenv (not (equal "document" inenv)))
3090 (funcall indent-relative))
3091 ((YaTeX-on-section-command-p YaTeX-sectioning-regexp)
3092 (require 'yatexsec) ;to know YaTeX-sectioning-level
3093 (setq sect (YaTeX-match-string 1))
3094 (if (string-match "\\*$" sect)
3095 (setq sect (substring sect 0 -1)))
3096 (YaTeX-reindent
3097 (* (max
3098 (1- ;I want chapter to have indentation 0
3099 (or (cdr (assoc sect YaTeX-sectioning-level))
3100 0))
3101 0)
3102 YaTeX-environment-indent)))
3103 ;;Default movement
3104 ((and (bolp) fill-prefix) (insert fill-prefix))
3105 (t (save-excursion
3106 (beginning-of-line)
3107 (if fill-prefix
3108 (progn
3109 (delete-region (point)
3110 (progn (skip-chars-forward " \t")
3111 (point)))
3112 (insert fill-prefix))
3113 (skip-chars-forward " \t")
3114 (if (bobp)
3115 nil
3116 (indent-relative-maybe))))
3117 (skip-chars-forward " \t")))
3118 ;;if current line is \begin, re-indent \end too
3119 (if (and (YaTeX-on-begin-end-p) (match-beginning 1))
3120 (save-excursion
3121 ;;(beginning-of-line)
3122 ;;(search-forward "\\begin")
3123 (goto-char (match-beginning 0))
3124 (setq depth (current-column))
3125 (YaTeX-goto-corresponding-environment)
3126 (YaTeX-reindent depth)))
3127 (if (or
3128 (and NTT-jTeX
3129 (save-excursion (beginning-of-line) (looking-at "[ \t]")))
3130 (save-excursion
3131 (beginning-of-line)
3132 (and
3133 (not (bobp))
3134 (progn
3135 (backward-char 1)
3136 (re-search-backward
3137 "\\\\\\(\\(page\\)?ref\\|cite\\){" (point-beginning-of-line) t))
3138 (goto-char (1- (match-end 0)))
3139 (> (save-excursion
3140 (condition-case ()
3141 (progn (forward-list 1) (point))
3142 (error (point-max))))
3143 (point-end-of-line)))))
3144 (save-excursion
3145 (end-of-line)
3146 (let ((p (point)))
3147 (forward-line -1)
3148 (end-of-line)
3149 (or (= p (point))
3150 (looking-at (regexp-quote YaTeX-comment-prefix))
3151 (bobp) (bolp)
3152 (save-excursion
3153 (backward-word 1)
3154 (looking-at "\\sw+")) ;is not japanese string
3155 (insert YaTeX-comment-prefix)))))))
3157 (defun YaTeX-comment-line-break (&optional soft)
3158 "Call comment-indent-new-line and YaTeX-indent-line"
3159 (comment-indent-new-line soft)
3160 (YaTeX-indent-line))
3162 (defun YaTeX-latex2e-p ()
3163 (let ((b (current-buffer))
3164 (ptn (concat YaTeX-ec "documentclass")))
3165 (unwind-protect
3166 (or (save-excursion (search-backward ptn nil t))
3167 (progn
3168 (YaTeX-visit-main t)
3169 (save-excursion (search-backward ptn nil t))))
3170 (set-buffer b))))
3172 (provide 'yatex)
3173 (defvar yatex-mode-load-hook nil
3174 "*List of functions to be called when yatex.el is loaded.")
3175 (if (and YaTeX-emacs-19 YaTeX-display-color-p (not (featurep 'yatex19)))
3176 (load "yatex19"))
3177 (load "yatexhks" t)
3179 ;;-------------------- Final hook jobs --------------------
3180 (substitute-all-key-definition
3181 'fill-paragraph 'YaTeX-fill-paragraph YaTeX-mode-map)
3182 (substitute-all-key-definition
3183 'kill-buffer 'YaTeX-kill-buffer YaTeX-mode-map)
3184 (run-hooks 'yatex-mode-load-hook)
3186 ;; `History' was moved to ChangeLog
3187 ;----------------------------- End of yatex.el -----------------------------
3189 ; Local variables:
3190 ; coding: sjis
3191 ; End: