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