yatex

view yatex.el @ 500:965a6713da83

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