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