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