yatex

view yatex.el @ 449:c2c547e147c7

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