yatex

view yatex.el @ 327:2bc5b59840d5

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