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