yatex

view yatex.el @ 584:907de32064c9

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