yatex

view yatex.el @ 338:c731bc210af1

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