yatex

view yatex.el @ 123:590fc51462c7

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