yatex

view yatex.el @ 322:c456fd55013e

Add `dia' to YaTeX-file-processor-alist-default
author HIROSE Yuuji <yuuji@gentei.org>
date Sun, 06 Jul 2014 23:25:21 +0900
parents 774935c77366
children d08c824ababe
line source
1 ;;; yatex.el --- Yet Another tex-mode for emacs //野鳥// -*- coding: sjis -*-
2 ;;; (c)1991-2013 by HIROSE Yuuji.[yuuji@yatex.org]
3 ;;; Last modified Sun Jul 6 13:25:42 2014 on firestorm
4 ;;; $Id$
5 ;;; The latest version of this software is always available at;
6 ;;; http://www.yatex.org/
8 ;;; Code:
9 (require 'comment)
10 (require 'yatexlib)
11 (defconst YaTeX-revision-number "1.77.1"
12 "Revision number of running yatex.el")
14 ;---------- Local variables ----------
15 (defvar YaTeX-prefix "\C-c"
16 "*Prefix key to call YaTeX functions.
17 You can select favorite prefix key by setq in your ~/.emacs.")
19 (defvar YaTeX-environment-indent 1
20 "*Indentation depth at column width in LaTeX environments.")
22 (defvar YaTeX-fill-prefix nil
23 "*fill-prefix used for auto-fill-mode.
24 The default value is nil.")
26 (defvar YaTeX-fill-column 72
27 "*fill-column used for auto-fill-mode.")
29 (defvar YaTeX-comment-prefix "%"
30 "TeX comment prefix.")
32 (defvar YaTeX-current-position-register ?3
33 "*Position register to keep where the last completion was done.
34 All of YaTeX completing input store the current position into
35 the register YaTeX-current-position-register. So every time you
36 make a trip to any other part of text other than you are writing, you can
37 return to the editing paragraph by calling register-to-point with argument
38 YaTeX-current-position-register.")
40 ;;(defvar YaTeX-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 ("multicolumn" 3) ("shortstack") ("parbox" 2)
265 ;; for mathmode accent
266 ("tilde") ("hat") ("check") ("bar") ("dot") ("ddot") ("vec")
267 ("widetilde") ("widehat") ("overline") ("overrightarrow")
268 ;; section types in mathmode
269 ("frac" 2) ("sqrt") ("mathrm") ("mathbf") ("mathit")
271 )
272 (if YaTeX-use-LaTeX2e
273 '(("documentclass") ("usepackage")
274 ("textbf") ("textgt") ("textit") ("textmc") ("textmd") ("textnormal")
275 ("textrm") ("textsc") ("textsf") ("textsl") ("texttt") ("textup")
276 ("mathbf") ("mathcal") ("mathit") ("mathnormal") ("mathrm")
277 ("mathsf") ("mathtt")
278 ("textcircled")
279 ("scalebox" 1) ;is faking of argument position
280 ("rotatebox" 2) ("resizebox" 3) ("reflectbox")
281 ("colorbox" 2) ("fcolorbox" 3) ("textcolor" 2) ("color") ("pagecolor")
282 ("includegraphics") ("includegraphics*")
283 ("bou") ;defined in plext
284 ("url") ;defined in url
285 ("shadowbox") ("doublebox") ("ovalbox") ("Ovalbox")
286 ("fancyoval") ;defined in fancybox
287 ("keytop") ("mask" 2) ("maskbox" 5) ;defined in ascmac
288 ("bm") ;deined in bm
289 ("verbfile") ("listing") ;defined in misc
290 ("slashbox" 2) ("backslashbox" 2) ;defined in slashbox
291 ))
292 (if YaTeX-use-AMS-LaTeX
293 '(("DeclareMathOperator" 2) ("boldsymbol") ("pmb") ("eqref")
294 ("tag") ("tag*"))))
295 "Default completion table for section-type completion.")
297 (defvar user-section-table nil)
298 (defvar tmp-section-table nil)
299 (defvar YaTeX-ams-math-begin-alist
300 '(("align") ("align*") ("multline") ("multline*") ("gather") ("gather*")
301 ("alignat") ("alignat*") ("xalignat") ("xalignat*")
302 ("xxalignat") ("xxalignat*") ("flalign") ("flalign*") ("equation*")))
303 (defvar YaTeX-ams-math-gathering-alist
304 '(("matrix") ("pmatrix") ("bmatrix") ("Bmatrix") ("vmatrix") ("Vmatrix")
305 ("split") ("split*") ("aligned") ("aligned*") ("alignedat") ("gathered")
306 ("smallmatrix") ("cases") ("subequations")))
307 ;; Prepare list(not alist) for YaTeX::ref in yatexadd.el
308 (defvar YaTeX-math-begin-list
309 (mapcar 'car YaTeX-ams-math-begin-alist))
310 (defvar YaTeX-math-gathering-list ;used in yatexadd.el#yatex::ref
311 (mapcar 'car YaTeX-ams-math-gathering-alist))
314 (defvar YaTeX-ams-env-table
315 (append YaTeX-ams-math-begin-alist YaTeX-ams-math-gathering-alist)
316 "*Standard AMS-LaTeX(2e) environment completion table.")
318 ; Set tex-environment possible completion
319 (defvar env-table
320 (append
321 '(("quote") ("quotation") ("center") ("verse") ("document")
322 ("verbatim") ("itemize") ("enumerate") ("description")
323 ("list") ("tabular") ("tabular*") ("table") ("tabbing") ("titlepage")
324 ("sloppypar") ("picture") ("displaymath")
325 ("eqnarray") ("eqnarray*") ("figure") ("equation") ("equation*")
326 ("abstract") ("array")
327 ("thebibliography") ("theindex") ("flushleft") ("flushright")
328 ("minipage")
329 ("supertabular")
330 )
331 (if YaTeX-use-LaTeX2e
332 '(("comment") ;defined in version
333 ("longtable") ;defined in longtable
334 ("screen") ("boxnote") ("shadebox") ;; ("itembox") ;in ascmac
335 ("alltt") ;defined in alltt
336 ("multicols") ;defined in multicol
337 ("breakbox"))) ;defined in eclbkbox
338 (if YaTeX-use-AMS-LaTeX YaTeX-ams-env-table))
339 "Default completion table for begin-type completion.")
341 (defvar user-env-table nil)
342 (defvar tmp-env-table nil)
344 ; Set {\Large }-like completion
345 (defvar fontsize-table
346 '(("rm") ("em") ("bf") ("boldmath") ("it") ("sl") ("sf") ("sc") ("tt")
347 ("dg") ("dm")
348 ("tiny") ("scriptsize") ("footnotesize") ("small")("normalsize")
349 ("large") ("Large") ("LARGE") ("huge") ("Huge")
350 ("rmfamily") ("sffamily") ("ttfamily")
351 ("mdseries") ("bfseries") ("upshape")
352 ("itshape") ("slshape") ("scshape")
353 )
354 "Default completion table for large-type completion.")
356 (defvar LaTeX2e-fontstyle-alist
357 '(("rm" . "rmfamily")
358 ("sf" . "sffamily")
359 ("tt" . "ttfamily")
360 ("md" . "mdseries")
361 ("bf" . "bfseries")
362 ("up" . "upshape")
363 ("it" . "itshape")
364 ("sl" . "slshape")
365 ("sc" . "scshape")))
367 (defvar user-fontsize-table nil)
368 (defvar tmp-fontsize-table nil)
370 (defvar singlecmd-table
371 (append
372 '(("maketitle") ("makeindex") ("sloppy") ("protect") ("par")
373 ("LaTeX") ("TeX") ("item") ("item[]") ("appendix") ("hline") ("kill")
374 ;;("rightarrow") ("Rightarrow") ("leftarrow") ("Leftarrow")
375 ("pagebreak") ("nopagebreak") ("tableofcontents")
376 ("newpage") ("clearpage") ("cleardoublepage")
377 ("footnotemark") ("verb") ("verb*")
378 ("linebreak") ("pagebreak") ("noindent") ("indent")
379 ("left") ("right") ("dots") ("smallskip") ("medskip") ("bigskip")
380 ("displaystyle")
381 )
382 (if YaTeX-greek-by-maketitle-completion
383 '(("alpha") ("beta") ("gamma") ("delta") ("epsilon")
384 ("varepsilon") ("zeta") ("eta") ("theta")("vartheta")
385 ("iota") ("kappa") ("lambda") ("mu") ("nu") ("xi") ("pi")
386 ("varpi") ("rho") ("varrho") ("sigma") ("varsigma") ("tau")
387 ("upsilon") ("phi") ("varphi") ("chi") ("psi") ("omega")
388 ("Gamma") ("Delta") ("Theta") ("Lambda")("Xi") ("Pi")
389 ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")))
390 (if YaTeX-use-LaTeX2e
391 '(("return") ("Return") ("yen"))) ;defined in ascmac
392 (if YaTeX-use-AMS-LaTeX
393 '(("nonumber")))
394 )
395 "Default completion table for maketitle-type completion.")
397 (defvar user-singlecmd-table nil)
398 (defvar tmp-singlecmd-table nil)
400 ;---------- Key mode map ----------
401 ;;;
402 ;; Create new key map: YaTeX-mode-map
403 ;; Do not change this section.
404 ;;;
405 (defvar YaTeX-mode-map nil
406 "Keymap used in YaTeX mode")
408 (defvar YaTeX-prefix-map nil
409 "Keymap used when YaTeX-prefix key pushed")
411 (defvar YaTeX-user-extensional-map (make-sparse-keymap)
412 "*Keymap used for the user's customization")
413 (defvar YaTeX-current-completion-type nil
414 "Has current completion type. This may be used in YaTeX addin functions.")
416 (defvar YaTeX-modify-mode nil
417 "*Current editing mode.
418 When non-nil, each opening parentheses only opens,
419 nil enters both open/close parentheses when opening parentheses key pressed.")
421 (defvar YaTeX-math-mode nil
422 "Holds whether current mode is math-mode.")
423 ;;;
424 ;; Define key table
425 ;;;
426 (if YaTeX-mode-map
427 nil
428 (setq YaTeX-mode-map (make-sparse-keymap))
429 (setq YaTeX-prefix-map (make-sparse-keymap))
430 (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
431 (define-key YaTeX-mode-map "{" 'YaTeX-insert-braces)
432 (define-key YaTeX-mode-map "(" 'YaTeX-insert-parens)
433 (define-key YaTeX-mode-map "$" 'YaTeX-insert-dollar)
434 (define-key YaTeX-mode-map "|" 'YaTeX-insert-bar)
435 (define-key YaTeX-mode-map "&" 'YaTeX-insert-amper)
436 (define-key YaTeX-mode-map "[" 'YaTeX-insert-brackets)
437 (define-key YaTeX-mode-map YaTeX-prefix YaTeX-prefix-map)
438 (define-key YaTeX-mode-map "\M-\C-@" 'YaTeX-mark-environment)
439 (define-key YaTeX-mode-map "\M-\C-a" 'YaTeX-beginning-of-environment)
440 (define-key YaTeX-mode-map "\M-\C-e" 'YaTeX-end-of-environment)
441 (define-key YaTeX-mode-map "\M-\C-m" 'YaTeX-intelligent-newline)
442 (define-key YaTeX-mode-map "\C-i" 'YaTeX-indent-line)
443 (YaTeX-define-key "%" 'YaTeX-%-menu)
444 (YaTeX-define-key "t" 'YaTeX-typeset-menu)
445 (YaTeX-define-key "w" 'YaTeX-switch-mode-menu)
446 (YaTeX-define-key "'" 'YaTeX-prev-error)
447 (YaTeX-define-key "^" 'YaTeX-visit-main)
448 (YaTeX-define-key "4^" 'YaTeX-visit-main-other-window)
449 (YaTeX-define-key "4g" 'YaTeX-goto-corresponding-*-other-window)
450 (YaTeX-define-key "44" 'YaTeX-switch-to-window)
451 (and YaTeX-emacs-19 window-system
452 (progn
453 (YaTeX-define-key "5^" 'YaTeX-visit-main-other-frame)
454 (YaTeX-define-key "5g" 'YaTeX-goto-corresponding-*-other-frame)
455 (YaTeX-define-key "55" 'YaTeX-switch-to-window)))
456 (YaTeX-define-key " " 'YaTeX-do-completion)
457 (YaTeX-define-key "v" 'YaTeX-version)
459 (YaTeX-define-key "}" 'YaTeX-insert-braces-region)
460 (YaTeX-define-key "]" 'YaTeX-insert-brackets-region)
461 (YaTeX-define-key ")" 'YaTeX-insert-parens-region)
462 (YaTeX-define-key "$" 'YaTeX-insert-dollars-region)
463 (YaTeX-define-key "i" 'YaTeX-fill-item)
464 (YaTeX-define-key "\\"
465 '(lambda () (interactive)
466 (insert (if (YaTeX-in-math-mode-p) "\\backslash" "\\textbackslash"))))
467 (if YaTeX-no-begend-shortcut
468 (progn
469 (YaTeX-define-key "B" 'YaTeX-make-begin-end-region)
470 (YaTeX-define-key "b" 'YaTeX-make-begin-end))
471 (YaTeX-define-begend-key "bc" "center")
472 (YaTeX-define-begend-key "bd" "document")
473 (YaTeX-define-begend-key "bD" "description")
474 (YaTeX-define-begend-key "be" "enumerate")
475 (YaTeX-define-begend-key "bE" "equation")
476 (YaTeX-define-begend-key "bi" "itemize")
477 (YaTeX-define-begend-key "bl" "flushleft")
478 (YaTeX-define-begend-key "bm" "minipage")
479 (YaTeX-define-begend-key "bt" "tabbing")
480 (YaTeX-define-begend-key "bT" "tabular")
481 (YaTeX-define-begend-key "b\^t" "table")
482 (YaTeX-define-begend-key "bp" "picture")
483 (YaTeX-define-begend-key "bq" "quote")
484 (YaTeX-define-begend-key "bQ" "quotation")
485 (YaTeX-define-begend-key "br" "flushright")
486 (YaTeX-define-begend-key "bv" "verbatim")
487 (YaTeX-define-begend-key "bV" "verse")
488 (YaTeX-define-key "B " 'YaTeX-make-begin-end-region)
489 (YaTeX-define-key "b " 'YaTeX-make-begin-end))
490 (YaTeX-define-key "e" 'YaTeX-end-environment)
491 (YaTeX-define-key "S" 'YaTeX-make-section-region)
492 (YaTeX-define-key "s" 'YaTeX-make-section)
493 (YaTeX-define-key "L" 'YaTeX-make-fontsize-region)
494 (YaTeX-define-key "l" 'YaTeX-make-fontsize)
495 (YaTeX-define-key "m" 'YaTeX-make-singlecmd)
496 (YaTeX-define-key "." 'YaTeX-comment-paragraph)
497 (YaTeX-define-key "," 'YaTeX-uncomment-paragraph)
498 (YaTeX-define-key ">" 'YaTeX-comment-region)
499 (YaTeX-define-key "<" 'YaTeX-uncomment-region)
500 (YaTeX-define-key "g" 'YaTeX-goto-corresponding-*)
501 (YaTeX-define-key "k" 'YaTeX-kill-*)
502 (YaTeX-define-key "c" 'YaTeX-change-*)
503 (YaTeX-define-key "a" 'YaTeX-make-accent)
504 (YaTeX-define-key "?" 'YaTeX-help)
505 (YaTeX-define-key "/" 'YaTeX-apropos)
506 (YaTeX-define-key "&" 'YaTeX-what-column)
507 (YaTeX-define-key "d" 'YaTeX-display-hierarchy)
508 (YaTeX-define-key "x" YaTeX-user-extensional-map)
509 (YaTeX-define-key "n"
510 '(lambda () (interactive)
511 (insert "\\" (if (YaTeX-on-section-command-p "o?oalign") "crcr" "\\"))))
512 (if YaTeX-dos
513 (define-key YaTeX-prefix-map "\C-r"
514 '(lambda () (interactive)
515 (YaTeX-set-screen-height YaTeX-saved-screen-height) (recenter)))))
517 (defvar YaTeX-section-completion-map nil
518 "*Key map used at YaTeX completion in the minibuffer.")
519 (if YaTeX-section-completion-map nil
520 (setq YaTeX-section-completion-map
521 (copy-keymap (or (and (boundp 'gmhist-completion-map)
522 gmhist-completion-map)
523 minibuffer-local-completion-map)))
524 (define-key YaTeX-section-completion-map
525 " " 'YaTeX-minibuffer-complete)
526 (define-key YaTeX-section-completion-map
527 "\C-i" 'YaTeX-minibuffer-complete)
528 (define-key YaTeX-section-completion-map
529 "\C-v" 'YaTeX-read-section-with-overview))
531 (defvar YaTeX-recursive-map nil
532 "*Key map used at YaTeX reading arguments in the minibuffer.")
533 (if YaTeX-recursive-map nil
534 (setq YaTeX-recursive-map (copy-keymap global-map))
535 (define-key YaTeX-recursive-map YaTeX-prefix YaTeX-prefix-map)
536 (mapcar
537 (function
538 (lambda (key)
539 (define-key YaTeX-mode-map (car key) 'YaTeX-math-insert-sequence)
540 (define-key YaTeX-recursive-map (car key) 'YaTeX-math-insert-sequence)))
541 YaTeX-math-key-list))
542 ;---------- Define other variable ----------
543 (defvar YaTeX-env-name "document" "*Initial tex-environment completion")
544 (defvar YaTeX-section-name
545 (if YaTeX-use-LaTeX2e "documentclass" "documentstyle")
546 "*Initial tex-section completion")
547 (defvar YaTeX-fontsize-name "large" "*Initial fontsize completion")
548 (defvar YaTeX-single-command "maketitle" "*Initial LaTeX single command")
549 (defvar YaTeX-kanji-code (if YaTeX-dos 1 2)
550 "*File kanji code used by Japanese TeX.
551 nil: Do not care (Preserve coding-system)
552 0: no-converion (mule)
553 1: Shift JIS
554 2: JIS
555 3: EUC
556 4: UTF-8")
558 (defvar YaTeX-coding-system nil "File coding system used by Japanese TeX.")
559 (cond
560 (YaTeX-emacs-20
561 (setq YaTeX-coding-system
562 (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist))))
563 ((boundp 'MULE)
564 (setq YaTeX-coding-system
565 (symbol-value (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist))))))
567 (defvar YaTeX-mode-syntax-table nil
568 "*Syntax table for yatex-mode")
570 (if YaTeX-mode-syntax-table nil
571 (setq YaTeX-mode-syntax-table (make-syntax-table (standard-syntax-table)))
572 (modify-syntax-entry ?\n " " YaTeX-mode-syntax-table)
573 (modify-syntax-entry ?\{ "(}" YaTeX-mode-syntax-table)
574 (modify-syntax-entry ?\} "){" YaTeX-mode-syntax-table)
575 (modify-syntax-entry ?\t " " YaTeX-mode-syntax-table)
576 (modify-syntax-entry ?\f ">" YaTeX-mode-syntax-table)
577 (modify-syntax-entry ?\n ">" YaTeX-mode-syntax-table)
578 (modify-syntax-entry ?$ "$$" 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))
583 ;---------- Provide YaTeX-mode ----------
584 ;;;
585 ;; Major mode definition
586 ;;;
587 (defun yatex-mode ()
588 " Yet Another LaTeX mode: Major mode for editing input files of LaTeX.
589 -You can invoke processes concerning LaTeX typesetting by
590 \\[YaTeX-typeset-menu]
591 -Complete LaTeX environment form of `\\begin{env} ... \\end{env}' by
592 \\[YaTeX-make-begin-end]
593 -Enclose region into some environment by
594 \\[universal-argument] \\[YaTeX-make-begin-end]
595 -Complete LaTeX command which takes argument like `\\section{}' by
596 \\[YaTeX-make-section]
597 -Put LaTeX command which takes no arguments like `\\maketitle' by
598 \\[YaTeX-make-singlecmd]
599 -Complete font or character size descriptor like `{\\large }' by
600 \\[YaTeX-make-fontsize]
601 -Enclose region into those descriptors above by
602 \\[universal-argument] \\[YaTeX-make-fontsize]
603 -Enter European accent notations by
604 \\[YaTeX-make-accent]
605 -Toggle various modes of YaTeX by
606 \\[YaTeX-switch-mode-menu]
607 -Change environt name (on the begin/end line) by
608 \\[YaTeX-change-*]
609 -Kill LaTeX command/environment sequences by
610 \\[YaTeX-kill-*]
611 -Kill LaTeX command/environment with its contents
612 \\[universal-argument] \\[YaTeX-kill-*]
613 -Go to corresponding object (begin/end, file, labels) by
614 \\[YaTeX-goto-corresponding-*] or
615 \\[YaTeX-goto-corresponding-*-other-window] (in other window)
616 \\[YaTeX-goto-corresponding-*-other-frame] (in other frame)
617 -Go to main LaTeX source text by
618 \\[YaTeX-visit-main] or
619 \\[YaTeX-visit-main-other-window] (in other window)
620 \\[YaTeX-visit-main-other-frame] (in other frame)
621 -Comment out or uncomment region by
622 \\[YaTeX-comment-region] or \\[YaTeX-uncomment-region]
623 -Comment out or uncomment paragraph by
624 \\[YaTeX-comment-paragraph] or \\[YaTeX-uncomment-paragraph]
625 -Make an \\item entry hang-indented by
626 \\[YaTeX-fill-item]
627 -Enclose the region with parentheses by
628 \\[YaTeX-insert-parens-region]
629 \\[YaTeX-insert-braces-region]
630 \\[YaTeX-insert-brackets-region]
631 \\[YaTeX-insert-dollars-region]
632 -Look up the corresponding column header of tabular environment by
633 \\[YaTeX-what-column]
634 -Enter a newline and an entry suitable for environment by
635 \\[YaTeX-intelligent-newline]
636 -View the structure of file inclusion by
637 \\[YaTeX-display-hierarchy]
638 -Refer the online help of popular LaTeX commands by
639 \\[YaTeX-help] (help)
640 \\[YaTeX-apropos] (apropos)
641 -Edit `%# notation' by
642 \\[YaTeX-%-menu]
644 Those are enough for fastening your editing of LaTeX source. But further
645 more features are available and they are documented in the manual.
646 "
647 (interactive)
648 (kill-all-local-variables)
649 (setq major-mode 'yatex-mode)
650 (setq mode-name (if YaTeX-japan "やてふ" "YaTeX"))
651 (mapcar 'make-local-variable
652 '(dvi2-command fill-column fill-prefix
653 tmp-env-table tmp-section-table tmp-fontsize-table
654 tmp-singlecmd-table paragraph-start paragraph-separate
655 YaTeX-math-mode indent-line-function comment-line-break-function
656 comment-start comment-start-skip
657 ))
658 (cond ((null YaTeX-kanji-code)
659 nil)
660 ((boundp 'MULE)
661 (set-file-coding-system YaTeX-coding-system))
662 ((and YaTeX-emacs-20 (boundp 'buffer-file-coding-system))
663 (setq buffer-file-coding-system
664 (or (and (fboundp 'set-auto-coding) buffer-file-name
665 (save-excursion
666 (goto-char (point-min))
667 (set-auto-coding buffer-file-name (buffer-size))))
668 YaTeX-coding-system)))
669 ((featurep 'mule)
670 (set-file-coding-system YaTeX-coding-system))
671 ((boundp 'NEMACS)
672 (make-local-variable 'kanji-fileio-code)
673 (setq kanji-fileio-code YaTeX-kanji-code)))
674 (setq fill-column YaTeX-fill-column
675 fill-prefix YaTeX-fill-prefix
676 paragraph-start YaTeX-paragraph-start
677 paragraph-separate YaTeX-paragraph-separate
678 indent-line-function 'YaTeX-indent-line
679 comment-start YaTeX-comment-prefix
680 comment-end ""
681 comment-start-skip "[^\\\\]%+[ \t]*"
682 local-abbrev-table yatex-mode-abbrev-table)
683 (if (fboundp 'comment-indent-new-line) ;for Emacs21
684 (setq comment-line-break-function 'YaTeX-comment-line-break))
686 (if (and YaTeX-use-font-lock (featurep 'font-lock))
687 (progn
688 (require 'yatex19)
689 (YaTeX-font-lock-set-default-keywords)
690 (or (featurep 'xemacs)
691 (set (make-local-variable 'font-lock-defaults)
692 (get 'yatex-mode 'font-lock-defaults)))
693 ;;(font-lock-mode 1)
694 ))
695 (use-local-map YaTeX-mode-map)
696 (set-syntax-table YaTeX-mode-syntax-table)
697 (if YaTeX-dos (setq YaTeX-saved-screen-height (YaTeX-screen-height)))
698 (YaTeX-read-user-completion-table)
699 (and (fboundp 'YaTeX-hilit-setup-alist) (YaTeX-hilit-setup-alist))
700 (makunbound 'inenv)
701 (turn-on-auto-fill) ;1.63
702 (and (= 0 (buffer-size)) (file-exists-p YaTeX-template-file)
703 (y-or-n-p (format "Insert %s?" YaTeX-template-file))
704 (insert-file-contents (expand-file-name YaTeX-template-file)))
705 (run-hooks 'text-mode-hook 'yatex-mode-hook))
707 ;---------- Define YaTeX-mode functions ----------
708 (defvar YaTeX-ec "\\" "Escape character of current mark-up language.")
709 (defvar YaTeX-ec-regexp (regexp-quote YaTeX-ec))
710 (defvar YaTeX-struct-begin
711 (concat YaTeX-ec "begin{%1}%2")
712 "Keyword format of begin-environment.")
713 (defvar YaTeX-struct-end
714 (concat YaTeX-ec "end{%1}")
715 "Keyword format of end-environment.")
716 (defvar YaTeX-struct-name-regexp "[^}]*"
717 "Environment name regexp.")
718 (defvar YaTeX-TeX-token-regexp
719 (cond (YaTeX-japan "[A-Za-z*ぁ-ん亜-龠]+")
720 (t "[A-Za-z*]+"))
721 "Regexp of characters which can be a member of TeX command's name.")
722 (defvar YaTeX-kanji-regexp "[ぁ-ん亜-龠]"
723 "Generic regexp of Japanese Kanji (and symbol) characters.")
724 (defvar YaTeX-command-token-regexp YaTeX-TeX-token-regexp
725 "Regexp of characters which can be a member of current mark up language's command name.")
727 ;;(defvar YaTeX-struct-section
728 ;; (concat YaTeX-ec "%1{%2}")
729 ;; "Keyword to make section.")
731 ;;;
732 ;; autoload section
733 ;;;
735 ;;autoload from yatexprc.el
736 (autoload 'YaTeX-visit-main "yatexprc" "Visit main LaTeX file." t)
737 (autoload 'YaTeX-visit-main-other-window "yatexprc"
738 "Visit main other window." t)
739 (autoload 'YaTeX-main-file-p "yatexprc" "Check if the file is main." t)
740 (autoload 'YaTeX-get-builtin "yatexprc" "Get %# built-in." t)
741 (autoload 'YaTeX-system "yatexprc" "Call system command" t)
742 (autoload 'YaTeX-save-buffers "yatexprc" "Save buffers of same major mode" t)
744 ;;autoload from yatexmth.el
745 (autoload 'YaTeX-math-insert-sequence "yatexmth" "Image input." t)
746 (autoload 'YaTeX-in-math-mode-p "yatexmth" "Check if in math-env." t)
747 (autoload 'YaTeX-toggle-math-mode "yatexmth" "YaTeX math-mode interfaces." t)
748 (autoload 'YaTeX-math-member-p "yatexmth" "Check if a word is math command." t)
749 (autoload 'YaTeX-insert-amsparens-region "yatexmth" "AMS parens region" t)
750 (autoload 'YaTeX-insert-amsbraces-region "yatexmth" "AMS braces region" t)
751 (autoload 'YaTeX-insert-amsbrackets-region "yatexmth" "AMS brackets region" t)
752 (autoload 'YaTeX-on-parenthesis-p "yatexmth" "Check if on math-parens" t)
753 (autoload 'YaTeX-goto-open-paren "yatexmth" "Goto opening paren" t)
754 (autoload 'YaTeX-change-parentheses "yatexmth" "Change corresponding parens" t)
755 (autoload 'YaTeX-goto-corresponding-paren "yatexmth" "\bigl\bigr jumps" t)
756 (autoload 'YaTeX-typeset-math-region "yatexmth" "Typeset math-region" t)
758 ;;autoload from yatexhlp.el
759 (autoload 'YaTeX-help "yatexhlp" "YaTeX helper with LaTeX commands." t)
760 (autoload 'YaTeX-apropos "yatexhlp" "Apropos for (La)TeX commands." t)
762 ;;autoload from yatexgen.el
763 (autoload 'YaTeX-generate "yatexgen" "YaTeX add-in function generator." t)
764 (autoload 'YaTeX-generate-simple "yatexgen" "YaTeX add-in support." t)
766 ;;autoload from yatexsec.el
767 (autoload 'YaTeX-section-overview "yatexsec" "YaTeX sectioning(view)" t)
768 (autoload 'YaTeX-read-section-in-minibuffer "yatexsec" "YaTeX sectioning" t)
769 (autoload 'YaTeX-make-section-with-overview "yatexsec" "YaTeX sectioning" t)
771 ;;autoload from yatexenv.el
772 (autoload 'YaTeX-what-column "yatexenv" "YaTeX env. specific funcs" t)
773 (autoload 'YaTeX-intelligent-newline "yatexenv" "YaTeX env. specific funcs" t)
774 (autoload 'YaTeX-indent-line-equation "yatexenv" "Indent equation lines." t)
775 (autoload 'YaTeX-goto-corresponding-leftright "yatexenv" "\left\right jumps" t)
777 ;;autoload from yatexhie.el
778 (autoload 'YaTeX-display-hierarchy "yatexhie"
779 "YaTeX document hierarchy browser" t)
780 (autoload 'YaTeX-display-hierarchy-directly "yatexhie"
781 "Same as YaTeX-display-hierarchy. Call from mouse." t)
783 ;;autoload from yatexpkg.el
784 (autoload 'YaTeX-package-auto-usepackage "yatexpkg" "Auto \\usepackage" t)
786 ;;;
787 ;; YaTeX-mode functions
788 ;;;
789 (defun YaTeX-insert-begin-end (env region-mode)
790 "Insert \\begin{mode-name} and \\end{mode-name}.
791 This works also for other defined begin/end tokens to define the structure."
792 (setq YaTeX-current-completion-type 'begin)
793 (let*((ccol (current-column)) beg beg2 exchange
794 (arg region-mode) ;for old compatibility
795 (indent-column (+ ccol YaTeX-environment-indent))(i 1) func)
796 (if (and region-mode (> (point) (mark)))
797 (progn (exchange-point-and-mark)
798 (setq exchange t
799 ccol (current-column)
800 indent-column (+ ccol YaTeX-environment-indent))))
801 ;;VER2 (insert "\\begin{" env "}" (YaTeX-addin env))
802 (setq beg (point))
803 (YaTeX-insert-struc 'begin env)
804 (setq beg2 (point))
805 (insert "\n")
806 (indent-to indent-column)
807 (save-excursion
808 ;;indent optional argument of \begin{env}, if any
809 (while (> (point-beginning-of-line) beg)
810 (skip-chars-forward "\\s " (point-end-of-line))
811 (indent-to indent-column)
812 (forward-line -1)))
813 (require 'yatexenv)
814 (if region-mode
815 ;;if region-mode, indent all text in the region
816 (save-excursion
817 (if (fboundp (intern-soft (concat "YaTeX-enclose-" env)))
818 (funcall (intern-soft (concat "YaTeX-enclose-" env))
819 (point) (mark))
820 (while (< (progn (forward-line 1) (point)) (mark))
821 (if (eolp) nil
822 (skip-chars-forward " \t\n")
823 (indent-to indent-column))))))
824 (if region-mode (exchange-point-and-mark))
825 (indent-to ccol)
826 ;;VER2 (insert "\\end{" env "}\n")
827 (YaTeX-insert-struc 'end env)
828 (YaTeX-reindent ccol)
829 (if region-mode
830 (progn
831 (insert "\n")
832 (or exchange (exchange-point-and-mark)))
833 (goto-char beg2)
834 (YaTeX-intelligent-newline nil)
835 (if (fboundp (intern-soft (concat "YaTeX-intelligent-newline-" env)))
836 (progn
837 (message
838 (cond
839 (YaTeX-japan "%s で次の行の入力に進みます。")
840 (t "`%s' produces the next line's template."))
841 (key-description
842 (car (where-is-internal 'YaTeX-intelligent-newline))))))
843 (YaTeX-indent-line))
844 (YaTeX-package-auto-usepackage env 'env)
845 (if YaTeX-current-position-register
846 (point-to-register YaTeX-current-position-register))))
848 (defun YaTeX-make-begin-end (arg)
849 "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
850 by completing read.
851 If you invoke this command with universal argument,
852 \(key binding for universal-argument is \\[universal-argument]\)
853 you can put REGION into that environment between \\begin and \\end."
854 (interactive "P")
855 (let*
856 ((mode (if arg " region" ""))
857 (env
858 (YaTeX-read-environment
859 (format "Begin environment%s(default %s): " mode YaTeX-env-name))))
860 (if (string= env "")
861 (setq env YaTeX-env-name))
862 (setq YaTeX-env-name env)
863 (YaTeX-update-table
864 (list YaTeX-env-name) 'env-table 'user-env-table 'tmp-env-table)
865 (YaTeX-insert-begin-end YaTeX-env-name arg)))
867 (defun YaTeX-make-begin-end-region ()
868 "Call YaTeX-make-begin-end with ARG to specify region mode."
869 (interactive)
870 (YaTeX-make-begin-end t))
872 (defun YaTeX-guess-section-type ()
873 (if (eq major-mode 'yatex-mode)
874 (save-excursion
875 (cond
876 ((save-excursion (not (search-backward YaTeX-ec nil t)))
877 (if YaTeX-use-LaTeX2e "documentclass" "documentstyle"))
878 ((progn
879 (if (= (char-after (1- (point))) ?~) (forward-char -1))
880 (forward-char -1) (looking-at "表\\|図\\|式\\|第"))
881 "ref")
882 ((and (looking-at "[a-z \t]")
883 (progn (skip-chars-backward "a-z \t")
884 (looking-at "table\\|figure\\|formula")))
885 "ref")
886 ((save-excursion
887 (skip-chars-backward "[^ア-ン]")
888 (looking-at "プログラム\\|リスト"))
889 "ref")
890 ((YaTeX-re-search-active-backward
891 (concat YaTeX-ec-regexp "begin{\\([^}]+\\)}")
892 (regexp-quote YaTeX-comment-prefix)
893 (save-excursion (forward-line -1) (point))
894 t)
895 (let ((env (YaTeX-match-string 1)))
896 (cdr (assoc env
897 '(("table" . "caption"))))))
898 ))))
900 (defun YaTeX-make-section (arg &optional beg end cmd)
901 "Make LaTeX \\section{} type command with completing read.
902 With numeric ARG, you can specify the number of arguments of
903 LaTeX command.
904 For example, if you want to produce LaTeX command
906 \\addtolength{\\topmargin}{8mm}
908 which has two arguments. You can produce that sequence by typing...
909 ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
910 \(by default\)
911 Then yatex will automatically complete `addtolength' with two arguments
912 next time.
913 You can complete symbol at LaTeX command and the 1st argument.
915 If the optional 2nd and 3rd argument BEG END are specified, enclose
916 the region from BEG to END into the first argument of the LaTeX sequence.
917 Optional 4th arg CMD is LaTeX command name, for non-interactive use."
918 (interactive "P")
919 (setq YaTeX-current-completion-type 'section)
920 (if (equal arg '(4)) (setq beg (region-beginning) end (region-end)))
921 (unwind-protect
922 (let*
923 ((source-window (selected-window))
924 guess
925 (section
926 (or cmd
927 (progn
928 (setq guess
929 (or (YaTeX-guess-section-type) YaTeX-section-name))
930 (YaTeX-read-section
931 (if YaTeX-simple-messages
932 (format "Section-type (default %s): " guess)
933 (if (> (minibuffer-depth) 0)
934 (format "%s???{} (default %s)%s: "
935 YaTeX-ec guess
936 (format "[level:%d]" (minibuffer-depth)))
937 (format "(C-v for view-section) %s???{%s} (default %s): "
938 YaTeX-ec (if beg "region" "") guess)))
939 nil))))
940 (section (if (string= section "") guess section))
941 (numarg ;; The number of section-type command's argument
942 (or (and (numberp arg) arg)
943 (nth 1 (YaTeX-lookup-table section 'section))
944 1))
945 (arg-reader (intern-soft (concat "YaTeX::" section)))
946 (addin-args (and arg-reader (fboundp arg-reader)))
947 (title "")
948 (j 1)
949 (after-change-functions nil) ;inhibit font-locking temporarily
950 (enable-recursive-minibuffers t)
951 (mkarg-func
952 (function
953 (lambda (n)
954 (while (<= j n)
955 (unwind-protect
956 (setq title
957 (cond
958 (addin-args (funcall arg-reader j))
959 (YaTeX-skip-default-reader "")
960 (t
961 (read-string
962 (format "Argument %d of %s: " j section)))))
963 (insert
964 (concat ;to allow nil return value
965 "{" title "}")))
966 (setq j (1+ j))))))
967 );;let
968 (setq YaTeX-section-name section)
969 (if beg
970 (let*((e (make-marker))
971 (ar2 (intern-soft (concat "YaTeX::" section "-region")))
972 (arp (and ar2 (fboundp ar2))))
973 (goto-char end)
974 (insert "}")
975 (set-marker e (point))
976 (goto-char beg)
977 (unwind-protect
978 (progn
979 (insert YaTeX-ec YaTeX-section-name
980 (YaTeX-addin YaTeX-section-name))
981 (if (> numarg 1) (funcall mkarg-func (1- numarg))))
982 (insert "{"))
983 (if arp (funcall ar2 (point) e))
984 (goto-char e)
985 (set-marker e nil))
986 (use-global-map YaTeX-recursive-map)
987 (if (= numarg 0) (YaTeX-make-singlecmd YaTeX-section-name)
988 (progn (insert YaTeX-ec YaTeX-section-name)
989 (insert (YaTeX-addin YaTeX-section-name))))
990 ;;read arguments with add-in
991 (funcall mkarg-func numarg))
992 (YaTeX-update-table
993 (if (/= numarg 1) (list section numarg)
994 (list section))
995 'section-table 'user-section-table 'tmp-section-table)
996 (if YaTeX-current-position-register
997 (point-to-register YaTeX-current-position-register))
998 (if (string= (YaTeX-buffer-substring (- (point) 2) (point))
999 "{}")
1000 (forward-char -1))
1001 (while (string= (YaTeX-buffer-substring (- (point) 3) (1- (point)))
1002 "{}")
1003 (forward-char -2))
1004 (YaTeX-package-auto-usepackage section 'section))
1005 (if (<= (minibuffer-depth) 0) (use-global-map global-map))
1006 (insert ""))) ;insert dummy string to fontify(Emacs20)
1008 (defun YaTeX-make-section-region (args beg end)
1009 "Call YaTeX-make-section with arguments to specify region mode."
1010 (interactive "P\nr")
1011 (YaTeX-make-section args beg end))
1013 (defun YaTeX-make-fontsize (arg &optional fontsize)
1014 "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
1015 If you invoke this command with universal argument, you can put region
1016 into {\\xxx } braces.
1017 \(key binding for universal-argument is \\[universal-argument]\)"
1018 (interactive "P")
1019 (YaTeX-sync-local-table 'tmp-fontsize-table)
1020 (let* ((mode (if arg "region" ""))
1021 (fontsize
1022 (or fontsize
1023 (YaTeX-read-fontsize
1024 (if YaTeX-simple-messages
1025 (format "Font or size (default %s): " YaTeX-fontsize-name)
1026 (format "{\\??? %s} (default %s)%s: " mode YaTeX-fontsize-name
1027 (if (> (minibuffer-depth) 0)
1028 (format "[level:%d]" (minibuffer-depth)) "")))
1029 nil nil))))
1030 (if (string= fontsize "")
1031 (setq fontsize YaTeX-fontsize-name))
1032 (setq YaTeX-current-completion-type 'large)
1033 (setq YaTeX-fontsize-name fontsize)
1034 (YaTeX-update-table
1035 (list YaTeX-fontsize-name)
1036 'fontsize-table 'user-fontsize-table 'tmp-fontsize-table)
1037 (and YaTeX-use-LaTeX2e
1038 (YaTeX-latex2e-p)
1039 (setq fontsize
1040 (cdr (assoc YaTeX-fontsize-name LaTeX2e-fontstyle-alist)))
1041 (setq YaTeX-fontsize-name fontsize))
1042 (if arg
1043 (save-excursion
1044 (if (> (point) (mark)) (exchange-point-and-mark))
1045 (insert "{\\" YaTeX-fontsize-name " ")
1046 (exchange-point-and-mark)
1047 (insert "}"))
1048 (insert (concat "{\\" YaTeX-fontsize-name " }"))
1049 (forward-char -1)
1050 (if YaTeX-current-position-register
1051 (point-to-register YaTeX-current-position-register))
1052 (save-excursion
1053 (insert (YaTeX-addin YaTeX-fontsize-name)))
1054 (YaTeX-package-auto-usepackage YaTeX-fontsize-name 'large))))
1056 (defun YaTeX-make-fontsize-region ()
1057 "Call function:YaTeX-make-fontsize with ARG to specify region mode."
1058 (interactive)
1059 (YaTeX-make-fontsize t))
1061 (defvar YaTeX-singlecmd-suffix "" "*Suffix for maketitle-type commands.")
1062 (defvar YaTeX-read-singlecmd-history nil "Holds maketitle-type history.")
1063 (put 'YaTeX-read-singlecmd-history 'no-default t)
1064 (defun YaTeX-make-singlecmd (single)
1065 (interactive
1066 (list (YaTeX-cplread-with-learning
1067 (if YaTeX-simple-messages
1068 (format "maketitle-type (default %s): " YaTeX-single-command)
1069 (format "%s??? (default %s)%s: " YaTeX-ec YaTeX-single-command
1070 (if (> (minibuffer-depth) 0)
1071 (format "[level:%d]" (minibuffer-depth)) "")))
1072 'singlecmd-table 'user-singlecmd-table 'tmp-singlecmd-table
1073 nil nil nil 'YaTeX-read-singlecmd-history)))
1074 (if (string= single "")
1075 (setq single YaTeX-single-command))
1076 (setq YaTeX-single-command single)
1077 (setq YaTeX-current-completion-type 'maketitle)
1078 (let ((dollar (and (not (YaTeX-in-math-mode-p))
1079 (YaTeX-math-member-p YaTeX-single-command)))
1080 p q)
1081 (if dollar (insert "$"))
1082 (insert YaTeX-ec YaTeX-single-command)
1083 (setq p (point))
1084 (insert (YaTeX-addin single) YaTeX-singlecmd-suffix)
1085 (if dollar (insert "$"))
1086 (setq q (point))
1087 (goto-char p)
1088 (forward-char -2)
1089 (if (looking-at "\\[\\]") (forward-char 1) (goto-char q)))
1090 (YaTeX-package-auto-usepackage YaTeX-single-command 'maketitle)
1091 (if YaTeX-current-position-register
1092 (point-to-register YaTeX-current-position-register)))
1094 (defvar YaTeX-completion-begin-regexp "[{\\]"
1095 "Regular expression of limit where LaTeX command's completion begins.")
1097 (defun YaTeX-do-completion ()
1098 "Try completion on LaTeX command preceding point."
1099 (interactive)
1100 (if
1101 (or (eq (preceding-char) ? )
1102 (eq (preceding-char) ?\t)
1103 (eq (preceding-char) ?\n)
1104 (bobp))
1105 (message "Nothing to complete.") ;Do not complete
1106 (let* ((end (point))
1107 (limit (point-beginning-of-line))
1108 (completion-begin
1109 (progn (re-search-backward "[ \t\n]" limit 1) (point)))
1110 (begin (progn
1111 (goto-char end)
1112 (if (re-search-backward YaTeX-completion-begin-regexp
1113 completion-begin t)
1114 (1+ (point))
1115 nil))))
1116 (goto-char end)
1117 (cond
1118 ((null begin)
1119 (message "I think it is not a LaTeX sequence."))
1120 (t
1121 (mapcar 'YaTeX-sync-local-table
1122 '(tmp-section-table tmp-env-table tmp-singlecmd-table))
1123 (let*((pattern (YaTeX-buffer-substring begin end))
1124 (all-table
1125 (append
1126 section-table user-section-table tmp-section-table
1127 env-table user-env-table tmp-env-table
1128 singlecmd-table user-singlecmd-table tmp-singlecmd-table))
1129 ;; First,
1130 ;; search completion without backslash.
1131 (completion (try-completion pattern all-table)))
1132 (if
1133 (eq completion nil)
1134 ;; Next,
1135 ;; search completion with backslash
1136 (setq completion
1137 (try-completion
1138 (YaTeX-buffer-substring (1- begin) end)
1139 all-table nil)
1140 begin (1- begin)))
1141 (cond
1142 ((null completion)
1143 (message (concat "Can't find completion for '" pattern "'"))
1144 (ding))
1145 ((eq completion t) (message "Sole completion."))
1146 ((not (string= completion pattern))
1147 (delete-region begin end)
1148 (insert completion)
1150 (t
1151 (message "Making completion list...")
1152 (with-output-to-temp-buffer "*Help*"
1153 (display-completion-list
1154 (all-completions pattern all-table)))))))))))
1156 (defun YaTeX-toggle-modify-mode (&optional arg)
1157 (interactive "P")
1158 (or (memq 'YaTeX-modify-mode mode-line-format)
1159 (setq mode-line-format
1160 (append (list "" 'YaTeX-modify-mode) mode-line-format)))
1161 (if (or arg (null YaTeX-modify-mode))
1162 (progn
1163 (setq YaTeX-modify-mode "*m*")
1164 (message "Modify mode"))
1165 (setq YaTeX-modify-mode nil)
1166 (message "Cancel modify mode."))
1167 (set-buffer-modified-p (buffer-modified-p))) ;redraw mode-line
1169 (defun YaTeX-switch-mode-menu (arg &optional char)
1170 (interactive "P")
1171 (message "Toggle: (M)odify-mode ma(T)h-mode")
1172 (let ((c (or char (read-char))))
1173 (cond
1174 ((= c ?m) (YaTeX-toggle-modify-mode arg))
1175 ((or (= c ?$) (= c ?t))
1176 (if YaTeX-auto-math-mode
1177 (message "Makes no sense in YaTeX-auto-math-mode.")
1178 (YaTeX-toggle-math-mode arg))))))
1180 (defun YaTeX-insert-quote ()
1181 (interactive)
1182 (insert
1183 (cond
1184 ((YaTeX-literal-p) ?\")
1185 ((= (preceding-char) ?\\ ) ?\")
1186 ;((= (preceding-char) ?\( ) ?\")
1187 ((or (= (preceding-char) 32)
1188 (= (preceding-char) 9)
1189 (= (preceding-char) ?\n)
1190 (bobp)
1191 (string-match
1192 (regexp-quote (char-to-string (preceding-char)))
1193 "、。,.?!「」『』【】()"))
1194 "``")
1195 (t "''"))))
1197 (defun YaTeX-closable-p ()
1198 (and (not YaTeX-modify-mode)
1199 (not (eq YaTeX-close-paren-always 'never))
1200 (or YaTeX-close-paren-always (eolp))
1201 (not (input-pending-p))
1202 (not (YaTeX-literal-p)))
1203 ;;(or YaTeX-modify-mode
1204 ;; (and (not YaTeX-close-paren-always) (not (eolp)))
1205 ;; (input-pending-p)
1206 ;; (YaTeX-quick-in-environment-p "verbatim"))
1209 (defun YaTeX-insert-braces-region (beg end &optional open close)
1210 (interactive "r")
1211 (save-excursion
1212 (goto-char end)
1213 (YaTeX-insert-inherit (or close "}"))
1214 (goto-char beg)
1215 (YaTeX-insert-inherit (or open "{"))))
1217 (defun YaTeX-get-macro-at-point (&optional p)
1218 "Get (La)TeX macro around point P."
1219 (interactive "d")
1220 (save-excursion
1221 (goto-char (setq p (or p (point))))
1222 (let ((token (substring (substring YaTeX-TeX-token-regexp 1) 0 -2))
1223 bsend)
1224 (and (not (bobp))
1225 (or (looking-at YaTeX-TeX-token-regexp)
1226 (string-match
1227 YaTeX-TeX-token-regexp (char-to-string (preceding-char))))
1228 (progn
1229 (skip-chars-backward token)
1230 (equal (preceding-char) ?\\))
1231 (save-excursion
1232 (setq bsend (point))
1233 (skip-chars-backward "\\\\") ;emacs18 doesn't return distance
1234 (/= (% (- bsend (point)) 2) 0)) ;consider \\
1235 (looking-at YaTeX-TeX-token-regexp)
1236 (YaTeX-match-string 0)))))
1238 (defun YaTeX-insert-braces (arg &optional open close)
1239 (interactive "p")
1240 (let ((begend-guide
1241 (function
1242 (lambda ()
1243 (if (equal (get 'YaTeX-insert-braces 'begend-guide) 2)
1244 nil ;if triggered thrice, do nothing
1245 (momentary-string-display
1246 (format
1247 (cond
1248 (YaTeX-japan "begin/end入力には %s を使いましょう")
1249 (t "You don't understand Zen of `%s'!"))
1250 (key-description
1251 (car (where-is-internal 'YaTeX-make-begin-end))))
1252 (point))
1253 (put 'YaTeX-insert-braces 'begend-guide
1254 (+ 1 (string-to-int ;increment counter of beg-end guidance
1255 (prin1-to-string
1256 (get 'YaTeX-insert-braces 'begend-guide)))))))))
1257 env macro not-literal b e)
1258 (cond
1259 ((YaTeX-jmode) (YaTeX-self-insert arg))
1260 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1261 ((save-excursion
1262 (and (> (- (point) (point-min)) 6)
1263 (condition-case () (forward-char -6) (error nil)))
1264 (looking-at "\\\\left\\\\"))
1265 (insert "{\\right\\}")
1266 (forward-char -8))
1267 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
1268 (and (> (- (point) (point-min)) 6) (forward-char -6))
1269 (looking-at "\\\\[bB]igl\\\\"))
1270 (insert
1271 (concat
1272 "{" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\}"))
1273 (forward-char -7))
1274 ((save-excursion
1275 (and (> (- (point) (point-min)) 7)
1276 (condition-case () (forward-char -7) (error nil)))
1277 (looking-at "\\\\[bB]iggl\\\\"))
1278 (insert
1279 (concat
1280 "{" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\}"))
1281 (forward-char -8))
1282 ((= (preceding-char) ?\\ )
1283 (insert "{\\}")
1284 (forward-char -2)) ;matsu's hack ends here
1285 ((and (setq not-literal (not (YaTeX-literal-p)))
1286 (equal "end" (setq macro (YaTeX-get-macro-at-point)))
1287 (setq env (YaTeX-inner-environment)))
1288 (funcall begend-guide)
1289 (insert "{" env "}"))
1290 ((and not-literal (equal "begin" macro))
1291 (insert "{")
1292 (save-excursion
1293 (indent-to (prog1 (- (current-column) 7) (insert "}\n")))
1294 (insert "\\end{}")
1295 (setq e (point)))
1296 (setq env
1297 (YaTeX-read-environment
1298 (format "Begin environment(default %s): " YaTeX-env-name)))
1299 (if (string= "" env) (setq env YaTeX-env-name))
1300 (setq YaTeX-env-name env)
1301 (funcall begend-guide)
1302 (delete-region (- (point) 7) e)
1303 (YaTeX-insert-begin-end env nil))
1304 (t
1305 (insert (or open "{") (or close "}"))
1306 (forward-char -1)
1307 (if (and (eq (char-after (point)) ?\}) ;; the case `\\{}'
1308 (eq (char-after (- (point) 2)) ?\\ ))
1309 (progn (insert "\\") (forward-char -1)))
1310 ))))
1312 (defun YaTeX-jmode ()
1313 (or (and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
1314 (and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
1315 (and (boundp 'skk-mode) skk-mode (not skk-latin-mode))
1316 (and (boundp 'default-input-method) default-input-method
1317 current-input-method)))
1319 (defun YaTeX-jmode-off ()
1320 (if (cond
1321 ((and (boundp 'canna:*japanese-mode*) canna:*japanese-mode*)
1322 (canna-toggle-japanese-mode) t)
1323 ((and (boundp 'egg:*mode-on*) egg:*mode-on* egg:*input-mode*)
1324 (egg:toggle-egg-mode-on-off) t)
1325 ((and (fboundp 'skk-mode) (boundp 'skk-mode) skk-mode)
1326 (cond
1327 ((fboundp 'skk-latin-mode)
1328 (or (and (boundp 'skk-henkan-mode) skk-henkan-mode)
1329 (and (boundp 'skk-henkan-on)
1330 (or skk-henkan-mode skk-henkan-active))
1331 (and (boundp 'j-henkan-on)
1332 (or j-henkan-on j-henkan-active))
1333 ;; Deactivate jmode if henkan-mode is not running.
1334 ;; Suggested by tt.tetsuo.tsukamoto.
1335 (progn
1336 (put 'YaTeX-jmode-on 'skkkata skk-katakana)
1337 (skk-latin-mode t))))
1338 ((fboundp 'skk-mode-off) (skk-mode-off))
1339 (t (j-mode-off)))
1340 t)
1341 ((and (fboundp 'toggle-input-method) current-input-method)
1342 (toggle-input-method) t)
1343 ((and (fboundp 'fep-force-off) (fep-force-off))))
1344 (put 'YaTeX-jmode 'jmode t)))
1346 (defun YaTeX-jmode-on ()
1347 (cond
1348 ((boundp 'canna:*japanese-mode*)
1349 (if (not canna:*japanese-mode*) (canna-toggle-japanese-mode)))
1350 ((boundp 'egg:*mode-on*)
1351 (and (not egg:*mode-on*) (not egg:*input-mode*)
1352 (egg:toggle-egg-mode-on-off)))
1353 ((and (fboundp 'skk-mode) (boundp 'skk-mode))
1354 (if (get 'YaTeX-jmode-on 'skkkata)
1355 (skk-j-mode-on t)
1356 (skk-mode 1))
1357 (put 'YaTeX-jmode-on 'skkkata nil))
1358 ((fboundp 'toggle-input-method)
1359 (if (not current-input-method) (toggle-input-method)))
1360 ((and (fboundp 'fep-force-on) (fep-force-on)))))
1362 (defun YaTeX-jmode-back ()
1363 (if (get 'YaTeX-jmode 'jmode)
1364 (YaTeX-jmode-on))
1365 (setplist 'YaTeX-jmode nil))
1367 (defun YaTeX-self-insert (arg)
1368 (call-interactively (global-key-binding (char-to-string (YaTeX-last-key)))))
1369 (defun YaTeX-insert-inherit (&rest args)
1370 (apply (if (fboundp 'insert-and-inherit) 'insert-and-inherit 'insert)
1371 args))
1373 (defun YaTeX-insert-brackets (arg)
1374 "Insert Kagi-kakko or \\ [ \\] pair or simply \[."
1375 (interactive "p")
1376 (let ((col (1- (current-column))))
1377 (cond
1378 ((YaTeX-jmode) (YaTeX-self-insert arg))
1379 ((not (YaTeX-closable-p))
1380 (YaTeX-self-insert arg))
1381 ((save-excursion
1382 (and (> (- (point) (point-min)) 5) (forward-char -5))
1383 (looking-at "\\\\left"))
1384 (YaTeX-insert-inherit "[\\right]")
1385 (forward-char -7))
1386 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
1387 (and (> (- (point) (point-min)) 5) (forward-char -5))
1388 (looking-at "\\\\[bB]igl"))
1389 (YaTeX-insert-inherit
1390 (concat
1391 "[" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r]"))
1392 (forward-char -6))
1393 ((save-excursion
1394 (and (> (- (point) (point-min)) 6) (forward-char -6))
1395 (looking-at "\\\\[bB]iggl"))
1396 (YaTeX-insert-inherit
1397 (concat
1398 "[" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r]"))
1399 (forward-char -7)) ;matsu's hack ends here
1400 ((and (= (preceding-char) ?\\ )
1401 (/= (char-after (- (point) 2)) ?\\ )
1402 (not (YaTeX-in-math-mode-p)))
1403 (YaTeX-insert-inherit (YaTeX-last-key) "\n")
1404 (indent-to (max 0 col))
1405 (YaTeX-insert-inherit "\\]")
1406 (beginning-of-line)
1407 (open-line 1)
1408 (delete-region (point) (progn (beginning-of-line) (point)))
1409 (indent-to (+ YaTeX-environment-indent (max 0 col)))
1410 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1)))
1411 ((YaTeX-closable-p)
1412 (YaTeX-insert-inherit "[]")
1413 (backward-char 1))
1414 (t (YaTeX-self-insert arg)))))
1416 (defun YaTeX-insert-brackets-region (beg end)
1417 (interactive "r")
1418 (YaTeX-insert-braces-region beg end "[" "]"))
1420 (defun YaTeX-insert-parens (arg)
1421 "Insert parenthesis pair."
1422 (interactive "p")
1423 (cond
1424 ((YaTeX-jmode) (YaTeX-self-insert arg))
1425 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1426 ((save-excursion
1427 (and (> (- (point) (point-min)) 5) (forward-char -5))
1428 (looking-at "\\\\left"))
1429 (YaTeX-insert-inherit "(\\right)")
1430 (forward-char -7))
1431 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
1432 (and (> (- (point) (point-min)) 5) (forward-char -5))
1433 (looking-at "\\\\[bB]igl"))
1434 (YaTeX-insert-inherit
1435 (concat
1436 "(" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r)"))
1437 (forward-char -6))
1438 ((save-excursion
1439 (and (> (- (point) (point-min)) 6) (forward-char -6))
1440 (looking-at "\\\\[bB]iggl"))
1441 (YaTeX-insert-inherit
1442 (concat
1443 "(" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r)"))
1444 (forward-char -7))
1445 ((= (preceding-char) ?\\ ) ;matsu's hack ends here
1446 (YaTeX-insert-inherit "(\\)")
1447 (backward-char 2))
1448 ((YaTeX-closable-p)
1449 (YaTeX-insert-inherit "()")
1450 (backward-char 1))
1451 (t (YaTeX-self-insert arg))))
1453 (defun YaTeX-insert-parens-region (beg end)
1454 (interactive "r")
1455 (YaTeX-insert-braces-region beg end "(" ")"))
1457 (defun YaTeX-insert-bar (arg)
1458 "Insert bar pair."
1459 (interactive "p")
1460 (cond
1461 ((YaTeX-jmode) (YaTeX-self-insert arg))
1462 ((not (YaTeX-closable-p)) (YaTeX-self-insert arg))
1463 ((save-excursion
1464 (and (> (- (point) (point-min)) 5) (forward-char -5))
1465 (looking-at "\\\\left"))
1466 (YaTeX-insert-inherit "|\\right|")
1467 (forward-char -7))
1468 ((save-excursion ;from matsu<at>math.s.chiba-u.ac.jp
1469 (and (> (- (point) (point-min)) 5) (forward-char -5))
1470 (looking-at "\\\\[bB]igl"))
1471 (insert
1472 (concat
1473 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r|"))
1474 (forward-char -6))
1475 ((save-excursion
1476 (and (> (- (point) (point-min)) 6) (forward-char -6))
1477 (looking-at "\\\\[bB]iggl"))
1478 (insert
1479 (concat
1480 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 1)) "r|"))
1481 (forward-char -7))
1482 ((save-excursion ; added by Jin <MAF01011<at>nifty.ne.jp>
1483 (and (> (- (point) (point-min)) 6) (forward-char -6))
1484 (looking-at "\\\\left\\\\"))
1485 (YaTeX-insert-inherit "|\\right\\|")
1486 (forward-char -8))
1487 ((save-excursion
1488 (and (> (- (point) (point-min)) 6) (forward-char -6))
1489 (looking-at "\\\\[bB]igl\\\\"))
1490 (insert
1491 (concat
1492 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\|"))
1493 (forward-char -7))
1494 ((save-excursion
1495 (and (> (- (point) (point-min)) 7) (forward-char -7))
1496 (looking-at "\\\\[bB]iggl\\\\"))
1497 (insert
1498 (concat
1499 "|" (buffer-substring (match-beginning 0) (- (match-end 0) 2)) "r\\|"))
1500 (forward-char -8)) ; added by Jin up to here.
1501 ((= (preceding-char) ?\\ )
1502 (YaTeX-insert-inherit "|\\|")
1503 (backward-char 2))
1504 ; ((and (YaTeX-closable-p)
1505 ; (/= (preceding-char) ?|)
1506 ; (/= (following-char) ?|))
1507 ; (YaTeX-insert-inherit "||")
1508 ; (backward-char 1))
1509 (t (YaTeX-self-insert arg))))
1511 (defvar YaTeX-use-jmode-hook
1512 (and (featurep 'canna) (boundp 'canna:*initialized*) canna:*initialized*)
1513 ;; (not (and (fboundp 'skk-mode) (boundp 'skk-mode)))
1514 "*Non-nil means activate automatic jmode switcher within/out math mode.
1515 Hopefully, change default to t in the next version of 1.75.")
1516 (defun YaTeX-jmode-hook (old new)
1517 "A hook controling jmode on/off."
1518 ;; This function is called via point-entered/leave hook, so that
1519 ;; codes in it is evaluated on such emacsen as having text-properties.
1520 (let ((inhibit-point-motion-hooks t)
1521 (oldp (plist-get (text-properties-at old) 'point-left))
1522 (newp (plist-get (text-properties-at new) 'point-left))
1523 (lnew (plist-get (text-properties-at new) 'last-new))
1524 (mjmode (plist-get (text-properties-at new) 'mjmode))
1525 (bmp (buffer-modified-p))
1526 (jm (YaTeX-jmode)) b e)
1527 (unwind-protect
1528 (cond
1529 ((eq lnew new) nil) ;Do nothing if continuous entry
1530 ((and (not (eq newp 'YaTeX-jmode-hook))
1531 (eq oldp 'YaTeX-jmode-hook)
1532 (plist-get (text-properties-at old) 'entered))
1533 ;; leave
1534 (remove-text-properties
1535 (setq b (1+ (or (previous-single-property-change old 'point-left)
1536 (1- (point)))))
1537 (setq e (1- (or (next-single-property-change old 'point-left)
1538 (1+ (point)))))
1539 (list 'last-new nil 'entered nil))
1540 (add-text-properties b e (list 'mjmode jm))
1541 (if (boundp 'skk-katakana)
1542 (put 'YaTeX-jmode-on 'skkkata skk-katakana))
1543 (if (plist-get (text-properties-at old) 'jmode)
1544 (YaTeX-jmode-on)))
1545 ((and (not (eq oldp 'YaTeX-jmode-hook))
1546 (eq newp 'YaTeX-jmode-hook)
1547 (not (plist-get (text-properties-at new) 'entered)))
1548 ;; enter
1549 (add-text-properties
1550 (1+ (or (previous-single-property-change new 'point-left)
1551 (1- (point))))
1552 (1- (or (next-single-property-change new 'point-left)
1553 (1+ (point))))
1554 (list 'jmode jm 'last-new new 'entered t))
1555 (if (boundp 'skk-katakana) ;care for skk katakana mode
1556 (put 'YaTeX-jmode-on 'skkkata skk-katakana))
1557 (if mjmode (YaTeX-jmode-on) (YaTeX-jmode-off))))
1558 ;;unwind job
1559 (set-buffer-modified-p bmp))))
1561 (defun YaTeX-insert-dollar ()
1562 (interactive)
1563 (if (or (not (YaTeX-closable-p))
1564 (= (preceding-char) 92)
1565 (and (YaTeX-in-math-mode-p)
1566 (or (/= (preceding-char) ?$) (/= (following-char) ?$))))
1567 (insert "$")
1568 (insert "$$")
1569 (forward-char -1)
1570 (and YaTeX-use-jmode-hook
1571 (fboundp 'add-text-properties)
1572 (add-text-properties
1573 (1- (point)) (1+ (point))
1574 (list 'point-left 'YaTeX-jmode-hook
1575 'point-entered 'YaTeX-jmode-hook
1576 'front-sticky t
1577 'rear-nonsticky t
1578 'mjmode nil
1579 'jmode (YaTeX-jmode))))
1580 (YaTeX-jmode-off)
1581 (or YaTeX-auto-math-mode YaTeX-math-mode (YaTeX-toggle-math-mode 1))))
1583 (defun YaTeX-insert-dollars-region (beg end)
1584 (interactive "r")
1585 (YaTeX-insert-braces-region beg end "$" "$"))
1587 (defun YaTeX-insert-amper ()
1588 (interactive)
1589 (if (or (string-match YaTeX-array-env-regexp
1590 (or (YaTeX-inner-environment t) "document"))
1591 (= (preceding-char) 92)
1592 (YaTeX-literal-p)
1593 (YaTeX-in-math-mode-p))
1594 (insert "&")
1595 (insert "\\&")))
1597 (defun YaTeX-version ()
1598 "Return string of the version of running YaTeX."
1599 (interactive)
1600 (message
1601 (concat "Yet Another tex-mode "
1602 (if YaTeX-japan "「野鳥」" "`Wild Bird'")
1603 " Revision "
1604 YaTeX-revision-number)))
1606 (defun YaTeX-typeset-menu (arg &optional char)
1607 "Typeset, preview, visit error and miscellaneous convenient menu.
1608 Optional second argument CHAR is for non-interactive call from menu."
1609 (interactive "P")
1610 (message
1611 (concat "J)latex R)egion E)nv B)ibtex mk(I)dx "
1612 "latex+p(D)f "
1613 (if (fboundp 'start-process) "K)ill ")
1614 "P)review "
1615 (and (boundp 'window-system) window-system "S)earch ")
1616 "V)iewErr L)pr"))
1617 (let ((sw (selected-window)) (c (or char (read-char))))
1618 (require 'yatexprc) ;for Nemacs's bug
1619 (select-window sw)
1620 (cond
1621 ((= c ?j) (YaTeX-typeset-buffer))
1622 ((= c ?r) (YaTeX-typeset-region))
1623 ((= c ?e) (YaTeX-typeset-environment))
1624 ((= c ?b) (YaTeX-call-builtin-on-file
1625 "BIBTEX" bibtex-command arg))
1626 ((= c ?i) (YaTeX-call-builtin-on-file
1627 "MAKEINDEX" makeindex-command arg))
1628 ((= c ?k) (YaTeX-kill-typeset-process YaTeX-typeset-process))
1629 ((= c ?p) (call-interactively 'YaTeX-preview))
1630 ((= c ?q) (YaTeX-system "lpq" "*Printer queue*"))
1631 ((= c ?d) (YaTeX-typeset-buffer
1632 (or (YaTeX-get-builtin "DVIPDF") YaTeX-dvipdf-command)))
1633 ((= c ?v) (YaTeX-view-error))
1634 ((= c ?l) (YaTeX-lpr arg))
1635 ((= c ?m) (YaTeX-switch-mode-menu arg))
1636 ((= c ?b) (YaTeX-insert-string "\\"))
1637 ((= c ?s) (YaTeX-xdvi-remote-search arg)))))
1639 (if (fboundp 'wrap-function-to-control-ime)
1640 (wrap-function-to-control-ime 'YaTeX-typeset-menu t "P"))
1643 (defun YaTeX-%-menu (&optional beg end char)
1644 "Operate %# notation."
1645 ;;Do not use interactive"r" for the functions which require no mark
1646 (interactive)
1647 (message "!)Edit-%%#! B)EGIN-END-region P)review L)Edit-%%#LPR make(I)ndex B)ibtex")
1648 (let ((c (or char (read-char))) (string "") key
1649 (b (make-marker)) (e (make-marker)))
1650 (save-excursion
1651 (cond
1652 ((rindex "!plib" c) ;Edit %#xxx
1653 (setq key (cdr (assq c '((?! . "!")
1654 (?p . "PREVIEW")
1655 (?l . "LPR")
1656 (?i . "MAKEINDEX")
1657 (?b . "BIBTEX")))))
1658 (YaTeX-getset-builtin key t))
1660 ((= c ?b) ;%#BEGIN %#END region
1661 (or end (setq beg (min (point) (mark)) end (max (point) (mark))))
1662 (set-marker b beg)
1663 (set-marker e end)
1664 (goto-char (point-min))
1665 (while (re-search-forward "^%#\\(BEGIN\\)\\|\\(END\\)$" nil t)
1666 (beginning-of-line)
1667 (delete-region (point) (progn (forward-line 1) (point))))
1668 (goto-char b)
1669 (open-line 1)
1670 (delete-region (point) (progn (beginning-of-line)(point)));for 19 :-<
1671 (insert "%#BEGIN")
1672 (goto-char e)
1673 (insert "%#END\n")
1674 (set-marker b nil)
1675 (set-marker e nil))
1676 ))))
1678 (defvar YaTeX-refcommand-def-regexp-default
1679 "label\\|bibitem")
1680 (defvar YaTeX-refcommand-def-regexp-private nil
1681 "*Regexp of defining label commands")
1682 (defvar YaTeX-refcommand-def-regexp
1683 (concat (if YaTeX-refcommand-def-regexp-private
1684 (concat YaTeX-refcommand-def-regexp-private "\\|"))
1685 YaTeX-refcommand-def-regexp-default))
1687 (defvar YaTeX-refcommand-ref-regexp-default
1688 "\\(page\\|eq\\|fig\\)?ref\\|cite")
1689 (defvar YaTeX-refcommand-ref-regexp-private nil
1690 "*Regexp of referring label commands")
1691 (defvar YaTeX-refcommand-ref-regexp
1692 (concat (if YaTeX-refcommand-ref-regexp-private
1693 (concat YaTeX-refcommand-ref-regexp-private "\\|"))
1694 YaTeX-refcommand-ref-regexp-default))
1696 (defvar YaTeX-refcommand-regexp
1697 (concat YaTeX-refcommand-def-regexp
1698 "\\|" YaTeX-refcommand-ref-regexp)
1699 "Regexp of label defining/referring command name.")
1701 (defun YaTeX-goto-corresponding-label (reverse &optional otherwin)
1702 "Jump to corresponding \\label{} and \\ref{} or \\cite and \\bibitem.
1703 The default search direction depends on the command at the cursor position.
1704 When the cursor is on \\ref(\\cite), YaTeX will try to search the
1705 corresponding \\label(\\bibitem) backward,
1706 and if it fails search forward again. And when the cursor is
1707 on \\label(\\bibitem), YaTeX will search the corresponding \\ref(\\cite)
1708 forward at first and secondary backward.
1709 Argument REVERSE non-nil makes the default
1710 direction rule reverse. Since Search string is automatically set in
1711 search-last-string, you can repeat search the same label/ref by typing
1712 \\[isearch-forward] or \\[isearch-backward].
1713 If optional second argument OTHERWIN is non-nil, move to other window."
1715 (let ((scmd "") label direc string blist (p (point)) (cb (current-buffer))
1716 (refcommands YaTeX-refcommand-regexp)
1717 (foundmsg (format "Type %s %c to return to original position."
1718 (key-description
1719 (car
1720 (or (where-is-internal 'register-to-point)
1721 (where-is-internal 'jump-to-register))))
1722 YaTeX-current-position-register))
1723 (func (function (lambda (string sfunc)
1724 (or
1725 (funcall sfunc string nil t)
1726 (funcall (if (eq sfunc 're-search-forward)
1727 're-search-backward 're-search-forward)
1728 string nil t))))))
1729 (cond
1730 ((YaTeX-on-section-command-p refcommands)
1731 (setq scmd
1732 (cdr
1733 (assoc
1734 (YaTeX-match-string 1)
1735 '(("label" . "\\\\\\(page\\|eq\\)?ref{%k}")
1736 ("ref" . "\\\\label{%k}")
1737 ("eqref" . "\\\\label{%k}")
1738 ("pageref" . "\\\\label{%k}")
1739 ("cite" .
1740 "\\\\bibitem\\(\\[[^]]+\\]\\)?{%k}\\|^\\s *@[a-z]+{%k,")
1741 ("bibitem" . "\\\\cite\\(\\[[^]]+\\]\\)?")))))
1742 (goto-char (match-end 0))
1743 (let ((label (YaTeX-buffer-substring
1744 (1- (point)) (progn (backward-list 1) (1+ (point)))))
1745 (fp (make-marker))fl fn
1746 (goother (function (lambda (buffer point)
1747 (goto-char point)
1748 (if (one-window-p)
1749 (split-window-calculate-height
1750 YaTeX-default-pop-window-height))
1751 (select-window (get-lru-window))
1752 (switch-to-buffer buffer)))))
1753 ;(setq string (concat "\\" scmd "{" label "}"))
1754 ;(setq string (concat "\\\\" scmd "{" (regexp-quote label) "}"))
1755 (setq string (YaTeX-replace-format scmd "k" (regexp-quote label)))
1756 (setq direc (if (string-match "ref\\|cite" scmd)
1757 're-search-forward 're-search-backward))
1758 (if YaTeX-current-position-register
1759 (point-to-register YaTeX-current-position-register))
1760 (if reverse (setq direc (if (eq direc 're-search-forward)
1761 're-search-backward 're-search-forward)))
1762 (if (funcall func string direc) ;label/ref found!
1763 (progn
1764 (if otherwin (funcall goother cb p))
1765 (goto-char (match-beginning 0))
1766 (push-mark p))
1767 ;;if label/ref not found, search through all yatex buffers.
1768 (goto-char p) ;resume position of current buffer
1769 (catch 'found
1770 (setq blist (YaTeX-yatex-buffer-list))
1771 (while blist
1772 ;; search for corresponding keyword
1773 (set-buffer (car blist))
1774 (if (YaTeX-on-section-command-p refcommands)
1775 (goto-char (match-beginning 0)))
1776 (cond
1777 ; cond1
1778 ((funcall func string direc)
1779 (cond
1780 (otherwin
1781 (set-buffer cb)
1782 (funcall goother (car blist) p))
1783 ((or (get-buffer-window (car blist))
1784 (and YaTeX-emacs-19
1785 (get-buffer-window (car blist) t)))
1786 (goto-buffer-window (car blist)))
1787 (t
1788 (switch-to-buffer (car blist))
1789 (message foundmsg)))
1790 (goto-char (match-beginning 0))
1791 (throw 'found t))
1792 ; cond2
1793 ((and
1794 (string-match "bibitem" scmd)
1795 (catch 'found2
1796 (save-excursion
1797 (goto-char (point-min))
1798 (while (YaTeX-re-search-active-forward
1799 "\\\\bibliography{\\([^}]*\\)}" "%" nil t)
1800 (setq fl (YaTeX-split-string (YaTeX-match-string 1) ","))
1801 (while fl
1802 (if (or (file-exists-p (setq fn (car fl)))
1803 (file-exists-p (setq fn (concat fn ".bib"))))
1804 (progn
1805 (set-buffer (find-file-noselect fn))
1806 (save-excursion
1807 (goto-char (point-min))
1808 (if (YaTeX-re-search-active-forward
1809 string "%" nil t)
1810 (throw 'found2
1811 (set-marker fp (point)))))))
1812 (setq fl (cdr fl)))))))
1813 (if otherwin
1814 (funcall goother (marker-buffer fp) fp)
1815 (switch-to-buffer (marker-buffer fp))
1816 (goto-char fp))
1817 (set-marker fp nil)
1818 (message foundmsg)
1819 (throw 'found t)))
1820 (setq blist (cdr blist)))
1821 ;; search for bibliography
1822 )))
1823 (if YaTeX-emacs-19
1824 (setq regexp-search-ring
1825 (cons string (delete string regexp-search-ring)))
1826 (setq search-last-regexp string)))
1827 (t nil))))
1829 ;;YaTeX-goto-corresponding-environment was moved to yatexlib
1831 (defun YaTeX-goto-corresponding-file (&optional other)
1832 "Visit or switch buffer of corresponding file,
1833 looking at \\input or \\include or \\includeonly on current line."
1834 (if (not (YaTeX-on-includes-p)) nil
1835 (let ((parent buffer-file-name) input-file b)
1836 (save-excursion
1837 (if (and (re-search-forward "[{%]" (point-end-of-line) t)
1838 (= ?{ (char-after (match-beginning 0))))
1839 nil
1840 (skip-chars-backward "^,{"))
1841 (setq input-file
1842 (YaTeX-buffer-substring
1843 (point) (progn (skip-chars-forward "^ ,}") (point))))
1844 (if (not (string-match "\\.\\(tex\\|sty\\)$" input-file))
1845 (setq input-file (concat input-file ".tex"))))
1846 (cond
1847 (other (YaTeX-switch-to-buffer-other-window input-file))
1848 ((setq b (YaTeX-get-file-buffer input-file))
1849 (goto-buffer-window b))
1850 (t (YaTeX-switch-to-buffer input-file)))
1851 (or (YaTeX-get-builtin "!")
1852 YaTeX-parent-file
1853 (setq YaTeX-parent-file parent)))))
1855 (defun YaTeX-goto-corresponding-BEGIN-END ()
1856 (if (not (YaTeX-on-BEGIN-END-p)) nil
1857 (if (cond
1858 ((equal (match-beginning 0) (match-beginning 1)) ;if on %#BEGIN
1859 (not (search-forward "%#END" nil t)))
1860 (t ; if on %#END
1861 (not (search-backward "%#BEGIN" nil t))))
1862 (error "Corresponding %%#BEGIN/END not found."))
1863 (beginning-of-line)
1864 t))
1866 (defvar YaTeX-processed-file-regexp-alist nil
1867 "Alist of regexp of processed file regexp vs. its file name part;
1868 For example, if you include image file with `\\epsfile{file=FILE}' where
1869 `FILE' is processed file. You might want to view FILE with other previewer
1870 such as ghostview, or want to preview its source which was drawn with
1871 other drawing tool, tgif for example. Then you should set entire regexp
1872 of including expression and enclose its file name part with \\\\( and \\\\).
1874 Ex. (\"\\\\\\\\epsfile{[^}]*file=\\\\([^,} ]+\\\\)\\\\(\\\\.e?ps\\\\)?[^}]*}\" 1)
1876 Where the first group surrounded by \\\\( and \\\\) is the file name part
1877 of expression. So you should set 1 to second element. And the first
1878 matching group is sent to (image) processor defined by the variable
1879 YaTeX-file-processor-alist. See also the documentation of
1880 YaTeX-file-processor-alist.
1882 ↑じゃ良くわかんないすね。例えば tgif hoge.obj して hoge.eps を
1883 \\epsfile{file=hoge.eps} でインクルードしているとしよう。その行で
1884 \[prefix\] g を押した時に tgif を起動して欲しかったら、まず上のような
1885 正規表現を設定する。\\\\(と\\\\)で囲んだところがファイル名になるように
1886 注意する。でファイル名部分が何番目の\\\\(\\\\)になるかをリストの2番目に書く。
1887 すると、その部分が変数 YaTeX-file-processor-alist で定義された
1888 処理プログラムに渡される。というわけ。
1889 ん〜やっぱりむずかしいね。分からない時は隣の Lisper に聞くか、
1890 fj野鳥の会で聞こう!
1891 ")
1893 (defvar YaTeX-processed-file-regexp-alist-default
1894 '(("\\\\epsfile\\(\\[[^]]+\\]\\)?{[^},]*file=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1895 ("\\\\epsfig{[^},]*fi\\(le\\|gure\\)=\\(\\([^,} ]*/\\)?[^,}. ]+\\)\\(\\.e?ps\\)?[^}]*}" 2)
1896 ("\\\\postscriptbox{[^}]*}{[^}]*}{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 1)
1897 ("\\\\\\(epsfbox\\|epsfig\\)\\*?{\\(\\([^,} ]*/\\)?[^}. ]+\\)\\(\\.e?ps\\)?}" 2) ;\epsfbox{hoge.ps}
1898 ("\\\\includegraphics\\*?\\(.*\\]\\|\\s \\)?{\\(.*\\)\\(\\.ai\\|\\.pdf\\|\\.svg\\|\\.png\\|\\.jpe?g\\|\\.e?ps\\)}" 2) ;\includegraphics[options...]{hoge.eps}
1899 ("\\\\\\(psbox\\)\\(\\[[^]]+\\]\\)?{\\(\\([^,} ]*/\\)?[^} ]+\\)\\(\\.e?ps\\)}" 3) ;\psbox[options...]{hoge.eps} (97/1/11)
1900 ("\\\\input{\\([^} ]+\\)\\(\\.tps\\)}" 1) ;tgif2tex (1998/9/16)
1902 "See the documentation of YaTeX-processed-file-regexp-alist.")
1904 (defvar YaTeX-file-processor-alist nil
1905 "*Alist of files' processor vs. its extension;
1906 See also the documentation of YaTeX-processed-file-regexp-alist.")
1908 (defvar YaTeX-file-processor-alist-default
1909 '(("tgif" . ".obj")
1910 ("gimp" . ".xcf") ("gimp" . ".xcf.gz") ("gimp" . ".xcf.bz2")
1911 ("inkscape" . ".svg") ("inkscape" . ".svgz") ("inkscape" . ".ai")
1912 ("dia" . ".dia")
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: