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