yatex

view yatex.el @ 323:d08c824ababe

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