yatex

view yatex.el @ 0:9c72144baf95

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