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