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