yatex

view yatex.el @ 611:e87c3271b8fd

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