yatex

view yatex.el @ 242:cb4449ecb9f3

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