yatex

view yatex.el @ 360:e17589ce8b0d

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