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