yatex

view yatex.el @ 572:714f3527b4a1

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