yatex

view yatex.el @ 79:0734be649cb8

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