yatex

view yatex.el @ 313:fcdb9189cd9c

\cref Update (c)-line
author HIROSE Yuuji <yuuji@gentei.org>
date Wed, 08 Jan 2014 07:52:12 +0900
parents 0d42b3d7f958
children fae84a98372c
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 Wed Jan 8 07:49:58 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.2"
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 nil
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 ("cref") ;cleveref
265 ("multicolumn" 3) ("shortstack") ("parbox" 2)
266 ;; for mathmode accent
267 ("tilde") ("hat") ("check") ("bar") ("dot") ("ddot") ("vec")
268 ("widetilde") ("widehat") ("overline") ("overrightarrow")
269 ;; section types in mathmode
270 ("frac" 2) ("sqrt") ("mathrm") ("mathbf") ("mathit")
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")))
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 ((= c ?j) (YaTeX-typeset-buffer))
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 ?b) (YaTeX-insert-string "\\"))
1638 ((= c ?s) (YaTeX-xdvi-remote-search arg)))))
1640 (if (fboundp 'wrap-function-to-control-ime)
1641 (wrap-function-to-control-ime 'YaTeX-typeset-menu t "P"))
1644 (defun YaTeX-%-menu (&optional beg end char)
1645 "Operate %# notation."
1646 ;;Do not use interactive"r" for the functions which require no mark
1647 (interactive)
1648 (message "!)Edit-%%#! B)EGIN-END-region P)review L)Edit-%%#LPR make(I)ndex B)ibtex")
1649 (let ((c (or char (read-char))) (string "") key
1650 (b (make-marker)) (e (make-marker)))
1651 (save-excursion
1652 (cond
1653 ((rindex "!plib" c) ;Edit %#xxx
1654 (setq key (cdr (assq c '((?! . "!")
1655 (?p . "PREVIEW")
1656 (?l . "LPR")
1657 (?i . "MAKEINDEX")
1658 (?b . "BIBTEX")))))
1659 (YaTeX-getset-builtin key t))
1661 ((= c ?b) ;%#BEGIN %#END region
1662 (or end (setq beg (min (point) (mark)) end (max (point) (mark))))
1663 (set-marker b beg)
1664 (set-marker e end)
1665 (goto-char (point-min))
1666 (while (re-search-forward "^%#\\(BEGIN\\)\\|\\(END\\)$" nil t)
1667 (beginning-of-line)
1668 (delete-region (point) (progn (forward-line 1) (point))))
1669 (goto-char b)
1670 (open-line 1)
1671 (delete-region (point) (progn (beginning-of-line)(point)));for 19 :-<
1672 (insert "%#BEGIN")
1673 (goto-char e)
1674 (insert "%#END\n")
1675 (set-marker b nil)
1676 (set-marker e nil))
1677 ))))
1679 (defvar YaTeX-refcommand-def-regexp-default
1680 "label\\|bibitem")
1681 (defvar YaTeX-refcommand-def-regexp-private nil
1682 "*Regexp of defining label commands")
1683 (defvar YaTeX-refcommand-def-regexp
1684 (concat (if YaTeX-refcommand-def-regexp-private
1685 (concat YaTeX-refcommand-def-regexp-private "\\|"))
1686 YaTeX-refcommand-def-regexp-default))
1688 (defvar YaTeX-refcommand-ref-regexp-default
1689 "\\(page\\|eq\\|fig\\|c\\)?ref\\|cite")
1690 (defvar YaTeX-refcommand-ref-regexp-private nil
1691 "*Regexp of referring label commands")
1692 (defvar YaTeX-refcommand-ref-regexp
1693 (concat (if YaTeX-refcommand-ref-regexp-private
1694 (concat YaTeX-refcommand-ref-regexp-private "\\|"))
1695 YaTeX-refcommand-ref-regexp-default))
1697 (defvar YaTeX-refcommand-regexp
1698 (concat YaTeX-refcommand-def-regexp
1699 "\\|" YaTeX-refcommand-ref-regexp)
1700 "Regexp of label defining/referring command name.")
1702 (defun YaTeX-goto-corresponding-label (reverse &optional otherwin)
1703 "Jump to corresponding \\label{} and \\ref{} or \\cite and \\bibitem.
1704 The default search direction depends on the command at the cursor position.
1705 When the cursor is on \\ref(\\cite), YaTeX will try to search the
1706 corresponding \\label(\\bibitem) backward,
1707 and if it fails search forward again. And when the cursor is
1708 on \\label(\\bibitem), YaTeX will search the corresponding \\ref(\\cite)
1709 forward at first and secondary backward.
1710 Argument REVERSE non-nil makes the default
1711 direction rule reverse. Since Search string is automatically set in
1712 search-last-string, you can repeat search the same label/ref by typing
1713 \\[isearch-forward] or \\[isearch-backward].
1714 If optional second argument OTHERWIN is non-nil, move to other window."
1716 (let ((scmd "") label direc string blist (p (point)) (cb (current-buffer))
1717 (refcommands YaTeX-refcommand-regexp)
1718 (foundmsg (format "Type %s %c to return to original position."
1719 (key-description
1720 (car
1721 (or (where-is-internal 'register-to-point)
1722 (where-is-internal 'jump-to-register))))
1723 YaTeX-current-position-register))
1724 (func (function (lambda (string sfunc)
1725 (or
1726 (funcall sfunc string nil t)
1727 (funcall (if (eq sfunc 're-search-forward)
1728 're-search-backward 're-search-forward)
1729 string nil t))))))
1730 (cond
1731 ((YaTeX-on-section-command-p refcommands)
1732 (setq scmd
1733 (cdr
1734 (assoc
1735 (YaTeX-match-string 1)
1736 '(("label" . "\\\\\\(page\\|eq\\)?ref{%k}")
1737 ("ref" . "\\\\label{%k}")
1738 ("eqref" . "\\\\label{%k}")
1739 ("pageref" . "\\\\label{%k}")
1740 ("cite" .
1741 "\\\\bibitem\\(\\[[^]]+\\]\\)?{%k}\\|^\\s *@[a-z]+{%k,")
1742 ("bibitem" . "\\\\cite\\(\\[[^]]+\\]\\)?")))))
1743 (goto-char (match-end 0))
1744 (let ((label (YaTeX-buffer-substring
1745 (1- (point)) (progn (backward-list 1) (1+ (point)))))
1746 (fp (make-marker))fl fn
1747 (goother (function (lambda (buffer point)
1748 (goto-char point)
1749 (if (one-window-p)
1750 (split-window-calculate-height
1751 YaTeX-default-pop-window-height))
1752 (select-window (get-lru-window))
1753 (switch-to-buffer buffer)))))
1754 ;(setq string (concat "\\" scmd "{" label "}"))
1755 ;(setq string (concat "\\\\" scmd "{" (regexp-quote label) "}"))
1756 (setq string (YaTeX-replace-format scmd "k" (regexp-quote label)))
1757 (setq direc (if (string-match "ref\\|cite" scmd)
1758 're-search-forward 're-search-backward))
1759 (if YaTeX-current-position-register
1760 (point-to-register YaTeX-current-position-register))
1761 (if reverse (setq direc (if (eq direc 're-search-forward)
1762 're-search-backward 're-search-forward)))
1763 (if (funcall func string direc) ;label/ref found!
1764 (progn
1765 (if otherwin (funcall goother cb p))
1766 (goto-char (match-beginning 0))
1767 (push-mark p))
1768 ;;if label/ref not found, search through all yatex buffers.
1769 (goto-char p) ;resume position of current buffer
1770 (catch 'found
1771 (setq blist (YaTeX-yatex-buffer-list))
1772 (while blist
1773 ;; search for corresponding keyword
1774 (set-buffer (car blist))
1775 (if (YaTeX-on-section-command-p refcommands)
1776 (goto-char (match-beginning 0)))
1777 (cond
1778 ; cond1
1779 ((funcall func string direc)
1780 (cond
1781 (otherwin
1782 (set-buffer cb)
1783 (funcall goother (car blist) p))
1784 ((or (get-buffer-window (car blist))
1785 (and YaTeX-emacs-19
1786 (get-buffer-window (car blist) t)))
1787 (goto-buffer-window (car blist)))
1788 (t
1789 (switch-to-buffer (car blist))
1790 (message foundmsg)))
1791 (goto-char (match-beginning 0))
1792 (throw 'found t))
1793 ; cond2
1794 ((and
1795 (string-match "bibitem" scmd)
1796 (catch 'found2
1797 (save-excursion
1798 (goto-char (point-min))
1799 (while (YaTeX-re-search-active-forward
1800 "\\\\bibliography{\\([^}]*\\)}" "%" nil t)
1801 (setq fl (YaTeX-split-string (YaTeX-match-string 1) ","))
1802 (while fl
1803 (if (or (file-exists-p (setq fn (car fl)))
1804 (file-exists-p (setq fn (concat fn ".bib"))))
1805 (progn
1806 (set-buffer (find-file-noselect fn))
1807 (save-excursion
1808 (goto-char (point-min))
1809 (if (YaTeX-re-search-active-forward
1810 string "%" nil t)
1811 (throw 'found2
1812 (set-marker fp (point)))))))
1813 (setq fl (cdr fl)))))))
1814 (if otherwin
1815 (funcall goother (marker-buffer fp) fp)
1816 (switch-to-buffer (marker-buffer fp))
1817 (goto-char fp))
1818 (set-marker fp nil)
1819 (message foundmsg)
1820 (throw 'found t)))
1821 (setq blist (cdr blist)))
1822 ;; search for bibliography
1823 )))
1824 (if YaTeX-emacs-19
1825 (setq regexp-search-ring
1826 (cons string (delete string regexp-search-ring)))
1827 (setq search-last-regexp string)))
1828 (t nil))))
1830 ;;YaTeX-goto-corresponding-environment was moved to yatexlib
1832 (defun YaTeX-goto-corresponding-file (&optional other)
1833 "Visit or switch buffer of corresponding file,
1834 looking at \\input or \\include or \\includeonly on current line."
1835 (if (not (YaTeX-on-includes-p)) nil
1836 (let ((parent buffer-file-name) input-file b)
1837 (save-excursion
1838 (if (and (re-search-forward "[{%]" (point-end-of-line) t)
1839 (= ?{ (char-after (match-beginning 0))))
1840 nil
1841 (skip-chars-backward "^,{"))
1842 (setq input-file
1843 (YaTeX-buffer-substring
1844 (point) (progn (skip-chars-forward "^ ,}") (point))))
1845 (if (not (string-match "\\.\\(tex\\|sty\\)$" input-file))
1846 (setq input-file (concat input-file ".tex"))))
1847 (cond
1848 (other (YaTeX-switch-to-buffer-other-window input-file))
1849 ((setq b (YaTeX-get-file-buffer input-file))
1850 (goto-buffer-window b))
1851 (t (YaTeX-switch-to-buffer input-file)))
1852 (or (YaTeX-get-builtin "!")
1853 YaTeX-parent-file
1854 (setq YaTeX-parent-file parent)))))
1856 (defun YaTeX-goto-corresponding-BEGIN-END ()
1857 (if (not (YaTeX-on-BEGIN-END-p)) nil
1858 (if (cond
1859 ((equal (match-beginning 0) (match-beginning 1)) ;if on %#BEGIN
1860 (not (search-forward "%#END" nil t)))
1861 (t ; if on %#END
1862 (not (search-backward "%#BEGIN" nil t))))
1863 (error "Corresponding %%#BEGIN/END not found."))
1864 (beginning-of-line)
1865 t))
1867 (defvar YaTeX-processed-file-regexp-alist nil
1868 "Alist of regexp of processed file regexp vs. its file name part;
1869 For example, if you include image file with `\\epsfile{file=FILE}' where
1870 `FILE' is processed file. You might want to view FILE with other previewer
1871 such as ghostview, or want to preview its source which was drawn with
1872 other drawing tool, tgif for example. Then you should set entire regexp
1873 of including expression and enclose its file name part with \\\\( and \\\\).
1875 Ex. (\"\\\\\\\\epsfile{[^}]*file=\\\\([^,} ]+\\\\)\\\\(\\\\.e?ps\\\\)?[^}]*}\" 1)
1877 Where the first group surrounded by \\\\( and \\\\) is the file name part
1878 of expression. So you should set 1 to second element. And the first
1879 matching group is sent to (image) processor defined by the variable
1880 YaTeX-file-processor-alist. See also the documentation of
1881 YaTeX-file-processor-alist.
1883 ↑じゃ良くわかんないすね。例えば tgif hoge.obj して hoge.eps を
1884 \\epsfile{file=hoge.eps} でインクルードしているとしよう。その行で
1885 \[prefix\] g を押した時に tgif を起動して欲しかったら、まず上のような
1886 正規表現を設定する。\\\\(と\\\\)で囲んだところがファイル名になるように
1887 注意する。でファイル名部分が何番目の\\\\(\\\\)になるかをリストの2番目に書く。
1888 すると、その部分が変数 YaTeX-file-processor-alist で定義された
1889 処理プログラムに渡される。というわけ。
1890 ん〜やっぱりむずかしいね。分からない時は隣の Lisper に聞くか、
1891 fj野鳥の会で聞こう!
1892 ")
1894 (defvar YaTeX-processed-file-regexp-alist-default
1895 '(("\\\\epsfile\\(\\[[^]]+\\]\\)?{[^},]*file=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1896 ("\\\\epsfig{[^},]*fi\\(le\\|gure\\)=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1897 ("\\\\postscriptbox{[^}]*}{[^}]*}{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 1)
1898 ("\\\\\\(epsfbox\\|epsfig\\)\\*?{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 2) ;\epsfbox{hoge.ps}
1899 ("\\\\includegraphics\\*?\\(.*\\]\\|\\s \\)?{\\(.*\\)\\(\\.ai\\|\\.pdf\\|\\.svg\\|\\.png\\|\\.jpe?g\\|\\.e?ps\\)}" 2) ;\includegraphics[options...]{hoge.eps}
1900 ("\\\\\\(psbox\\)\\(\\[[^]]+\\]\\)?{\\(\\([^,} ]*/\\)?[^} ]+\\)\\(\\.e?ps\\)}" 3) ;\psbox[options...]{hoge.eps} (97/1/11)
1901 ("\\\\input{\\([^} ]+\\)\\(\\.tps\\)}" 1) ;tgif2tex (1998/9/16)
1903 "See the documentation of YaTeX-processed-file-regexp-alist.")
1905 (defvar YaTeX-file-processor-alist nil
1906 "*Alist of files' processor vs. its extension;
1907 See also the documentation of YaTeX-processed-file-regexp-alist.")
1909 (defvar YaTeX-file-processor-alist-default
1910 '(("tgif" . ".obj")
1911 ("gimp" . ".xcf") ("gimp" . ".xcf.gz") ("gimp" . ".xcf.bz2")
1912 ("inkscape" . ".svg") ("inkscape" . ".svgz") ("inkscape" . ".ai")
1913 ("soffice" . ".odg")
1914 ("gimp" . ".jpeg") ("gimp" . ".jpg") ("gimp" . ".png")
1915 ("evince" . ".ps")
1916 ("evince" . ".eps")
1917 ("soffice" . ".pdf")
1918 (t . ".tex")
1919 (t . ".sty")
1920 (t . ""))
1921 "See the documentation of YaTeX-file-processor-alist.")
1923 (defun YaTeX-goto-corresponding-file-processor (&optional other)
1924 "Execute corresponding file processor."
1925 (save-excursion
1926 (or (looking-at YaTeX-ec-regexp)
1927 (skip-chars-backward (concat "^" YaTeX-ec) (point-beginning-of-line)))
1928 (let ((list (append YaTeX-processed-file-regexp-alist
1929 YaTeX-processed-file-regexp-alist-default))
1930 (p (point)) flist file
1931 (peol (point-end-of-line))
1932 (basedir
1933 (if YaTeX-search-file-from-top-directory
1934 (save-excursion (YaTeX-visit-main t) default-directory)
1935 ".")))
1936 (setq flist (catch 'found
1937 (while list
1938 (goto-char p)
1939 (if (re-search-forward (car (car list)) peol t)
1940 (progn
1941 (setq file (YaTeX-match-string
1942 (car (cdr (car list)))))
1943 (throw 'found (cdr (car list)))))
1944 (setq list (cdr list)))))
1945 (if flist ;if pattern and file name found
1946 (let*((plist (append YaTeX-file-processor-alist
1947 YaTeX-file-processor-alist-default))
1948 (plist0 plist)
1949 ext cmd src buf (alt (car (cdr flist))))
1950 (if (and (re-search-forward
1951 (concat YaTeX-comment-prefix "\\s *\\(.*\\)$") peol t)
1952 (assoc (setq cmd (YaTeX-match-string 1))
1953 YaTeX-file-processor-alist))
1954 (setq src ;if processor is specified
1955 (concat file
1956 (cdr (assoc cmd YaTeX-file-processor-alist))))
1957 (while plist ;if processor is not specified
1958 (setq ext (cdr (car plist)))
1959 (if (and (string< "" (concat file ext))
1960 (file-exists-p
1961 (expand-file-name (concat file ext) basedir)))
1962 (setq cmd (car (car plist))
1963 src (concat file ext) plist nil))
1964 (setq plist (cdr plist)))
1965 (if (and (null src) alt YaTeX-create-file-prefix-g)
1966 (setq cmd alt
1967 src (concat file (cdr (assoc alt plist0))))))
1968 (if src ;if processor and src file found
1969 (let ((default-directory basedir))
1970 (cond
1971 ((stringp cmd)
1972 (let ((buf (concat "* " cmd " " src " *")))
1973 (YaTeX-system (concat cmd " " src) buf)
1974 t))
1975 ((eq t cmd)
1976 (let ((parent buffer-file-name))
1977 (funcall
1978 (cond
1979 (other 'YaTeX-switch-to-buffer-other-window)
1980 ((get-file-buffer src) 'goto-buffer-window)
1981 (t 'YaTeX-switch-to-buffer))
1982 src)
1983 (or (YaTeX-get-builtin "!")
1984 YaTeX-parent-file
1985 (setq YaTeX-parent-file parent))
1986 t))
1987 ((symbolp cmd)
1988 (cond
1989 ((symbol-function cmd)
1990 (funcall cmd src other)))
1991 t)))))))))
1993 (defun YaTeX-on-section-command-p (command)
1994 "Check if point is on the LaTeX command: COMMAND(regexp).
1995 Return nil if point is not on it. Otherwise return the
1996 number of argument position.
1997 Section command name is stored in match-data #1.
1998 Parsing information is stored to plist.
1999 Macros name stored to propname 'command.
2000 Macro's argument number stored to propname 'argc."
2001 (let ((p (point)) md (parg 0) (argc 1) word (grouping 0) (i 0)
2002 (ec+command (concat YaTeX-ec-regexp "\\(" command "\\)")))
2003 (setplist 'YaTeX-on-section-command-p nil)
2004 (while (setq i (string-match "\\\\(" command i))
2005 (setq grouping (1+ grouping) i (+ i 2)))
2006 (save-excursion
2007 (if (looking-at ec+command) nil
2008 (catch 'found ;caught value has no meaning
2009 ;;(1) looking at current position
2010 (and (looking-at command)
2011 (save-excursion
2012 (while (and (not (bobp)) (looking-at command))
2013 (forward-char -1))
2014 (looking-at ec+command))
2015 (goto-char (match-beginning 0))
2016 (throw 'found t))
2017 ;;If inside of parentheses, try to escape.
2018 (while (condition-case err
2019 (progn (up-list -1) t)
2020 (error nil)))
2021 (while (equal (preceding-char) ?\]) (backward-list))
2022 ;;(2) search command directly
2023 (skip-chars-forward "^{}[]")
2024 (and (YaTeX-re-search-active-backward
2025 ec+command
2026 YaTeX-comment-prefix nil t)
2027 (>= p (match-beginning 0))
2028 (throw 'found (goto-char (match-beginning 0))))
2029 ;;(3) search token
2030 (goto-char p)
2031 (while t
2032 (if (bobp) (throw 'found nil))
2033 (cond
2034 ((looking-at YaTeX-ec-regexp) (throw 'found t))
2035 ((looking-at "[[{]") nil)
2036 ((looking-at "[]}]")(condition-case nil (up-list -1) (error nil)))
2037 (t (skip-chars-backward " \t\r\n")))
2038 (skip-chars-backward (concat "^ \t\r\n{}[]" YaTeX-ec-regexp))
2039 (or (bobp) (forward-char -1)))))
2040 (if (and
2041 (looking-at (concat ec+command
2042 "\\(\\(\\[[^]]+\\]\\|([0-9,]+)\\)*\\)" ;optional arg
2043 ;"[ \t\n\r]*{[^}]+}")) ;arg braces
2044 "[ \t\n\r]*{[^}]*}")) ;arg braces
2045 (not (YaTeX-lookup-table
2046 (setq word (YaTeX-match-string 1)) 'singlecmd)))
2047 (progn
2048 (setq md (match-data))
2049 (skip-chars-forward "^{")
2050 (if (<= (point) p) (setq parg (1+ parg)))
2051 (setq argc
2052 (or (car (cdr (YaTeX-lookup-table word 'section)))
2053 argc))
2054 (put 'YaTeX-on-section-command-p 'argc argc)
2055 (put 'YaTeX-on-section-command-p 'command argc)
2056 (while (and (>= (setq argc (1- argc)) 0)
2057 (progn (skip-chars-forward " \t\n\r")
2058 (looking-at "{")))
2059 (forward-list 1)
2060 (if (<= (point) p) (setq parg (1+ parg))))
2061 (store-match-data md)
2062 (setq i (+ 2 grouping))
2063 (if (and (match-beginning i)
2064 (>= p (match-beginning i)) (< p (match-end i)))
2065 -1 ;return -1 if point is on optional arg
2066 (if (< p (point)) parg))
2067 )))))
2069 (defun YaTeX-on-maketitle-p ()
2070 "Check if point is on maketitle type commands.
2071 Call this function after YaTeX-on-section-command-p."
2072 (let ((p (point)))
2073 (save-excursion
2074 (or (= (char-after (point)) ?\\ )
2075 (progn
2076 (skip-chars-backward
2077 (concat "^" YaTeX-ec-regexp) (point-beginning-of-line))
2078 (or (bobp) (bolp) (backward-char 1))))
2079 (and (looking-at (concat YaTeX-ec-regexp YaTeX-TeX-token-regexp))
2080 (<= (match-beginning 0) p)
2081 (> (match-end 0) p)))))
2083 (defun YaTeX-on-begin-end-p ()
2084 (save-excursion
2085 (if (and (boundp 'in-leftright-p) in-leftright-p)
2086 ;; Dirty workaround for YaTeX-goto-corresponding-leftright 2003/3/28
2087 (let ((md (match-data))) ; for safety
2088 (if (looking-at YaTeX-ec-regexp)
2089 nil ; stay here
2090 (cond
2091 ((looking-at "\\w") (skip-chars-backward "A-Za-z"))
2092 ((looking-at "\\.()\\[\\]|") (forward-char -1)))
2093 (if (equal (char-after (1- (point)))
2094 (string-to-char YaTeX-ec))
2095 (forward-char -1))))
2096 ;(beginning-of-line)
2097 (if (equal (char-after (point)) ?\\) nil ;stay here
2098 (skip-chars-backward "^\n\\\\")
2099 (or (bolp) (forward-char -1))))
2100 (re-search-forward
2101 ;;"\\\\begin{\\([^}]+\\)}\\|\\\\end{\\([^}]+\\)}"
2102 (concat
2103 (YaTeX-replace-format-args
2104 (regexp-quote YaTeX-struct-begin)
2105 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" "")
2106 "\\|"
2107 (YaTeX-replace-format-args
2108 (regexp-quote YaTeX-struct-end)
2109 (concat "\\(" YaTeX-struct-name-regexp "\\)") "" "" "")
2110 "\\|\\("
2111 YaTeX-ec-regexp ;;"[][()]\\)"
2112 "[][]\\)"
2114 (point-end-of-line) t)))
2116 (defun YaTeX-on-includes-p ()
2117 (save-excursion
2118 (beginning-of-line)
2119 (re-search-forward "\\(\\(include[^}]*\\)\\|\\(input\\)\\){[^}]*}"
2120 (point-end-of-line) t)))
2122 (defun YaTeX-on-comment-p (&optional sw)
2123 "Return t if current line is commented out.
2124 Optional argument SW t to treat all `%' lines as comment,
2125 even if on `%#' notation."
2126 (save-excursion
2127 (beginning-of-line)
2128 (skip-chars-forward "\\s ")
2129 (looking-at (if sw "%" "%[^#]"))))
2131 (defun YaTeX-on-BEGIN-END-p ()
2132 (save-excursion
2133 (let ((case-fold-search nil))
2134 (beginning-of-line)
2135 (re-search-forward
2136 "\\(%#BEGIN\\)\\|\\(%#END\\)" (point-end-of-line) t))))
2138 (defun YaTeX-goto-corresponding-* (arg)
2139 "Parse current line and call suitable function."
2140 (interactive "P")
2141 (let (mm)
2142 (cond
2143 ((YaTeX-goto-corresponding-label arg))
2144 ((YaTeX-goto-corresponding-environment))
2145 ((YaTeX-goto-corresponding-file-processor arg))
2146 ((YaTeX-goto-corresponding-file arg))
2147 ((YaTeX-goto-corresponding-BEGIN-END))
2148 ((and (setq mm (YaTeX-in-math-mode-p))
2149 (YaTeX-goto-corresponding-leftright)))
2150 ((and ;;mm YaTeX-use-AMS-LaTeX
2151 (YaTeX-goto-corresponding-paren)))
2152 ;;((and (string-match
2153 ;; YaTeX-equation-env-regexp ;to delay loading
2154 ;; (or (YaTeX-inner-environment t) "document"))
2155 ;; (YaTeX-goto-corresponding-leftright)))
2156 (t (message "I don't know where to go.")))))
2158 (defun YaTeX-goto-corresponding-*-other-window (arg)
2159 "Parse current line and call suitable function."
2160 (interactive "P")
2161 (cond
2162 ((YaTeX-goto-corresponding-label arg t))
2163 ;;((YaTeX-goto-corresponding-environment))
2164 ((YaTeX-goto-corresponding-file t))
2165 ;;((YaTeX-goto-corresponding-BEGIN-END))
2166 (t (message "I don't know where to go."))))
2168 (defun YaTeX-comment-region (alt-prefix)
2169 "Comment out region by '%'.
2170 If you call this function on the 'begin{}' or 'end{}' line,
2171 it comments out whole environment"
2172 (interactive "P")
2173 (if (not (YaTeX-on-begin-end-p))
2174 (comment-out-region
2175 (if alt-prefix
2176 (read-string "Insert prefix: ")
2177 YaTeX-comment-prefix))
2178 (YaTeX-comment-uncomment-env 'comment-out-region)))
2180 (defun YaTeX-uncomment-region (alt-prefix)
2181 "Uncomment out region by '%'."
2182 (interactive "P")
2183 (if (not (YaTeX-on-begin-end-p))
2184 (uncomment-out-region
2185 (if alt-prefix (read-string "Remove prefix: ")
2186 YaTeX-comment-prefix)
2187 (region-beginning) (region-end) YaTeX-uncomment-once)
2188 (YaTeX-comment-uncomment-env 'uncomment-out-region)))
2190 (defun YaTeX-comment-uncomment-env (func)
2191 "Comment or uncomment out one LaTeX environment switching function by FUNC."
2192 (let (beg (p (point)))
2193 (save-excursion
2194 (beginning-of-line)
2195 (setq beg (point))
2196 (YaTeX-goto-corresponding-environment)
2197 (beginning-of-line)
2198 (if (> p (point)) (setq beg (1+ beg)) (forward-char 1))
2199 (funcall func YaTeX-comment-prefix beg (point) YaTeX-uncomment-once)))
2200 (message "%sommented out current environment."
2201 (if (eq func 'comment-out-region) "C" "Un-c")))
2203 (defun YaTeX-comment-paragraph ()
2204 "Comment out current paragraph."
2205 (interactive)
2206 (save-excursion
2207 (cond
2208 ((YaTeX-on-begin-end-p)
2209 (beginning-of-line)
2210 (insert YaTeX-comment-prefix)
2211 (YaTeX-goto-corresponding-environment)
2212 (beginning-of-line)
2213 (insert YaTeX-comment-prefix))
2214 ((YaTeX-on-comment-p)
2215 (message "Already commented out."))
2216 (t
2217 (mark-paragraph)
2218 (if (looking-at paragraph-separate) (forward-line 1))
2219 (comment-out-region "%")))))
2221 (defun YaTeX-uncomment-paragraph ()
2222 "Uncomment current paragraph."
2223 (interactive)
2224 (save-excursion
2225 (if (YaTeX-on-begin-end-p)
2226 (let ((p (point-marker)))
2227 (YaTeX-goto-corresponding-environment)
2228 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once)
2229 (goto-char p)
2230 (YaTeX-remove-prefix YaTeX-comment-prefix YaTeX-uncomment-once)
2231 (set-marker p nil))
2232 (if (YaTeX-on-comment-p)
2233 (let*((fill-prefix "")
2234 ;;append `^%' to head of paragraph delimiter.
2235 (paragraph-start
2236 (concat
2237 "^$\\|^%\\(" YaTeX-paragraph-separate "\\)"))
2238 (paragraph-separate paragraph-start))
2239 (mark-paragraph)
2240 (if (not (bobp)) (forward-line 1))
2241 (uncomment-out-region "%" nil nil YaTeX-uncomment-once))
2242 (message "This line is not a comment line.")))))
2244 (defun YaTeX-remove-prefix (prefix &optional once)
2245 "Remove prefix on current line as far as prefix detected. But
2246 optional argument ONCE makes deletion once."
2247 (interactive "sPrefix:")
2248 (beginning-of-line)
2249 (while (re-search-forward (concat "^" prefix) (point-end-of-line) t)
2250 (replace-match "")
2251 (if once (end-of-line))))
2253 (defun YaTeX-kill-some-pairs (predicate gofunc kill-contents)
2254 "Kill some matching pair.
2255 This function assumes that pairs occupy whole of each line where they resid."
2256 (if (not (funcall predicate)) nil
2257 (let ((b1 (match-beginning 0)) (e1 (match-end 0))
2258 b2 e2)
2259 (save-excursion
2260 (funcall gofunc)
2261 (funcall predicate) ;get match data
2262 (if (< (point) e1) ;if currently on begin-line
2263 (progn
2264 (setq b2 b1 e2 e1
2265 b1 (match-beginning 0) e1 (match-end 0))
2266 (goto-char e2)) ;goto end-line's end
2267 (setq b2 (match-beginning 0)
2268 e2 (match-end 0))
2269 (goto-char e2)) ;now e2 has surely end-line's end
2270 (skip-chars-forward " \t")
2271 (and (eolp)
2272 (not (eobp))
2273 (setq e2 (1+ (point))))
2274 (if (not kill-contents)
2275 (kill-region
2276 (progn
2277 (goto-char b2)
2278 (skip-chars-backward " \t%")
2279 (if (bolp) (point) b2))
2280 e2))
2281 (goto-char b1)
2282 (skip-chars-backward " \t%")
2283 (if (not kill-contents)
2284 (progn
2285 (kill-append
2286 (buffer-substring
2287 (setq b1 (if (bolp) (point) b1))
2288 (setq e1
2289 (progn
2290 (goto-char e1)
2291 (while (looking-at "{\\| \t")
2292 (forward-list 1))
2293 (skip-chars-forward " \t")
2294 (if (and (eolp) (not (eobp)))
2295 (1+ (point))
2296 (point)))))
2297 t)
2298 (delete-region b1 e1))
2299 (kill-region
2300 (if (bolp) (point) b1)
2301 e2)))
2302 t)))
2304 (defun YaTeX-kill-section-command (point kill-all)
2305 "Kill section-type command at POINT leaving its last argument.
2306 Non-nil for the second argument kill its last argument too."
2307 (let ((cmd (get 'YaTeX-on-section-command-p 'command))
2308 (argc (get 'YaTeX-on-section-command-p 'argc))
2309 beg (end (make-marker)))
2310 (save-excursion
2311 (goto-char point)
2312 (or (looking-at YaTeX-ec-regexp)
2313 (progn
2314 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
2315 (forward-char -1)))
2316 (setq beg (point))
2317 (skip-chars-forward "^{")
2318 (while (> (setq argc (1- argc)) 0)
2319 (skip-chars-forward "^{")
2320 (forward-list 1))
2321 (kill-region beg (point))
2322 (forward-list 1)
2323 (set-marker end (point))
2324 (if kill-all
2325 (progn
2326 (kill-append (buffer-substring beg end) nil)
2327 (delete-region beg end))
2328 (goto-char beg)
2329 (kill-append
2330 (buffer-substring
2331 (point) (progn (skip-chars-forward "^{" end) (1+ (point))))
2332 nil)
2333 (delete-region beg (1+ (point)))
2334 (goto-char end)
2335 (set-marker end nil)
2336 (kill-append (buffer-substring (point) (1- (point))) nil)
2337 (delete-backward-char 1)))))
2339 (defun YaTeX-kill-paren (kill-contents)
2340 "Kill parentheses leaving its contents.
2341 But kill its contents if the argument KILL-CONTENTS is non-nil."
2342 (interactive "P")
2343 (let (p bsl (backslash-syntax (char-to-string (char-syntax ?\\)))
2344 (md (match-data)))
2345 (unwind-protect
2346 (save-excursion
2347 (modify-syntax-entry ?\\ " ")
2348 (if (looking-at "\\s(\\|\\(\\s)\\)")
2349 (progn
2350 (if (match-beginning 1)
2351 (up-list -1))
2352 (if (and (> (point) (point-min))
2353 (= (char-after (1- (point))) ?\\ ))
2354 (setq p (1- (point)) bsl t)
2355 (setq p (point)))
2356 (forward-list 1)
2357 ;(YaTeX-goto-open-paren t)
2358 (if kill-contents (delete-region p (point))
2359 (backward-delete-char 1)
2360 (cond
2361 ((save-excursion
2362 (forward-char -2)
2363 (looking-at (concat YaTeX-ec-regexp "/")))
2364 (backward-delete-char 2))
2365 ((= (char-after (1- (point))) ?\\)
2366 (backward-delete-char 1)))
2367 (goto-char p)
2368 (if (looking-at
2369 (concat "{" YaTeX-ec-regexp
2370 YaTeX-command-token-regexp "+"
2371 "\\s +"))
2372 (delete-region (point) (match-end 0))
2373 (delete-char 1)
2374 (if bsl (delete-char 1))))
2375 t)))
2376 (modify-syntax-entry ?\\ backslash-syntax)
2377 (store-match-data md))))
2379 (defvar YaTeX-read-environment-history nil "Holds history of environments.")
2380 (put 'YaTeX-read-environment-history 'no-default t)
2381 (defun YaTeX-read-environment (prompt &optional predicate must-match initial)
2382 "Read a LaTeX environment name with completion."
2383 (YaTeX-sync-local-table 'tmp-env-table)
2384 (completing-read-with-history
2385 prompt
2386 (append tmp-env-table user-env-table env-table)
2387 predicate must-match initial
2388 'YaTeX-read-environment-history))
2390 (defvar YaTeX-read-section-history nil "Holds history of section-types.")
2391 (put 'YaTeX-read-section-history 'no-default t)
2392 (defun YaTeX-read-section (prompt &optional predicate initial)
2393 "Read a LaTeX section-type command with completion."
2394 (YaTeX-sync-local-table 'tmp-section-table)
2395 (let ((minibuffer-completion-table
2396 (append tmp-section-table user-section-table section-table)))
2397 (read-from-minibuffer-with-history
2398 prompt initial YaTeX-section-completion-map nil
2399 'YaTeX-read-section-history)))
2401 (defun YaTeX-read-section-with-overview ()
2402 "Read sectioning command with overview.
2403 This function refers a local variable `source-window' in YaTeX-make-section,
2404 because this function is called with no argument."
2405 (interactive)
2406 (require 'yatexsec) ;some case needs this
2407 (if (> (minibuffer-depth) 1)
2408 (error "Too many minibuffer levels for overview."))
2409 (let ((sw (selected-window))
2410 (minibuffer-max-depth nil) ; for XEmacs20
2411 (enable-recursive-minibuffers t) sect)
2412 (unwind-protect
2413 (progn
2414 (select-window source-window)
2415 (setq sect (YaTeX-read-section-in-minibuffer
2416 "Sectioning(Up=C-p, Down=C-n, Help=?): "
2417 YaTeX-sectioning-level (YaTeX-section-overview))))
2418 (select-window sw))
2419 (YaTeX-minibuffer-erase)
2420 (insert sect)
2421 (exit-minibuffer)))
2423 (defvar YaTeX-read-fontsize-history nil "Holds history of font designator.")
2424 (put 'YaTeX-read-fontsize-history 'no-default t)
2425 (defun YaTeX-read-fontsize (prompt &optional predicate must-match initial)
2426 "Read a LaTeX font changing command with completion."
2427 (YaTeX-sync-local-table 'tmp-fontsize-table)
2428 (completing-read-with-history
2429 prompt (append tmp-fontsize-table user-fontsize-table fontsize-table)
2430 predicate must-match initial 'YaTeX-read-fontsize-history))
2432 (defun YaTeX-change-environment ()
2433 "Change the name of environment."
2434 (interactive)
2435 (if (not (YaTeX-on-begin-end-p)) nil
2436 (save-excursion
2437 (let (p env newenv (m1 (match-beginning 1)) (m2 (match-beginning 2)))
2438 (setq env (if m1 (YaTeX-buffer-substring m1 (match-end 1))
2439 (YaTeX-buffer-substring m2 (match-end 2))))
2440 (goto-char (match-beginning 0))
2441 (set-mark-command nil)
2442 (YaTeX-goto-corresponding-environment)
2443 (setq newenv (YaTeX-read-environment
2444 (format "Change environment `%s' to: " env)))
2445 (cond
2446 ((string= newenv "") (message "Change environment cancelled."))
2447 ((string= newenv env) (message "No need to change."))
2448 (t
2449 (search-forward (concat "{" env) (point-end-of-line) t)
2450 (replace-match (concat "{" newenv) t)
2451 (exchange-point-and-mark)
2452 (search-forward (concat "{" env) (point-end-of-line) t)
2453 (replace-match (concat "{" newenv) t)))
2454 t))))
2456 (defun YaTeX-change-section ()
2457 "Change section-type command."
2458 (interactive)
2459 (let*((where (YaTeX-on-section-command-p YaTeX-command-token-regexp))
2460 (p (point)) (cmd (YaTeX-match-string 1))
2461 (beg (make-marker)) (end (make-marker)) old new)
2462 (if (null where) nil
2463 (unwind-protect
2464 (let ((source-window (selected-window)))
2465 (cond
2466 ((equal where 0);;if point is on section command
2467 (set-marker beg (match-beginning 1))
2468 (set-marker end (match-end 1))
2469 (goto-char beg) ;beginning of the command
2470 (setq new (YaTeX-read-section
2471 (format "Change `%s' to: " cmd) nil)
2472 old cmd))
2474 ((= where -1);;if point is on a optional parameter
2475 (set-marker beg (match-beginning 2))
2476 (skip-chars-forward "^{")
2477 (set-marker end (point))
2478 (goto-char p)
2479 (setq new
2480 (if (fboundp (intern-soft (concat YaTeX-addin-prefix cmd)))
2481 (YaTeX-addin cmd)
2482 (concat "["
2483 (read-string
2484 (format "Change `%s' to: "
2485 (setq old (YaTeX-buffer-substring
2486 (1+ beg) (1- end)))))
2487 "]"))))
2489 ((> where 0);;if point is in arguments' braces
2490 (or (looking-at "{")
2491 (progn (skip-chars-backward "^{") (forward-char -1)))
2492 (set-marker beg (1+ (point)))
2493 (forward-list 1)
2494 (forward-char -1)
2495 (set-marker end (point))
2496 (setq old (YaTeX-buffer-substring beg end))
2497 (goto-char p)
2498 (if (> (length old) 40)
2499 (setq old (concat (substring old 0 12) "..."
2500 (substring old -12))))
2501 (setq new
2502 (if (intern-soft (concat "YaTeX::" cmd))
2503 (funcall (intern-soft (concat "YaTeX::" cmd)) where)
2504 (read-string (format "Change `%s' to: " old)))))
2505 ) ;cond
2506 (if (string= old new)
2507 nil ;do not replace
2508 (delete-region beg end)
2509 (goto-char beg)
2510 (insert-before-markers new)))
2511 (set-marker beg nil)
2512 (set-marker end nil))
2513 ;;(goto-char (marker-position p))
2514 new)))
2516 (defun YaTeX-change-fontsize ()
2517 "Change large-type command."
2518 (let ((lt (append tmp-fontsize-table user-fontsize-table fontsize-table))
2519 (p (point)) large old new beg end)
2520 ;;(and (looking-at "}") (up-list -1))
2521 ;;(and (looking-at "{") (forward-char 1))
2522 ;;Is above convenient?
2523 (save-excursion
2524 (or (looking-at YaTeX-ec-regexp)
2525 (progn
2526 (skip-chars-backward (concat "^" YaTeX-ec-regexp))
2527 (forward-char -1)))
2528 (cond
2529 ((and
2530 (looking-at
2531 (concat YaTeX-ec-regexp "\\(" YaTeX-TeX-token-regexp "\\)"))
2532 (< p (match-end 0))
2533 (assoc (setq old (YaTeX-match-string 1)) lt))
2534 (goto-char p)
2535 (setq beg (match-beginning 1) end (match-end 1) ;save match position
2536 new (completing-read
2537 (format "Change font/size `%s' to : " old) lt))
2538 (delete-region beg end)
2539 (goto-char beg)
2540 (insert-before-markers new)
2541 new)
2542 (t nil)
2543 ))))
2545 (defun YaTeX-change-math-image ()
2546 "Change with image completion."
2547 (let (maketitle memberp beg end)
2548 (if (and (YaTeX-on-maketitle-p)
2549 (progn
2550 (setq maketitle (substring (YaTeX-match-string 0) 1))
2551 (setq memberp (YaTeX-math-member-p maketitle))))
2552 (let*((last-command-char (string-to-char (car memberp)))
2553 (last-command-event last-command-char))
2554 (setq beg (match-beginning 0) end (match-end 0))
2555 (delete-region beg end)
2556 (YaTeX-math-insert-sequence t (cdr memberp))))))
2558 (defun YaTeX-kill-* (&optional arg)
2559 "Parse current line and call suitable function.
2560 Non-nil for ARG kills its contents too."
2561 (interactive "P")
2562 (cond
2563 ((YaTeX-kill-some-pairs 'YaTeX-on-begin-end-p
2564 'YaTeX-goto-corresponding-environment arg))
2565 ((YaTeX-kill-some-pairs 'YaTeX-on-BEGIN-END-p
2566 'YaTeX-goto-corresponding-BEGIN-END arg))
2567 ((YaTeX-on-section-command-p YaTeX-command-token-regexp);on any command
2568 (YaTeX-kill-section-command (match-beginning 0) arg))
2569 ((YaTeX-kill-paren arg))
2570 (t (message "I don't know what to kill."))))
2572 (defun YaTeX-change-* ()
2573 "Parse current line and call suitable function."
2574 (interactive)
2575 (cond
2576 ((YaTeX-change-parentheses))
2577 ((YaTeX-change-environment))
2578 ((YaTeX-change-section))
2579 ((YaTeX-change-fontsize))
2580 ((YaTeX-change-math-image))
2581 (t (message "I don't know what to change."))))
2583 ;;;
2584 ;Check availability of add-in functions
2585 ;;;
2586 (cond
2587 ((featurep 'yatexadd) nil) ;Already provided.
2588 ((progn (load "yatexadd" t) (featurep 'yatexadd)) nil)
2589 (t (message "YaTeX add-in functions not supplied.")))
2591 (defun YaTeX-addin (name)
2592 "Check availability of addin function and call it if exists."
2593 (if (and (not (get 'YaTeX-generate 'disabled))
2594 (intern-soft (concat YaTeX-addin-prefix name))
2595 (fboundp (intern-soft (concat YaTeX-addin-prefix name))))
2596 (let ((s (funcall (intern (concat YaTeX-addin-prefix name)))))
2597 (if (stringp s) s ""))
2598 "")) ;Add in function is not bound.
2601 (defun YaTeX-on-item-p (&optional point)
2602 "Return t if POINT (default is (point)) is on \\item."
2603 (let ((p (or point (point))))
2604 (save-excursion
2605 (goto-char p)
2606 (end-of-line)
2607 (setq p (point))
2608 (re-search-backward YaTeX-paragraph-delimiter nil t)
2609 (re-search-forward YaTeX-item-regexp p t))))
2611 (defun YaTeX-in-verb-p (&optional point)
2612 "Check if POINT is in verb or verb*. Default of POINT is (point)."
2613 (setq point (or point (point)))
2614 (save-excursion
2615 (let ((md (match-data)))
2616 (goto-char point)
2617 (unwind-protect
2618 (if (not (re-search-backward
2619 (concat YaTeX-ec-regexp
2620 "\\(" YaTeX-verb-regexp "\\)"
2621 "\\([^-A-Za-z_*]\\)")
2622 (point-beginning-of-line) t))
2623 nil
2624 (goto-char (match-end 2))
2625 (skip-chars-forward
2626 (concat "^" (YaTeX-buffer-substring
2627 (match-beginning 2) (match-end 2))))
2628 (and (< (match-beginning 2) point) (< (1- point) (point))))
2629 (store-match-data md)))))
2631 (defun YaTeX-literal-p (&optional point)
2632 "Check if POINT is in verb or verb* or verbatime environment family.
2633 Default of POINT is (point)."
2634 (let ((md (match-data)))
2635 (unwind-protect
2636 (cond
2637 ((equal YaTeX-ec "\\") ;maybe LaTeX
2638 (save-excursion
2639 (and point (goto-char point))
2640 (or (YaTeX-in-verb-p (point))
2641 (and (not (looking-at "\\\\end{verb"))
2642 (YaTeX-quick-in-environment-p
2643 YaTeX-verbatim-environments))))))
2644 (store-match-data md))))
2646 (defun YaTeX-in-environment-p (env)
2647 "Return if current LaTeX environment is ENV.
2648 ENV is given in the form of environment's name or its list."
2649 (let ((md (match-data)) (nest 0) p envrx)
2650 (cond
2651 ((atom env)
2652 (setq envrx
2653 (concat "\\("
2654 (regexp-quote
2655 (YaTeX-replace-format-args
2656 YaTeX-struct-begin env "" ""))
2657 "\\)\\|\\("
2658 (regexp-quote
2659 (YaTeX-replace-format-args
2660 YaTeX-struct-end env "" ""))
2661 "\\)"))
2662 (save-excursion
2663 (setq p (catch 'open
2664 (while (YaTeX-re-search-active-backward
2665 envrx YaTeX-comment-prefix nil t)
2666 (if (match-beginning 2)
2667 (setq nest (1+ nest))
2668 (setq nest (1- nest)))
2669 (if (< nest 0)
2670 (throw 'open (cons env (match-beginning 0)))))))))
2671 ((listp env)
2672 (setq p
2673 (or (YaTeX-in-environment-p (car env))
2674 (and (cdr env) (YaTeX-in-environment-p (cdr env)))))))
2675 (store-match-data md)
2676 p;(or p (YaTeX-in-verb-p (match-beginning 0)))
2677 ))
2679 (defun YaTeX-quick-in-environment-p (env)
2680 "Check quickly but unsure if current environment is ENV.
2681 ENV is given in the form of environment's name or its list.
2682 This function returns correct result only if ENV is NOT nested."
2683 (save-excursion
2684 (let ((md (match-data)) m0 (p (point)) rc clfound)
2685 (cond
2686 ((listp env)
2687 (or (YaTeX-quick-in-environment-p (car env))
2688 (and (cdr env) (YaTeX-quick-in-environment-p (cdr env)))))
2689 (t
2690 (unwind-protect
2691 (if (prog1
2692 (YaTeX-search-active-backward
2693 (YaTeX-replace-format-args YaTeX-struct-begin env "" "")
2694 YaTeX-comment-prefix nil t)
2695 (setq m0 (match-beginning 0)))
2696 (if (YaTeX-search-active-forward
2697 (YaTeX-replace-format-args
2698 YaTeX-struct-end env)
2699 YaTeX-comment-prefix p t nil)
2700 nil ;if \end{env} found, return nil
2701 (cons env m0))) ;else, return meaningful values
2702 (store-match-data md)))))))
2704 ;; Filling \item
2705 (defun YaTeX-remove-trailing-comment (start end)
2706 "Remove trailing comment from START to end."
2707 (save-excursion
2708 (let ((trcom (concat YaTeX-comment-prefix "$")))
2709 (goto-char start)
2710 (while (re-search-forward trcom end t)
2711 (if (/= (char-after (1- (match-beginning 0))) ?\\ )
2712 (replace-match "\\1"))))))
2714 (defvar YaTeX-itemize-withlabel-max-indent-depth 8)
2715 (defun YaTeX-get-item-info (&optional recent thisenv)
2716 "Return the list of the beginning of \\item and column of its item.
2717 If it seems to be outside of itemizing environment, just return nil.
2718 Non-nil for optional argument RECENT refers recent \\item.
2719 Optional second argument THISENV omits calling YaTeX-inner-environment."
2720 (save-excursion
2721 (let* ((p (point)) env e0 c cc md
2722 (bndry (and (setq env (or thisenv (YaTeX-inner-environment t)))
2723 (get 'YaTeX-inner-environment 'point))))
2724 (end-of-line)
2725 (if (if recent
2726 (catch 'found
2727 (while (YaTeX-re-search-active-backward
2728 YaTeX-item-regexp YaTeX-comment-prefix bndry t)
2729 (setq md (match-data))
2730 (YaTeX-inner-environment t)
2731 (store-match-data md)
2732 (if (= bndry (get 'YaTeX-inner-environment 'point))
2733 (throw 'found t))))
2734 (goto-char bndry)
2735 (YaTeX-re-search-active-forward
2736 YaTeX-item-regexp YaTeX-comment-prefix p t))
2737 (progn
2738 (goto-char (match-end 0))
2739 ;(setq c (current-column))
2740 (if (string-match "desc" env)
2741 (setq c 6)
2742 (setq cc (current-column))
2743 (if (equal (following-char) ?\[) (forward-list 1))
2744 (if (< (- (current-column) cc)
2745 YaTeX-itemize-withlabel-max-indent-depth)
2746 (setq c 0)
2747 (move-to-column cc)
2748 (setq c YaTeX-itemize-withlabel-max-indent-depth)))
2749 (skip-chars-forward " \t" (point-end-of-line))
2750 (list (point-beginning-of-line) (+ c (current-column))))))))
2752 (defun YaTeX-fill-item ()
2753 "Fill item in itemize environment."
2754 (interactive)
2755 (save-excursion
2756 (let* ((p (point))
2757 (item-term (concat
2758 "\\(^[ \t]*$\\)\\|" YaTeX-item-regexp "\\|\\("
2759 YaTeX-ec-regexp "\\(begin\\|end\\)\\)"))
2760 ;;This value depends on LaTeX.
2761 fill-prefix start col
2762 (info (YaTeX-get-item-info t)))
2763 (if (null info) nil ;not on \item, do nothing
2764 (setq start (car info)
2765 col (car (cdr info)))
2766 (save-excursion
2767 (if (re-search-backward "^\\s *$" start t)
2768 ;;if separated from \item line, isolate this block
2769 (progn
2770 (setq start (1+ (match-end 0)))
2771 (goto-char start)
2772 (skip-chars-forward " \t")
2773 (delete-region (point) start) ;is this your favor???
2774 (indent-to col))))
2775 (beginning-of-line)
2776 (if (<= (save-excursion
2777 (re-search-forward
2778 (concat "\\\\end{\\|\\\\begin{\\|^[ \t]*$") nil t)
2779 (match-beginning 0))
2780 p)
2781 (progn (message "Not on itemize.") nil)
2782 (end-of-line)
2783 (newline)
2784 (indent-to col)
2785 (setq fill-prefix
2786 (YaTeX-buffer-substring (point-beginning-of-line)(point)))
2787 (beginning-of-line)
2788 (delete-region (point) (progn (forward-line 1) (point)))
2789 (re-search-forward item-term nil 1)
2790 (YaTeX-remove-trailing-comment start (point))
2791 (beginning-of-line)
2792 (push-mark (point) t)
2793 (goto-char start)
2794 (forward-line 1)
2795 (while (< (point) (mark))
2796 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
2797 (forward-line 1))
2798 (fill-region-as-paragraph start (mark))
2799 (if NTT-jTeX
2800 (while (progn(forward-line -1)(end-of-line) (> (point) start))
2801 (insert ?%)))
2802 (pop-mark))))))
2804 (defun YaTeX-fill-paragraph (arg)
2805 "YaTeX adjustment function for fill-paragraph.
2806 *Protect \\verb from unexpected broken up."
2807 (interactive "P")
2808 (cond
2809 ((not (eq major-mode 'yatex-mode)) (fill-paragraph arg))
2810 ((YaTeX-quick-in-environment-p YaTeX-fill-inhibit-environments) nil)
2811 ((YaTeX-in-math-mode-p) nil)
2812 (t
2813 (save-excursion
2814 (let*((verbrex (concat YaTeX-ec-regexp
2815 "\\(" YaTeX-verb-regexp "\\)" ;match#1
2816 "\\(.\\).*\\(\\2\\)")) ;match #2 and #3
2817 (tilderex (concat "\\("
2818 YaTeX-kanji-regexp "~"
2819 "\\)" YaTeX-ec-regexp
2820 "\\|\\("
2821 "~" YaTeX-kanji-regexp
2822 "\\)"))
2823 (p (point)) ii end poslist spacelist lenlist b e n
2824 (fill-prefix fill-prefix)
2825 (inenv (or (YaTeX-inner-environment t) "document"))
2826 (border (get 'YaTeX-inner-environment 'point)))
2827 (cond
2828 ((save-excursion (beginning-of-line) ;if point is on the first
2829 (setq end (point)) ;non-whitespace char
2830 (skip-chars-forward " \t")
2831 (equal (point) p))
2832 (setq fill-prefix (YaTeX-buffer-substring p end)))
2833 ((and ;;(not YaTeX-emacs-19)
2834 (string-match YaTeX-itemizing-env-regexp inenv)
2835 (setq ii (YaTeX-get-item-info)))
2836 (save-excursion
2837 (beginning-of-line)
2838 (indent-to-column (car (cdr ii)))
2839 (setq fill-prefix
2840 (YaTeX-buffer-substring (point) (point-beginning-of-line)))
2841 (delete-region (point) (progn (beginning-of-line) (point))))))
2842 (cond
2843 ((string-match "tabular" inenv)
2844 (let ((b (point-beginning-of-line))
2845 (e (point-end-of-line)))
2846 (if (re-search-backward
2847 "&\\|\\\\\\\\\\|\\\\\\(begin\\|end\\){" border t)
2848 (setq b (if (match-beginning 1)
2849 (progn (forward-line 1) (point))
2850 (point-beginning-of-line))))
2851 (goto-char p)
2852 (if (re-search-forward
2853 "&\\|\\\\\\\\\\|\\\\\\(end\\|begin\\){" nil t)
2854 (setq e (if (match-beginning 1)
2855 (progn (forward-line -1)
2856 (point-end-of-line))
2857 (match-beginning 0))))
2858 (set-mark e)
2859 (goto-char b)))
2860 (t
2861 (mark-paragraph)))
2862 (save-restriction
2863 (narrow-to-region (region-beginning) (region-end))
2864 (YaTeX-remove-trailing-comment (point-min) (point-max))
2865 ;; First, replace spaces in verb to _ temporarily.
2866 (goto-char (point-min))
2867 (while (YaTeX-re-search-active-forward
2868 verbrex YaTeX-comment-prefix (point-max) t)
2869 (setq end (match-beginning 3))
2870 (goto-char (match-beginning 2))
2871 (while (re-search-forward "\\s " end t)
2872 (setq poslist (cons (make-marker) poslist)
2873 spacelist (cons (preceding-char) spacelist)
2874 lenlist (cons 1 lenlist))
2875 (replace-match "_")
2876 (set-marker (car poslist) (match-beginning 0))))
2877 ;; Second, replace "表~\ref{...}" to "\\\ref{...}"
2878 (goto-char (point-min))
2879 (while (YaTeX-re-search-active-forward
2880 tilderex YaTeX-comment-prefix (point-max) t)
2881 (if (match-beginning 1)
2882 (setq b (match-beginning 1) e (match-end 1) n 1)
2883 (setq b (match-beginning 2) e (match-end 2) n 2))
2884 (setq poslist (cons (make-marker) poslist)
2885 spacelist (cons (YaTeX-match-string n) spacelist)
2886 lenlist (cons 2 lenlist))
2887 (goto-char (match-beginning 0))
2888 (delete-region (point) e)
2889 (insert YaTeX-ec YaTeX-ec) ;set-marker should be here
2890 (set-marker (car poslist) b))
2891 ;;(fill-paragraph arg)
2892 (fill-region-as-paragraph (point-min) (point-max) arg)
2893 (while spacelist
2894 (goto-char (car poslist))
2895 (set-marker (car poslist) nil)
2896 (and (eolp) (skip-chars-forward "\n\t "))
2897 (delete-char (car lenlist))
2898 (insert (car spacelist))
2899 (setq spacelist (cdr spacelist)
2900 poslist (cdr poslist)
2901 lenlist (cdr lenlist)))
2902 (goto-char (point-min))
2903 (forward-word 1)
2904 (beginning-of-line)
2905 (while (re-search-forward "\\\\\\([a-z]*ref\\|cite\\){" nil t)
2906 (if (< (point-end-of-line)
2907 (save-excursion (forward-char -1) (forward-list 1) (point)))
2908 (progn (end-of-line)
2909 (if (save-excursion
2910 (backward-word 1)
2911 (looking-at "[^0-9A-z!-)]"))
2912 (insert YaTeX-comment-prefix)))))
2913 ;; Nonbreak space `~'
2914 (goto-char (point-min))
2915 (while (YaTeX-re-search-active-forward
2916 "~\\(\\s *\\)$" YaTeX-comment-prefix (point-max) t)
2917 (delete-region (match-beginning 1) (match-end 1))
2918 (insert YaTeX-comment-prefix))
2919 (goto-char (point-min))
2920 (if (and NTT-jTeX (looking-at "[ \t]\\|^$"))
2921 (progn
2922 (goto-char (point-min))
2923 (while (not (eobp))
2924 (end-of-line)
2925 (or (bolp)
2926 (save-excursion
2927 (backward-word 1)
2928 (looking-at "[0-9A-z!-)]")) ;is not japanese string
2929 (progn (setq p (point)) (insert YaTeX-comment-prefix)))
2930 (forward-line 1))
2931 (goto-char p)
2932 (if (looking-at "%") (delete-char 1)) ;remove last inserted `%'
2933 ))))))))
2935 (if (fboundp 'YaTeX-saved-indent-new-comment-line) nil
2936 (fset 'YaTeX-saved-indent-new-comment-line
2937 (symbol-function 'indent-new-comment-line))
2938 (fset 'indent-new-comment-line 'YaTeX-indent-new-comment-line))
2940 (defun YaTeX-indent-new-comment-line (&optional soft)
2941 "Tuned `indent-new-comment-line' function for yatex.
2942 See the documentation of `YaTeX-saved-indent-new-comment-line'."
2943 (interactive)
2944 (cond
2945 ((or (not (memq major-mode '(yatex-mode yahtml-mode)))
2946 (string-match
2947 "document"
2948 (or (and (boundp 'inenv) inenv)
2949 (or (YaTeX-inner-environment t) "document"))))
2950 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft))))
2951 ; ((and (eq major-mode 'yahtml-mode)
2952 ; (string-match
2953 ; "^[Pp][Rr][Ee]" (yahtml-inner-environment-but "^[Aa]\\b" t)))
2954 ; (yahtml-indent-new-commnet-line))
2955 ((and (eq major-mode 'yatex-mode) ;1997/2/4
2956 (YaTeX-in-math-mode-p)) nil) ;1996/12/30
2957 (t (let (fill-prefix)
2958 (apply 'YaTeX-saved-indent-new-comment-line (if soft (list soft)))))))
2960 (defun YaTeX-fill-* ()
2961 "Fill paragraph according to its condition."
2962 (interactive)
2963 (cond
2964 ((YaTeX-fill-item))
2965 ))
2967 ;; Accent completion
2968 (defun YaTeX-read-accent-char (x)
2969 "Read char in accent braces."
2970 (let ((c (read-char)))
2971 (concat
2972 (if (and (or (= c ?i) (= c ?j))
2973 (not (string-match (regexp-quote x) "cdb")))
2974 "\\" "")
2975 (char-to-string c))))
2977 (defun YaTeX-make-accent ()
2978 "Make accent usage."
2979 (interactive)
2980 (message "1:` 2:' 3:^ 4:\" 5:~ 6:= 7:. u v H t c d b")
2981 (let ((c (read-char))(case-fold-search nil))
2982 (setq c (cond ((and (> c ?0) (< c ?8))
2983 (substring "`'^\"~=." (1- (- c ?0)) (- c ?0)))
2984 ((= c ?h) "H")
2985 (t (char-to-string c))))
2986 (if (not (string-match c "`'^\"~=.uvHtcdb")) nil
2987 (insert "\\" c "{}")
2988 (backward-char 1)
2989 (insert (YaTeX-read-accent-char c))
2990 (if (string= c "t") (insert (YaTeX-read-accent-char c)))
2991 (forward-char 1))))
2993 ;; Indentation
2994 (defun YaTeX-current-indentation ()
2995 "Return the indentation of current environment."
2996 (save-excursion
2997 ;;(beginning-of-line)
2998 (if (YaTeX-beginning-of-environment t)
2999 (goto-char (get 'YaTeX-inner-environment 'point))
3000 (forward-line -1)
3001 (beginning-of-line)
3002 (skip-chars-forward " \t"))
3003 (current-column)))
3005 (defun YaTeX-previous-line-indentation ()
3006 (save-excursion
3007 (forward-line -1)
3008 (skip-chars-forward " \t")
3009 (current-column)))
3011 (defvar YaTeX-noindent-env-regexp "verbatim\\*?\\|alltt"
3012 "*Regexp of environment names that should begin with no indentation.
3013 All verbatime-like environment name should match with.")
3014 (defun YaTeX-indent-line ()
3015 "Indent corrent line referrin current environment."
3016 (interactive)
3017 (let ((indent-relative
3018 (function
3019 (lambda (&optional additional)
3020 (YaTeX-reindent
3021 (+ (YaTeX-current-indentation)
3022 (or additional 0)
3023 YaTeX-environment-indent)))))
3024 sect depth iteminfo (p (point)) pp (peol (point-end-of-line)) begend
3025 ;;inenv below is sometimes defined in YaTeX-indent-new-comment-line
3026 (inenv (or (and (boundp 'inenv) inenv) (YaTeX-inner-environment t))))
3027 ;;(if NTT-jTeX ;;Do you need this section?
3028 ;; (save-excursion
3029 ;; (end-of-line)
3030 ;; (let ((p (point)))
3031 ;; (forward-line -1)
3032 ;; (end-of-line)
3033 ;; (or (= p (point))
3034 ;; (progn (backward-char (length YaTeX-comment-prefix))
3035 ;; (not (looking-at (regexp-quote YaTeX-comment-prefix))))
3036 ;; (progn
3037 ;; (skip-chars-backward YaTeX-comment-prefix)
3038 ;; (kill-line))))))
3039 (or inenv (setq inenv "document")) ;is the default environment
3040 (cond
3041 ((and
3042 (prog1 (YaTeX-on-begin-end-p)
3043 (setq begend (match-beginning 0)))
3044 (or (match-beginning 2) ;if \end
3045 (and (match-beginning 3) ;if \) \]
3046 (= (char-syntax (char-after (1+ (match-beginning 3)))) ?\)))))
3047 (YaTeX-reindent
3048 (save-excursion
3049 (YaTeX-goto-corresponding-environment)
3050 (current-column))))
3051 ;; on the begining of verbatime line, remove all indentation
3052 ((and begend ;; match-beginning 0 of \begin
3053 YaTeX-noindent-env-regexp
3054 (stringp YaTeX-noindent-env-regexp)
3055 (save-excursion
3056 (and ;; if the \begin is the first declaration of this line
3057 (progn (beginning-of-line) (skip-chars-forward " \t")
3058 (= begend (point)))
3059 (progn
3060 (goto-char begend)
3061 (looking-at
3062 (concat YaTeX-ec-regexp
3063 "begin{\\(" YaTeX-noindent-env-regexp "\\)}"))))))
3064 (save-excursion
3065 (goto-char begend)
3066 (delete-region (point) (point-beginning-of-line))))
3067 ((string-match YaTeX-equation-env-regexp inenv)
3068 (YaTeX-indent-line-equation)) ;autoload-ed from yatexenv
3069 (;(YaTeX-in-environment-p '("itemize" "enumerate" "description" "list"))
3070 (string-match YaTeX-itemizing-env-regexp inenv)
3071 ;;(YaTeX-on-item-p) ??
3072 ;;(setq iteminfo (YaTeX-get-item-info t))
3073 (if (save-excursion
3074 (beginning-of-line)
3075 (re-search-forward YaTeX-item-regexp peol t))
3076 (progn
3077 (save-excursion
3078 (goto-char (1+ (match-beginning 0)))
3079 (setq depth
3080 (* YaTeX-environment-indent
3081 (cond
3082 ((looking-at "subsubsub") 3)
3083 ((looking-at "subsub") 2)
3084 ((looking-at "sub") 1)
3085 (t 0)))))
3086 (funcall indent-relative depth))
3087 (YaTeX-reindent (or (car (cdr (YaTeX-get-item-info t inenv)))
3088 (+ (save-excursion
3089 (beginning-of-line)
3090 (YaTeX-current-indentation))
3091 YaTeX-environment-indent))))
3093 ((YaTeX-literal-p) ;verbatims
3094 (tab-to-tab-stop))
3095 ((string-match "\\(tabular\\|array\\)" inenv) ;1.73
3096 (let ((n 1))
3097 (condition-case err
3098 (save-excursion
3099 (beginning-of-line)
3100 (skip-chars-forward "[ \t]")
3101 ;;(if (looking-at "&") (forward-char 1))
3102 (require 'yatexenv)
3103 (setq n (car (YaTeX-array-what-column-internal))))
3104 (error nil))
3105 (YaTeX-reindent
3106 (+ (YaTeX-current-indentation)
3107 YaTeX-environment-indent
3108 (* (1- n) YaTeX-tabular-indentation)))))
3109 ((and inenv (not (equal "document" inenv)))
3110 (funcall indent-relative))
3111 ((YaTeX-on-section-command-p YaTeX-sectioning-regexp)
3112 (require 'yatexsec) ;to know YaTeX-sectioning-level
3113 (setq sect (YaTeX-match-string 1))
3114 (if (string-match "\\*$" sect)
3115 (setq sect (substring sect 0 -1)))
3116 (YaTeX-reindent
3117 (* (max
3118 (1- ;I want chapter to have indentation 0
3119 (or (cdr (assoc sect YaTeX-sectioning-level))
3120 0))
3121 0)
3122 YaTeX-environment-indent)))
3123 ;;Default movement
3124 ((and (bolp) fill-prefix) (insert fill-prefix))
3125 (t (save-excursion
3126 (beginning-of-line)
3127 (if fill-prefix
3128 (progn
3129 (delete-region (point)
3130 (progn (skip-chars-forward " \t")
3131 (point)))
3132 (insert fill-prefix))
3133 (skip-chars-forward " \t")
3134 (if (bobp)
3135 nil
3136 (indent-relative-maybe))))
3137 (skip-chars-forward " \t")))
3138 ;;if current line is \begin, re-indent \end too
3139 (if (and (YaTeX-on-begin-end-p) (match-beginning 1))
3140 (save-excursion
3141 ;;(beginning-of-line)
3142 ;;(search-forward "\\begin")
3143 (goto-char (match-beginning 0))
3144 (setq depth (current-column))
3145 (YaTeX-goto-corresponding-environment)
3146 (YaTeX-reindent depth)))
3147 (if (or
3148 (and NTT-jTeX
3149 (save-excursion (beginning-of-line) (looking-at "[ \t]")))
3150 (save-excursion
3151 (beginning-of-line)
3152 (and
3153 (not (bobp))
3154 (progn
3155 (backward-char 1)
3156 (re-search-backward
3157 "\\\\\\(\\(page\\)?ref\\|cite\\){" (point-beginning-of-line) t))
3158 (goto-char (1- (match-end 0)))
3159 (> (save-excursion
3160 (condition-case ()
3161 (progn (forward-list 1) (point))
3162 (error (point-max))))
3163 (point-end-of-line)))))
3164 (save-excursion
3165 (end-of-line)
3166 (let ((p (point)))
3167 (forward-line -1)
3168 (end-of-line)
3169 (or (= p (point))
3170 (looking-at (regexp-quote YaTeX-comment-prefix))
3171 (bobp) (bolp)
3172 (save-excursion
3173 (backward-word 1)
3174 (looking-at "\\sw+")) ;is not japanese string
3175 (insert YaTeX-comment-prefix)))))))
3177 (defun YaTeX-comment-line-break (&optional soft)
3178 "Call comment-indent-new-line and YaTeX-indent-line"
3179 (comment-indent-new-line soft)
3180 (YaTeX-indent-line))
3182 (defun YaTeX-latex2e-p ()
3183 (let ((b (current-buffer))
3184 (ptn (concat YaTeX-ec "documentclass")))
3185 (unwind-protect
3186 (or (save-excursion (search-backward ptn nil t))
3187 (progn
3188 (YaTeX-visit-main t)
3189 (save-excursion (search-backward ptn nil t))))
3190 (set-buffer b))))
3192 (provide 'yatex)
3193 (defvar yatex-mode-load-hook nil
3194 "*List of functions to be called when yatex.el is loaded.")
3195 (if (and YaTeX-emacs-19 YaTeX-display-color-p (not (featurep 'yatex19)))
3196 (load "yatex19"))
3197 (load "yatexhks" t)
3199 ;;-------------------- Final hook jobs --------------------
3200 (substitute-all-key-definition
3201 'fill-paragraph 'YaTeX-fill-paragraph YaTeX-mode-map)
3202 (substitute-all-key-definition
3203 'kill-buffer 'YaTeX-kill-buffer YaTeX-mode-map)
3204 (run-hooks 'yatex-mode-load-hook)
3206 ;; `History' was moved to ChangeLog
3207 ;----------------------------- End of yatex.el -----------------------------
3209 ; Local variables:
3210 ; coding: sjis
3211 ; End: