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