yatex

view yatex.el @ 84:73cba5ddd111

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