yatex

view yatex.el @ 519:a6a80e2b6f5a

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