yatex

view yatex.el @ 481:723f136edde5

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