yatex

view yatex.el @ 330:9cef5d10a0f1

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