yatex

view yatex.el @ 525:e0222b0ab207

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