yatex

view yatex.el @ 361:41a05a44826a

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