0
|
1 ;;; -*- Emacs-Lisp -*-
|
|
2 ;;; Yet Another tex-mode for emacs.
|
1
|
3 ;;; yatex.el rev.1.28
|
0
|
4 ;;; (c)1991 by Hirose Yuuji.[yuuji@ae.keio.ac.jp]
|
1
|
5 ;;; Last modified Mon Jul 20 21:46:13 1992 on figaro
|
0
|
6
|
|
7 (provide 'yatex-mode)
|
1
|
8 (defconst YaTeX-revision-number "1.28"
|
0
|
9 "Revision number of running yatex.el"
|
|
10 )
|
|
11
|
|
12 ;---------- Local variables ----------
|
|
13 ;;;
|
|
14 ;; Initialize local variable for yatex-mode.
|
|
15 ;; Preserving user preferred definitions.
|
|
16 ;; ** Check all of these defvar-ed values **
|
|
17 ;; ** and setq other values more suitable **
|
|
18 ;; ** for your site, if nedded. **
|
|
19 ;;;
|
|
20 (defvar YaTeX-prefix "\^C"
|
|
21 "Prefix key to trigger YaTeX functions.
|
|
22 You can select favorite prefix key by setq in your ~/.emacs."
|
|
23 )
|
|
24 (defvar YaTeX-open-lines 1
|
|
25 "Blank lines between text and \??{??}"
|
|
26 )
|
1
|
27 (defvar YaTeX-fill-prefix ""
|
0
|
28 "fill-prefix used for auto-fill-mode.
|
|
29 The defalut value is single TAB."
|
|
30 )
|
|
31 (defvar YaTeX-user-completion-table "~/.yatexrc"
|
|
32 "Default filename in which user completion table is saved."
|
|
33 )
|
|
34 (defvar tex-command "jlatex"
|
|
35 "Default command for compiling LaTeX text."
|
|
36 )
|
|
37 (defvar dvi2-command ;previewer command for your site
|
|
38 (concat
|
|
39 "xdvi -geo +0+0 -s 4 -display "
|
|
40 (getenv "DISPLAY"))
|
|
41 "Default previewer command including its option.
|
|
42 This default value is for X window system. If you want to use this
|
|
43 default, you have to make sure the environment variable DISPLAY is
|
|
44 correctly set."
|
|
45 )
|
|
46 (defvar latex-warning-regexp "line.* [0-9]*"
|
|
47 "Regular expression of line number of warning message by latex command."
|
|
48 )
|
|
49 (defvar latex-error-regexp "l\\.[1-9][0-9]*"
|
|
50 "Regular expression of line number of latex error. Perhaps your latex
|
|
51 command stops at this error message with line number of LaTeX source text."
|
|
52 )
|
1
|
53 (defvar latex-dos-emergency-message
|
|
54 ;;"Emergency stop" ;<- for Micro tex, ASCII-pTeX 1.6
|
|
55 "No pages of output." ;<- for ASCII-pTeX 1.7
|
0
|
56 "Because Demacs (GNU Emacs on DOS) cannot have pararell process, the
|
|
57 latex command which is stopping on a LaTeX error, is terminated by Demacs.
|
|
58 Many latex command on DOS display some message when it is terminated by
|
|
59 other process, user or OS. Define this variable a message string of your
|
|
60 latex command on DOS shows at abnormal termination.
|
|
61 Remember Demacs's call-process function is not oriented for interactive
|
|
62 process."
|
|
63 )
|
|
64
|
|
65 ;------------ Completion table ------------
|
|
66 ; Set tex-section-like command possible completion
|
|
67 (setq section-table
|
|
68 '(("part") ("section") ("subsection") ("subsubsection")
|
|
69 ("author") ("documentstyle") ("pagestyle")
|
|
70 ("documentstyle[10pt]") ("documentstyle[11pt]")
|
|
71 ("documentstyle[12pt]")
|
|
72 ("item[]") ("title") ("chapter") ("part") ("paragraph")
|
|
73 ("subparagraph") ("underline") ("label") ("footnote")
|
|
74 ("hspace*") ("vspace*") ("bibliography") ("bibitem[]") ("cite[]")
|
|
75 ("nocite") ("input") ("include") ("includeonly") ("mbox") ("hbox")
|
|
76 ("caption") ("newcommand") ("setlength") ("addtolength")
|
|
77 ("newenvironment") ("newtheorem")
|
|
78 ))
|
|
79 (defvar user-section-table nil)
|
|
80
|
|
81 ; Set style possible completion
|
|
82 (setq article-table
|
|
83 '(("article") ("jarticle") ("report") ("jreport") ("jbook")
|
|
84 ("4em") ("2ex")
|
|
85 ("empty") ("headings") ("\\textwidth")
|
|
86 ("\\oddsidemargin") ("\\evensidemargin")
|
|
87 ("\\textheight") ("\\topmargin")
|
|
88 ("\\bottommargin") ("\\footskip") ("\\footheight")
|
|
89 ))
|
|
90 (defvar user-article-table nil)
|
|
91
|
|
92 ; Set tex-environment possible completion
|
|
93 (setq env-table
|
|
94 '(("quote") ("quotation") ("center") ("verse") ("document")
|
|
95 ("verbatim") ("itemize") ("enumerate") ("description")
|
|
96 ("list{}") ("tabular") ("table") ("titlepage")
|
|
97 ("sloppypar") ("ref") ("quotation") ("quote") ("picture")
|
|
98 ("eqnarray") ("figure") ("equation") ("abstract") ("array")
|
|
99 ("thebibliography") ("theindex")
|
|
100 ))
|
|
101 (defvar user-env-table nil)
|
|
102
|
|
103 ; Set {\Large }-like comletion
|
|
104 (setq fontsize-table
|
|
105 '(("rm") ("em") ("bf") ("boldmath") ("it") ("sl") ("sf") ("sc") ("tt")
|
|
106 ("dg") ("dm")
|
|
107 ("tiny") ("scriptsize") ("footnotesize") ("small")("normalsize")
|
|
108 ("large") ("Large") ("LARGE") ("huge") ("Huge")
|
|
109 ))
|
|
110 (defvar user-fontsize-table nil)
|
|
111
|
|
112 (setq singlecmd-table
|
|
113 '(("maketitle") ("sloppy")
|
|
114 ("alpha") ("beta") ("gamma") ("delta") ("epsilon") ("varepsilon")
|
|
115 ("zeta") ("eta") ("theta")("vartheta") ("iota") ("kappa")
|
|
116 ("lambda") ("mu") ("nu") ("xi") ("pi") ("varpi") ("rho") ("varrho")
|
|
117 ("sigma") ("varsigma") ("tau") ("upsilon") ("phi") ("varphi")
|
|
118 ("chi") ("psi") ("omega") ("Gamma") ("Delta") ("Theta") ("Lambda")
|
|
119 ("Xi") ("Pi") ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")
|
|
120 ("LaTeX") ("TeX")
|
|
121 ))
|
|
122 (defvar user-singlecmd-table nil)
|
|
123
|
|
124 ;---------- Key mode map ----------
|
|
125 ;;;
|
|
126 ;; Create new key map: YaTeX-mode-map
|
|
127 ;; Do not change this section.
|
|
128 ;;;
|
|
129 (defvar YaTeX-mode-map nil
|
|
130 "Keymap used in YaTeX mode."
|
|
131 )
|
|
132 (defvar YaTeX-compilation-mode-map nil
|
|
133 "Keymap userd in YaTeX compilation buffer."
|
|
134 )
|
|
135
|
|
136 ;---------- Define deafult key bindings on YaTeX mode map ----------
|
|
137 ;;;
|
|
138 ;; Define key table
|
|
139 ;;;
|
|
140 (if YaTeX-mode-map
|
|
141 nil
|
|
142 (global-unset-key (concat YaTeX-prefix "b"))
|
|
143 (setq YaTeX-mode-map (make-sparse-keymap))
|
|
144 (define-key YaTeX-mode-map (concat YaTeX-prefix "tj")
|
|
145 'YaTeX-compile)
|
|
146 (define-key YaTeX-mode-map (concat YaTeX-prefix "tx")
|
|
147 'YaTeX-preview)
|
|
148 (define-key YaTeX-mode-map (concat YaTeX-prefix "tv")
|
|
149 'YaTeX-view-error)
|
|
150 (define-key YaTeX-mode-map (concat YaTeX-prefix "tb")
|
|
151 '(lambda () (interactive) (YaTeX-insert-string "\\")))
|
|
152 (define-key YaTeX-mode-map (concat YaTeX-prefix "'")
|
|
153 'YaTeX-prev-error)
|
|
154 (define-key YaTeX-mode-map (concat YaTeX-prefix " ")
|
|
155 'YaTeX-do-completion)
|
|
156 (define-key YaTeX-mode-map (concat YaTeX-prefix "v")
|
|
157 'YaTeX-version)
|
|
158
|
|
159 (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
|
|
160 (define-key YaTeX-mode-map (concat YaTeX-prefix "{")
|
|
161 'YaTeX-insert-braces)
|
|
162 (define-key YaTeX-mode-map (concat YaTeX-prefix "}")
|
|
163 'YaTeX-insert-braces-region)
|
|
164 (define-key YaTeX-mode-map (concat YaTeX-prefix "d")
|
|
165 'YaTeX-insert-dollar)
|
|
166 (define-key YaTeX-mode-map (concat YaTeX-prefix "\\")
|
|
167 '(lambda () (interactive) (YaTeX-insert-string "$\\backslash$")))
|
|
168 (define-key YaTeX-mode-map (concat YaTeX-prefix "bd")
|
|
169 '(lambda (arg) (interactive "P")
|
|
170 (YaTeX-insert-begin-end "document" arg)))
|
|
171 (define-key YaTeX-mode-map (concat YaTeX-prefix "Bd")
|
|
172 '(lambda () (interactive)
|
|
173 (YaTeX-insert-begin-end "document" t)))
|
|
174 (define-key YaTeX-mode-map (concat YaTeX-prefix "bD")
|
|
175 '(lambda (arg) (interactive "P")
|
|
176 (YaTeX-insert-begin-end "description" arg)))
|
|
177 (define-key YaTeX-mode-map (concat YaTeX-prefix "BD")
|
|
178 '(lambda () (interactive)
|
|
179 (YaTeX-insert-begin-end "description" t)))
|
|
180 (define-key YaTeX-mode-map (concat YaTeX-prefix "be")
|
|
181 '(lambda (arg) (interactive "P")
|
|
182 (YaTeX-insert-begin-end "enumerate" arg)))
|
|
183 (define-key YaTeX-mode-map (concat YaTeX-prefix "Be")
|
|
184 '(lambda () (interactive)
|
|
185 (YaTeX-insert-begin-end "enumerate" t)))
|
|
186 (define-key YaTeX-mode-map (concat YaTeX-prefix "bi")
|
|
187 '(lambda (arg) (interactive "P")
|
|
188 (YaTeX-insert-begin-end "itemize" arg)))
|
|
189 (define-key YaTeX-mode-map (concat YaTeX-prefix "Bi")
|
|
190 '(lambda () (interactive)
|
|
191 (YaTeX-insert-begin-end "itemize" t)))
|
|
192 (define-key YaTeX-mode-map (concat YaTeX-prefix "bt")
|
|
193 '(lambda (arg) (interactive "P")
|
|
194 (YaTeX-insert-begin-end "tabbing" arg)))
|
|
195 (define-key YaTeX-mode-map (concat YaTeX-prefix "Bt")
|
|
196 '(lambda () (interactive)
|
|
197 (YaTeX-insert-begin-end "tabbing" t)))
|
|
198 (define-key YaTeX-mode-map (concat YaTeX-prefix "bT")
|
|
199 '(lambda (arg) (interactive "P")
|
|
200 (YaTeX-insert-begin-end "tabular" arg)))
|
|
201 (define-key YaTeX-mode-map (concat YaTeX-prefix "BT")
|
|
202 '(lambda () (interactive)
|
|
203 (YaTeX-insert-begin-end "tabular" t)))
|
|
204 (define-key YaTeX-mode-map (concat YaTeX-prefix "bq")
|
|
205 '(lambda (arg) (interactive "P")
|
|
206 (YaTeX-insert-begin-end "quote" arg)))
|
|
207 (define-key YaTeX-mode-map (concat YaTeX-prefix "Bq")
|
|
208 '(lambda () (interactive)
|
|
209 (YaTeX-insert-begin-end "quote" t)))
|
|
210 (define-key YaTeX-mode-map (concat YaTeX-prefix "bQ")
|
|
211 '(lambda (arg) (interactive "P")
|
|
212 (YaTeX-insert-begin-end "quotation" arg)))
|
|
213 (define-key YaTeX-mode-map (concat YaTeX-prefix "BQ")
|
|
214 '(lambda () (interactive)
|
|
215 (YaTeX-insert-begin-end "quotation" t)))
|
|
216 (define-key YaTeX-mode-map (concat YaTeX-prefix "b ")
|
|
217 'YaTeX-make-begin-end)
|
|
218 (define-key YaTeX-mode-map (concat YaTeX-prefix "B ")
|
|
219 'YaTeX-make-begin-end-region)
|
|
220 (define-key YaTeX-mode-map (concat YaTeX-prefix "s")
|
|
221 'YaTeX-make-section)
|
|
222 (define-key YaTeX-mode-map (concat YaTeX-prefix "l")
|
|
223 'YaTeX-make-fontsize)
|
|
224 (define-key YaTeX-mode-map (concat YaTeX-prefix "L")
|
|
225 'YaTeX-make-fontsize-region)
|
|
226 (define-key YaTeX-mode-map (concat YaTeX-prefix "m")
|
|
227 'YaTeX-make-singlecmd)
|
|
228 (define-key YaTeX-mode-map (concat YaTeX-prefix "\C-m")
|
|
229 '(lambda () (interactive) (YaTeX-insert-string "\\\\")))
|
|
230 (if (eq system-type 'ms-dos)
|
|
231 (define-key YaTeX-mode-map (concat YaTeX-prefix "\^L")
|
|
232 '(lambda () (interactive)
|
|
233 (set-screen-height 24) (recenter))))
|
|
234 )
|
|
235
|
|
236 (if YaTeX-compilation-mode-map nil
|
|
237 (setq YaTeX-compilation-mode-map (make-keymap))
|
|
238 (suppress-keymap YaTeX-compilation-mode-map t)
|
|
239 (define-key YaTeX-compilation-mode-map " "
|
|
240 'YaTeX-jump-error-line)
|
|
241 )
|
|
242
|
|
243 ;---------- Customize as you like above ----------
|
|
244
|
|
245 ;---------- Define other variable ----------
|
|
246 (defvar env-name "document") ;Initial tex-environment completion
|
|
247 (defvar section-name "documentstyle[12pt]") ;Initial tex-section completion
|
|
248 (defvar fontsize-name "large") ;Initial fontsize completion
|
|
249 (defvar single-command "maketitle") ;Initial LaTeX single command
|
|
250 (defvar YaTeX-user-table-has-read nil
|
|
251 "Flag that means whether user completion table has read or not."
|
|
252 )
|
|
253 (defvar yatex-mode-hook nil
|
|
254 "List of functions to be called after .tex file is read
|
|
255 and yatex-mode starts.")
|
|
256
|
|
257 ;---------- Produce YaTeX-mode ----------
|
|
258 ;;;
|
|
259 ;; Major mode definition
|
|
260 ;;;
|
|
261 (defun yatex-mode ()
|
|
262 (interactive)
|
|
263 (kill-all-local-variables)
|
|
264 (setq major-mode 'YaTeX-mode)
|
1
|
265 (setq mode-name "‚â‚Ä‚Ó‚à[‚Ç")
|
0
|
266 (turn-on-auto-fill)
|
1
|
267 (make-local-variable 'kanji-display-code)
|
|
268 (make-local-variable 'kanji-fileio-code)
|
|
269 (if (eq system-type 'ms-dos)
|
|
270 (setq YaTeX-kanji-code 1)
|
|
271 (defvar YaTeX-kanji-code 2))
|
|
272 (setq kanji-display-code YaTeX-kanji-code
|
|
273 kanji-fileio-code YaTeX-kanji-code)
|
0
|
274 (make-local-variable 'fill-column)
|
|
275 (make-local-variable 'fill-prefix)
|
|
276 (setq fill-column 72
|
|
277 fill-prefix YaTeX-fill-prefix)
|
|
278 (use-local-map YaTeX-mode-map)
|
|
279 (if (eq system-type 'ms-dos)
|
|
280 (set-screen-height 24))
|
|
281 (if YaTeX-user-table-has-read nil
|
|
282 (YaTeX-read-user-completion-table)
|
|
283 (setq YaTeX-user-table-has-read t))
|
|
284 (run-hooks 'yatex-mode-hook)
|
|
285 )
|
|
286
|
|
287 ;---------- Define YaTeX-mode functions ----------
|
|
288 ;;;
|
|
289 ;; YaTeX-mode functions
|
|
290 ;;;
|
|
291 (defun YaTeX-insert-begin-end (env arg)
|
|
292 "Insert \begin{mode-name} and \end{mode-name}."
|
|
293 (if arg
|
|
294 (save-excursion
|
|
295 (if (> (point) (mark)) (exchange-point-and-mark))
|
|
296 (insert "\\begin{" env "}\n")
|
|
297 (exchange-point-and-mark)
|
|
298 (insert "\\end{" env "}\n"))
|
|
299 (delete-blank-lines)
|
|
300 (insert "\\begin{" env "}\n")
|
|
301 (newline (1+ (* 2 YaTeX-open-lines)))
|
|
302 (insert "\\end{" env "}\n")
|
|
303 (previous-line (+ 2 YaTeX-open-lines)))
|
|
304 )
|
|
305
|
|
306 (defun YaTeX-exist-completion-table (elm table)
|
|
307 "Return nil, if single list element:elm was
|
|
308 not found in possible completion table."
|
|
309 (while (not (or (null table) (equal elm (car table))))
|
|
310 (setq table (cdr table)))
|
|
311 table
|
|
312 )
|
|
313
|
|
314 (defun YaTeX-make-begin-end (arg)
|
|
315 "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
|
|
316 by completing read.
|
|
317 If you invoke this command with universal argument,
|
|
318 \(C-u or ESC-1 is typical prefix to invoke commands with ARG.\)
|
|
319 you can put REGION into that environment between \\begin and \\end."
|
|
320 (interactive "P")
|
|
321 (let*
|
|
322 ((mode (if arg " region" ""))
|
|
323 (env
|
|
324 (completing-read
|
|
325 (format "Begin environment%s(default %s): " mode env-name)
|
|
326 (append user-env-table env-table) nil nil)))
|
|
327 (if (string= env "")
|
|
328 (setq env env-name))
|
|
329 (setq env-name env)
|
|
330 (if (not (YaTeX-exist-completion-table
|
|
331 (list env-name) (append user-env-table env-table)))
|
|
332 (setq user-env-table (cons (list env-name) user-env-table)))
|
|
333 (YaTeX-insert-begin-end env-name arg))
|
|
334 )
|
|
335
|
|
336 (defun YaTeX-make-begin-end-region ()
|
|
337 "Call YaTeX-make-begin-end with ARG to specify region mode."
|
|
338 (interactive)
|
|
339 (YaTeX-make-begin-end t)
|
|
340 )
|
|
341
|
|
342 (defun YaTeX-make-section (arg)
|
|
343 "Make LaTeX \\section{} type command with completing read.
|
|
344 With ARG of numeric, you can specify the number of argument of
|
|
345 LaTeX command.
|
|
346 For example, if you want to produce LaTeX command
|
|
347
|
|
348 \\addtolength{\\topmargin}{8mm}
|
|
349
|
|
350 which has two argument. You can produce that sequence by typing...
|
|
351 ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
|
|
352 \(by default\)
|
|
353 You can complete symbol at LaTeX command and 1st argument."
|
|
354 (interactive "p")
|
|
355 (let*
|
|
356 ((section
|
|
357 (completing-read
|
|
358 (format "\\???{} (default %s): " section-name)
|
|
359 (append user-section-table section-table)
|
|
360 nil nil))
|
|
361 (section (if (string= section "") section-name section))
|
|
362 (title
|
|
363 (completing-read (concat "\\" section "{???}: ")
|
|
364 (append user-article-table article-table)
|
|
365 nil nil)))
|
|
366 (setq section-name section)
|
|
367 (if (not (YaTeX-exist-completion-table
|
|
368 (list section-name) (append user-section-table section-table)))
|
|
369 (setq user-section-table
|
|
370 (cons (list section-name) user-section-table)))
|
|
371 (insert "\\" section-name "{" title "}")
|
|
372 (let ((j 2))
|
|
373 (while (<= j arg)
|
|
374 (insert (concat "{" (read-string (format "Argument %d: " j))))
|
|
375 (insert "}")
|
|
376 (setq j (1+ j)))
|
|
377 )
|
|
378 (if (string= title "") (forward-char -1)
|
|
379 nil))
|
|
380 )
|
|
381
|
|
382 ;(defun YaTeX-make-section-region ()
|
|
383 ; "Call YaTeX-make-section with ARG to specify region mode."
|
|
384 ; (interactive)
|
|
385 ; (YaTeX-make-section t)
|
|
386 ;)
|
|
387
|
|
388 (defun YaTeX-make-fontsize (arg)
|
|
389 "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
|
|
390 If you invoke this command with universal argument, you can put region
|
|
391 into {\\xxx } braces.
|
|
392 \(C-u or ESC-1 are default key bindings of universal-argument.\)"
|
|
393 (interactive "P")
|
|
394 (let* ((mode (if arg "region" ""))
|
|
395 (fontsize
|
|
396 (completing-read
|
|
397 (format "{\\??? %s} (default %s): " mode fontsize-name)
|
|
398 (append user-fontsize-table fontsize-table)
|
|
399 nil nil )))
|
|
400 (if (string= fontsize "")
|
|
401 (setq fontsize fontsize-name))
|
|
402 (setq fontsize-name fontsize)
|
|
403 (if (not (YaTeX-exist-completion-table
|
|
404 (list fontsize-name)
|
|
405 (append user-fontsize-table fontsize-table)))
|
|
406 (setq user-fontsize-table
|
|
407 (cons (list fontsize-name) user-fontsize-table)))
|
|
408 (if arg
|
|
409 (save-excursion
|
|
410 (if (> (point) (mark)) (exchange-point-and-mark))
|
|
411 (insert "{\\" fontsize-name " ")
|
|
412 (exchange-point-and-mark)
|
|
413 (insert "}"))
|
|
414 (insert "{\\" fontsize-name " }")
|
|
415 (forward-char -1)))
|
|
416 )
|
|
417
|
|
418 (defun YaTeX-make-fontsize-region ()
|
|
419 "Call functino:YaTeX-make-fontsize with ARG to specify region mode."
|
|
420 (interactive)
|
|
421 (YaTeX-make-fontsize t)
|
|
422 )
|
|
423
|
|
424 (defun YaTeX-make-singlecmd (single)
|
|
425 (interactive
|
|
426 (list (completing-read
|
|
427 (format "\\??? (default %s): " single-command)
|
|
428 (append user-singlecmd-table singlecmd-table)
|
|
429 nil nil )))
|
|
430 (if (string= single "")
|
|
431 (setq single single-command))
|
|
432 (setq single-command single)
|
|
433 (if (not (YaTeX-exist-completion-table
|
|
434 (list single-command)
|
|
435 (append user-singlecmd-table singlecmd-table)))
|
|
436 (setq user-singlecmd-table
|
|
437 (cons (list single-command) user-singlecmd-table)))
|
|
438 (insert "\\" single-command " ")
|
|
439 )
|
|
440
|
|
441 (defvar YaTeX-completion-begin-regexp "[{\\]"
|
|
442 "Regular expression of limit where LaTeX command's
|
|
443 completion begins.")
|
|
444
|
|
445 (defun YaTeX-do-completion ()
|
|
446 "Try completion on LaTeX command preceding point."
|
|
447 (interactive)
|
|
448 (if
|
|
449 (or (eq (preceding-char) ? )
|
|
450 (eq (preceding-char) ?\t)
|
|
451 (eq (preceding-char) ?\n)
|
|
452 (bobp))
|
|
453 (message "Nothing to complete.") ;Do not complete
|
|
454 (let* ((end (point))
|
|
455 (limit (save-excursion (beginning-of-line) (point)))
|
|
456 (completion-begin
|
|
457 (progn (re-search-backward "[ \t\n]" limit 1)
|
|
458 (point)))
|
|
459 (begin (progn
|
|
460 (goto-char end)
|
|
461 (if (re-search-backward YaTeX-completion-begin-regexp
|
|
462 completion-begin t)
|
|
463 (1+ (point))
|
|
464 nil))))
|
|
465 (goto-char end)
|
|
466 (cond
|
|
467 ((null begin)
|
|
468 (message "I think it is not LaTeX sequence."))
|
|
469 (t
|
|
470 (let* ((pattern (buffer-substring begin end))
|
|
471 (all-table (append section-table user-section-table
|
|
472 article-table user-article-table
|
|
473 env-table user-env-table
|
|
474 singlecmd-table user-singlecmd-table))
|
|
475 ;; First,
|
|
476 ;; search completion without backslash.
|
|
477 (completion (try-completion pattern all-table nil)))
|
|
478 (if
|
|
479 (eq completion nil)
|
|
480 ;; Next,
|
|
481 ;; search completion with backslash
|
|
482 (setq completion
|
|
483 (try-completion (buffer-substring (1- begin) end)
|
|
484 all-table nil)
|
|
485 begin (1- begin)))
|
|
486 (cond
|
|
487 ((null completion)
|
|
488 (message (concat "Can't find completion for '" pattern "'"))
|
|
489 (ding))
|
|
490 ((eq completion t) (message "Sole completion."))
|
|
491 ((not (string= completion pattern))
|
|
492 (kill-region begin end)
|
|
493 (insert completion)
|
|
494 )
|
|
495 (t
|
|
496 (message "Making completion list...")
|
|
497 (with-output-to-temp-buffer "*Help*"
|
|
498 (display-completion-list
|
|
499 (all-completions pattern all-table))) )
|
|
500 ))))))
|
|
501 )
|
|
502
|
|
503 (defun YaTeX-insert-quote ()
|
|
504 (interactive)
|
|
505 (insert
|
|
506 (cond
|
|
507 ((= (preceding-char) ?\\ ) ?\")
|
|
508 ((= (preceding-char) ?\( ) ?\")
|
|
509 ((= (preceding-char) 32) "``")
|
|
510 ((= (preceding-char) 9) "``")
|
|
511 ((= (preceding-char) ?\n) "``")
|
|
512 ((bobp) "``")
|
|
513 (t "''")
|
|
514 )))
|
|
515
|
|
516
|
|
517 (defun YaTeX-insert-braces-region (beg end)
|
|
518 (interactive "r")
|
|
519 (save-excursion
|
|
520 (goto-char end)
|
|
521 (insert "}")
|
|
522 (goto-char beg)
|
|
523 (insert "{"))
|
|
524 )
|
|
525
|
|
526 (defun YaTeX-insert-braces ()
|
|
527 (interactive)
|
|
528 (insert "{}")
|
|
529 (forward-char -1)
|
|
530 )
|
|
531
|
|
532 (defun YaTeX-insert-dollar ()
|
|
533 (interactive)
|
|
534 (insert "$$")
|
|
535 (forward-char -1)
|
|
536 )
|
|
537
|
|
538 (defun YaTeX-insert-string (s)
|
|
539 (insert s)
|
|
540 )
|
|
541
|
|
542 (defun YaTeX-version ()
|
|
543 "Return string of the version of running YaTeX."
|
|
544 (interactive)
|
|
545 (message
|
1
|
546 (concat "Yet Another TeX mode u–ì’¹v Revision "
|
0
|
547 YaTeX-revision-number))
|
|
548 )
|
|
549
|
|
550 (defun YaTeX-compile-sentinel (proc mes)
|
|
551 (cond ((null (buffer-name (process-buffer proc)))
|
|
552 ;; buffer killed
|
|
553 (set-process-buffer proc nil))
|
|
554 ((memq (process-status proc) '(signal exit))
|
|
555 (let* ((obuf (current-buffer)))
|
|
556 ;; save-excursion isn't the right thing if
|
|
557 ;; process-buffer is current-buffer
|
|
558 (unwind-protect
|
|
559 (progn
|
|
560 ;; Write something in *compilation* and hack its mode line
|
|
561 (set-buffer (process-buffer proc))
|
|
562 (goto-char (point-max))
|
|
563 (insert ?\n "jlatex compilation " mes)
|
|
564 (forward-char -1)
|
|
565 (insert " at "
|
|
566 (substring (current-time-string) 0 -5))
|
|
567 (insert "\n * Hit any key to return * ")
|
|
568 (forward-char 1)
|
|
569 (setq mode-line-process
|
|
570 (concat ": "
|
|
571 (symbol-name (process-status proc))))
|
|
572 ;; If buffer and mode line will show that the process
|
|
573 ;; is dead, we can delete it now. Otherwise it
|
|
574 ;; will stay around until M-x list-processes.
|
|
575 (delete-process proc)
|
|
576 )
|
|
577 (setq YaTeX-compilation-process nil)
|
|
578 ;; Force mode line redisplay soon
|
|
579 (set-buffer-modified-p (buffer-modified-p))
|
|
580 )
|
|
581 (set-buffer obuf)
|
|
582 )))
|
|
583 )
|
|
584
|
|
585 (defvar YaTeX-compilation-process nil
|
|
586 "Process identifier for jlatex"
|
|
587 )
|
|
588
|
|
589 (defun YaTeX-compile ()
|
|
590 "Execute jlatex (or other) to LaTeX compile."
|
|
591 (interactive)
|
|
592 (if YaTeX-compilation-process
|
|
593 (if (eq (process-status YaTeX-compilation-process) 'run)
|
|
594 (progn (interrupt-process YaTeX-compilation-process)
|
|
595 (sit-for 1)
|
|
596 (delete-process YaTeX-compilation-process))
|
|
597 nil) nil)
|
|
598 ; (compile1 (concat tex-command " " (buffer-name))
|
|
599 ; "TeX error" "*TeX compilation*")
|
|
600 (setq YaTeX-compilation-process nil)
|
|
601 (if (eq system-type 'ms-dos) ;if MS-DOS
|
|
602 (with-output-to-temp-buffer "*YaTeX-compilation*"
|
|
603 (message (concat "Compiling " (buffer-name) "..."))
|
1
|
604 (YaTeX-put-nonstopmode)
|
|
605 (basic-save-buffer)
|
|
606 (call-process shell-file-name
|
|
607 nil
|
|
608 "*YaTeX-compilation*" nil
|
|
609 "/c" (YaTeX-get-latex-command))
|
|
610 ;;;"/c " tex-command (buffer-name) )
|
|
611 (YaTeX-remove-nonstopmode))
|
0
|
612 (setq YaTeX-compilation-process ;if UNIX
|
|
613 (with-output-to-temp-buffer "*YaTeX-compilation*"
|
1
|
614 (basic-save-buffer)
|
0
|
615 (start-process "LaTeX" "*YaTeX-compilation*" shell-file-name "-c"
|
1
|
616 (YaTeX-get-latex-command))
|
|
617 ;;;tex-command (buffer-name) "")
|
0
|
618 ))
|
|
619 (set-process-sentinel YaTeX-compilation-process 'YaTeX-compile-sentinel))
|
|
620 (setq current-TeX-buffer (buffer-name))
|
|
621 (other-window 1)
|
|
622 (use-local-map YaTeX-compilation-mode-map)
|
|
623 (set-kanji-process-code YaTeX-kanji-code)
|
|
624 (message "Type SPC to continue.")
|
|
625 (goto-char (point-max))
|
|
626 (sit-for 30)
|
|
627 (read-char) ;hit any key
|
|
628 (other-window -1)
|
|
629 )
|
|
630
|
|
631 (defun YaTeX-preview (preview-command preview-file)
|
|
632 "Execute xdvi (or other) to tex-preview."
|
|
633 (interactive
|
|
634 (list (read-string "Preview command: " dvi2-command)
|
|
635 (read-string "Prefiew file[.dvi]: "
|
|
636 (substring (buffer-name) 0 -4)
|
|
637 )))
|
|
638 (setq dvi2-command preview-command)
|
|
639 (with-output-to-temp-buffer "*dvi-preview*"
|
|
640 (if (eq system-type 'ms-dos)
|
|
641 (progn (send-string-to-terminal "\e[2J") ;if MS-DOS
|
|
642 (call-process shell-file-name "con" "*dvi-preview*" nil
|
|
643 "/c " dvi2-command preview-file)
|
|
644 (redraw-display))
|
|
645 (start-process "xdvi" "*dvi-preview*" shell-file-name "-c"
|
|
646 (concat dvi2-command " " preview-file)) ;if UNIX
|
|
647 (message (concat "Starting " dvi2-command " to preview " preview-file)))
|
|
648 )
|
|
649 )
|
|
650
|
|
651 (defun YaTeX-prev-error ()
|
|
652 "Visit previous error. The reason why not NEXT-error is to
|
|
653 avoid make confliction of line numbers by editing."
|
|
654 (interactive)
|
|
655 (setq cur-buf (buffer-name)
|
|
656 YaTeX-error-line nil)
|
|
657 (if (null (get-buffer "*YaTeX-compilation*"))
|
|
658 (message "There is no output buffer of compilation.")
|
|
659 (pop-to-buffer "*YaTeX-compilation*")
|
|
660 (if (eq system-type 'ms-dos)
|
|
661 (if (search-backward latex-dos-emergency-message nil t)
|
|
662 (progn (goto-char (point-max))
|
|
663 (setq error-regexp latex-error-regexp))
|
|
664 (beginning-of-line)
|
|
665 (forward-char -1)
|
|
666 (setq error-regexp latex-warning-regexp))
|
|
667 (if YaTeX-compilation-process ; if jlatex on UNIX
|
|
668 (if (eq (process-status YaTeX-compilation-process) 'run)
|
|
669 (progn
|
|
670 (goto-char (point-max))
|
|
671 (setq error-regexp latex-error-regexp)))
|
|
672 (beginning-of-line)
|
|
673 (setq error-regexp latex-warning-regexp)))
|
|
674 (if (re-search-backward error-regexp nil t)
|
|
675 (save-restriction
|
|
676 (set-mark-command nil)
|
|
677 (end-of-line)
|
|
678 (narrow-to-region (point) (mark))
|
|
679 (goto-char (point-min))
|
|
680 (re-search-forward "[0-9]")
|
|
681 (forward-char -1)
|
|
682 (set-mark (point))
|
1
|
683 (skip-chars-forward "0-9")
|
0
|
684 (narrow-to-region (point) (mark))
|
|
685 (goto-char (point-min))
|
|
686 (setq YaTeX-error-line (read (current-buffer))))
|
|
687 (message "No more error on %s" cur-buf)
|
|
688 (ding)
|
|
689 )
|
|
690 (other-window -1)
|
|
691 (switch-to-buffer cur-buf)
|
|
692 (if (null YaTeX-error-line)
|
|
693 nil
|
|
694 (goto-line YaTeX-error-line)
|
|
695 (message "latex error or warning at line: %d" YaTeX-error-line)
|
|
696 (other-window 1)
|
|
697 (skip-chars-backward "[0-9]")
|
|
698 (recenter (/ (window-height) 2))
|
|
699 (sit-for 3)
|
|
700 (forward-line -1)
|
|
701 (other-window -1)
|
|
702 ))
|
|
703 )
|
|
704
|
|
705 (defun YaTeX-jump-error-line ()
|
|
706 "Jump corresponding line on latex command's error message."
|
|
707 (interactive)
|
|
708 (let ((end (progn (end-of-line) (point)))
|
|
709 (begin (progn (beginning-of-line)(point))))
|
|
710 (if (null (re-search-forward "l[ ines]*\\.*[1-9][0-9]*" end t))
|
|
711 (message "No line number expression")
|
|
712 (goto-char (match-beginning 0))
|
|
713 (re-search-forward "[1-9][0-9]*" end t)
|
|
714 (save-restriction
|
|
715 (narrow-to-region (match-beginning 0) (match-end 0))
|
|
716 (goto-char (point-min))
|
|
717 (let ((error-line (read (current-buffer))))
|
|
718 (other-window -1)
|
|
719 (switch-to-buffer current-TeX-buffer)
|
|
720 (goto-line error-line)))))
|
|
721 )
|
|
722
|
|
723 (defun YaTeX-view-error ()
|
|
724 (interactive)
|
|
725 (other-window 1)
|
|
726 (goto-char (point-max))
|
|
727 (other-window -1)
|
|
728 )
|
|
729
|
1
|
730 (defun YaTeX-put-nonstopmode ()
|
|
731 (if (boundp 'YaTeX-need-nonstop)
|
|
732 (if (re-search-backward "\\nonstopmode{}" (point-min) t)
|
|
733 nil ;if already written in text then do nothing
|
|
734 (save-excursion
|
|
735 (goto-char (point-min))
|
|
736 (insert "\\nonstopmode{}%_YaTeX_%\n")))
|
|
737 )
|
|
738 )
|
|
739
|
|
740 (defun YaTeX-remove-nonstopmode ()
|
|
741 (if (boundp 'YaTeX-need-nonstop) ;for speed
|
|
742 (save-excursion
|
|
743 (goto-char (point-min))
|
|
744 (forward-line 1)
|
|
745 (narrow-to-region (point-min) (point))
|
|
746 (goto-char (point-min))
|
|
747 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$")
|
|
748 (widen)))
|
|
749 )
|
|
750
|
|
751 (defun YaTeX-get-latex-command ()
|
|
752 "Specify the latex-command name and its argument.
|
|
753 If there is a line which begins by string: \"%#!\", the following
|
|
754 strings are assumed to be the latex-command and arguments. The
|
|
755 default value of latex-command is:
|
|
756 tex-command (buffer-name)
|
|
757 and if you write \"%#!jlatex\" in the beginning of certain line.
|
|
758 \"jlatex \" (buffer-name)
|
|
759 will be the latex-command,
|
|
760 and you write \"%#!jlatex main.tex\"
|
|
761 \"jlatex main.tex\"
|
|
762 will be given to the shell."
|
|
763 (let*
|
|
764 ((default-command
|
|
765 (concat tex-command " " (buffer-name)))) ;default value
|
|
766 (save-excursion
|
|
767 (goto-char (point-min))
|
|
768 (if (null (re-search-forward "^%#!" (point-max) t))
|
|
769 default-command
|
|
770 (skip-chars-forward "%#! ")
|
|
771 (if (eolp)
|
|
772 default-command
|
|
773 (let ((s (point)))
|
|
774 (skip-chars-forward "A-z") ;Skip command name
|
|
775 ;(setq YaTeX-latex-command (buffer-substring s (point)))
|
|
776 (if (eolp) ;Only change command name
|
|
777 (concat (buffer-substring s (point)) " " (buffer-name))
|
|
778 (end-of-line) ;Change entire command name
|
|
779 (buffer-substring s (point)) ;including arguments.
|
|
780 ))
|
|
781 ))))
|
|
782 )
|
|
783
|
0
|
784 (defun YaTeX-read-user-completion-table ()
|
|
785 "Append user completion table of LaTeX word"
|
|
786 (message "Loading personal completion table")
|
|
787 (let ((user-table (expand-file-name YaTeX-user-completion-table)))
|
|
788 (if (file-exists-p user-table)
|
|
789 (load-file user-table)
|
|
790 (message "Personal completion table not found."))
|
|
791 ))
|
|
792
|
|
793 (defun YaTeX-save-table ()
|
|
794 "Save personal completion table as dictionary."
|
|
795 (interactive)
|
|
796 (message "Saving user table in %s" YaTeX-user-completion-table)
|
|
797 (find-file (expand-file-name YaTeX-user-completion-table))
|
|
798 (erase-buffer)
|
|
799 ; (prin1-to-string user-section-table)
|
|
800 (insert "(setq user-section-table '(\n")
|
|
801 (mapcar '(lambda (s)
|
|
802 (insert (prin1-to-string s))
|
|
803 (insert "\n"))
|
|
804 user-section-table)
|
|
805 (insert "))\n\n")
|
|
806
|
|
807 (insert "(setq user-article-table '(\n")
|
|
808 (mapcar '(lambda (s)
|
|
809 (insert (prin1-to-string s))
|
|
810 (insert "\n"))
|
|
811 user-article-table)
|
|
812 (insert "))\n\n")
|
|
813
|
|
814 (insert "(setq user-env-table '(\n")
|
|
815 (mapcar '(lambda (s)
|
|
816 (insert (prin1-to-string s))
|
|
817 (insert "\n"))
|
|
818 user-env-table)
|
|
819 (insert "))\n\n")
|
|
820
|
|
821 (insert "(setq user-fontsize-table '(\n")
|
|
822 (mapcar '(lambda (s)
|
|
823 (insert (prin1-to-string s))
|
|
824 (insert "\n"))
|
|
825 user-fontsize-table)
|
|
826 (insert "))\n\n")
|
|
827
|
|
828 (insert "(setq user-singlecmd-table '(\n")
|
|
829 (mapcar '(lambda (s)
|
|
830 (insert (prin1-to-string s))
|
|
831 (insert "\n"))
|
|
832 user-singlecmd-table)
|
|
833 (insert "))\n")
|
|
834
|
|
835 (basic-save-buffer)
|
|
836 (kill-buffer (current-buffer))
|
|
837 (message "")
|
|
838 )
|
|
839
|
|
840 (defun append-to-hook (hook hook-list)
|
|
841 "Add hook-list to certain emacs's hook correctly.
|
|
842 Argument hook-list is the list of function int the form to be called
|
|
843 Call this function with argument as next example,
|
|
844 (append-to-hook '((ding))) ;If one function to add.
|
|
845 (append-to-hook '((func1)(func2 arg)))."
|
|
846 (if (null (eval hook)) ;Not defined
|
|
847 (set hook
|
|
848 (append '(lambda ()) hook-list))
|
|
849 (if (listp (eval hook))
|
|
850 (if (eq (car (eval hook)) 'lambda) ;'(lambda () ....)
|
|
851 (set hook
|
|
852 (append (eval hook) hook-list))
|
|
853 (if (eq hook 'kill-emacs-hook) ;'(hook1 hook2 ...)
|
|
854 (progn ; this format is not
|
|
855 (ding) ; for kill-emacs-hook
|
|
856 (message
|
|
857 "Caution!! you have wrong format of kill-emacs-hook"))
|
|
858 (while (not (null hook-list))
|
|
859 (set hook
|
|
860 (append (eval hook) (car hook-list)))
|
|
861 (setq hook-list (cdr hook-list))))
|
|
862 )
|
|
863 (set hook ;'hook
|
|
864 (append '(lambda ())
|
|
865 (cons (list (eval hook)) hook-list)))))
|
|
866 )
|
|
867 (append-to-hook 'kill-emacs-hook '((YaTeX-save-table)))
|
|
868
|
|
869 ;--------------------------------- History ---------------------------------
|
|
870 ; Rev. | Date | Contents
|
|
871 ;------+----------+---------------------------------------------------------
|
|
872 ; 1.00 | 91/ 6/13 | Initial version.
|
|
873 ; | | Auto compilation & preview.
|
|
874 ; | | \section{}-type and \begin{}\end{}-type completion.
|
|
875 ; 1.01 | 91/ 6/14 | Add {\large ..} type completion (prefix+l).
|
|
876 ; 1.10 | 6/21 | Add learning feature of completion.
|
|
877 ; 1.11 | 6/27 | Simplify function begin-document etc. using lambda.
|
|
878 ; 1.12 | 7/ 6 | Modify YaTeX-make-section, show section-name.
|
|
879 ; 1.13 | 12/ 4 | Delete blank lines in make begin/end environment.
|
|
880 ; 1.20 | 12/ 5 | Saving learned completion into user file.
|
|
881 ; 1.21 | 12/ 6 | Add \maketitle type completion (prefix+m).
|
|
882 ; 1.22 | 12/30 | Port yatex.el to DOS(Demacs).
|
|
883 ; 1.23 | 92/ 1/ 8 | Enable latex and preview command on DOS.
|
|
884 ; 1.24 | 1/ 9 | Add YaTeX-save-table to kill-emacs-hook automatically.
|
|
885 ; 1.25 | 1/16 | YaTeX-do-completion (prefix+SPC) and argument
|
|
886 ; | | acceptable YaTeX-make-section work. Put region into
|
|
887 ; | | \begin...\end by calling YaTeX-make-begin-end with ARG.
|
|
888 ; | | append-kill-emacs-hook was revised to append-to-hook.
|
|
889 ; 1.26 | 1/18 | Region mode is added to {\large }. Default fontsize.
|
|
890 ; 1.27 | 1/21 | Default name on completing-read,
|
1
|
891 ; 1.28 | 7/ 2 | Add \nonstopmode{} automatically on DOS.
|
|
892 ; | 7/20 | %#! usage to specify latex command and its arguments.
|
0
|
893 ;------+----------+---------------------------------------------------------
|
|
894 ;
|
|
895 ;----------------------------- End of yatex.el -----------------------------
|