Mercurial > hgrepos > hgweb.cgi > yatex
annotate yatexprc.el @ 57:18f4939986e6
(j)LaTeX2e supported
yatex19.el fixed a lot
author | yuuji |
---|---|
date | Sat, 02 Dec 1995 18:35:28 +0000 |
parents | 5f4b18da14b3 |
children | 3a7c0c2bf16d |
rev | line source |
---|---|
51 | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX process handler. | |
3 ;;; yatexprc.el | |
52 | 4 ;;; (c )1993-1995 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp] |
57 | 5 ;;; Last modified Thu Nov 2 19:35:16 1995 on inspire |
51 | 6 ;;; $Id$ |
7 | |
8 (require 'yatex) | |
9 | |
10 (defvar YaTeX-typeset-process nil | |
11 "Process identifier for jlatex" | |
12 ) | |
13 (defvar YaTeX-typeset-buffer "*YaTeX-typesetting*" | |
14 "Process buffer for jlatex") | |
15 | |
16 (defvar YaTeX-typeset-buffer-syntax nil | |
17 "*Syntax table for typesetting buffer") | |
18 | |
19 (defvar YaTeX-current-TeX-buffer nil | |
20 "Keeps the buffer on which recently typeset run.") | |
21 | |
22 (defvar YaTeX-shell-command-option | |
23 (or (and (boundp 'shell-command-option) shell-command-option) | |
24 (if YaTeX-dos "/c" "-c")) | |
25 "Shell option for command execution.") | |
26 | |
27 (if YaTeX-typeset-buffer-syntax nil | |
28 (setq YaTeX-typeset-buffer-syntax | |
29 (make-syntax-table (standard-syntax-table))) | |
30 (modify-syntax-entry ?\{ "w" YaTeX-typeset-buffer-syntax) | |
31 (modify-syntax-entry ?\} "w" YaTeX-typeset-buffer-syntax) | |
32 (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax) | |
33 (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax) | |
34 ) | |
35 | |
36 (defun YaTeX-typeset (command buffer) | |
37 "Execute jlatex (or other) to LaTeX typeset." | |
38 (interactive) | |
39 (save-excursion | |
40 (let ((p (point)) (window (selected-window)) execdir (cb (current-buffer))) | |
41 (if (and YaTeX-typeset-process | |
42 (eq (process-status YaTeX-typeset-process) 'run)) | |
43 ;; if tex command is halting. | |
44 (YaTeX-kill-typeset-process YaTeX-typeset-process)) | |
45 (YaTeX-visit-main t) ;;execution directory | |
46 (setq execdir default-directory) | |
47 ;;Select lower-most window if there are more than 2 windows and | |
48 ;;typeset buffer not seen. | |
49 (YaTeX-showup-buffer | |
50 buffer (function (lambda (x) (nth 3 (window-edges x))))) | |
51 (set-buffer (get-buffer-create buffer)) | |
52 (setq default-directory execdir) | |
53 (cd execdir) | |
54 (erase-buffer) | |
55 (cond | |
56 (YaTeX-dos ;if MS-DOS | |
57 (YaTeX-put-nonstopmode) | |
58 (call-process | |
59 shell-file-name nil buffer nil YaTeX-shell-command-option command) | |
60 (YaTeX-remove-nonstopmode)) | |
61 (t ;if UNIX | |
62 (set-process-buffer | |
63 (setq YaTeX-typeset-process | |
64 (start-process "LaTeX" buffer shell-file-name | |
65 YaTeX-shell-command-option command)) | |
66 (get-buffer buffer)) | |
67 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel))) | |
68 (message (format "Calling `%s'..." command)) | |
69 (setq YaTeX-current-TeX-buffer (buffer-name)) | |
70 (use-local-map YaTeX-typesetting-mode-map) | |
71 (set-syntax-table YaTeX-typeset-buffer-syntax) | |
72 (setq mode-name "typeset") | |
73 (if YaTeX-typeset-process ; if process is running (maybe on UNIX) | |
74 (cond ((boundp 'MULE) | |
75 (set-current-process-coding-system | |
76 YaTeX-latex-message-code YaTeX-coding-system)) | |
77 ((boundp 'NEMACS) | |
78 (set-kanji-process-code YaTeX-latex-message-code)))) | |
79 (if YaTeX-dos (message "Done.") | |
80 (insert " ") | |
81 (set-marker (process-mark YaTeX-typeset-process) (1- (point)))) | |
82 (if (bolp) (forward-line -1)) ;what for? | |
83 (if (and YaTeX-emacs-19 window-system) | |
84 (let ((win (get-buffer-window buffer t)) owin) | |
85 (select-frame (window-frame win)) | |
86 (setq owin (selected-window)) | |
87 (select-window win) | |
88 (goto-char (point-max)) | |
89 (recenter -1) | |
90 (select-window owin)) | |
91 (select-window (get-buffer-window buffer)) | |
92 (goto-char (point-max)) | |
93 (recenter -1)) | |
94 (select-window window) | |
95 (switch-to-buffer cb))) | |
96 ) | |
97 | |
98 (defun YaTeX-typeset-sentinel (proc mes) | |
99 (cond ((null (buffer-name (process-buffer proc))) | |
100 ;; buffer killed | |
101 (set-process-buffer proc nil)) | |
102 ((memq (process-status proc) '(signal exit)) | |
103 (let* ((obuf (current-buffer)) (pbuf (process-buffer proc)) | |
104 (pwin (get-buffer-window pbuf)) | |
105 (owin (selected-window)) win) | |
106 ;; save-excursion isn't the right thing if | |
107 ;; process-buffer is current-buffer | |
108 (unwind-protect | |
109 (progn | |
110 ;; Write something in *typesetting* and hack its mode line | |
111 (if pwin | |
112 (select-window pwin) | |
113 (set-buffer pbuf)) | |
114 ;;(YaTeX-showup-buffer pbuf nil t) | |
115 (goto-char (point-max)) | |
116 (if pwin (recenter -3)) | |
117 (insert ?\n "latex typesetting " mes) | |
118 (forward-char -1) | |
119 (insert " at " (substring (current-time-string) 0 -5) "\n") | |
120 (forward-char 1) | |
121 (setq mode-line-process | |
122 (concat ": " | |
123 (symbol-name (process-status proc)))) | |
124 (message "latex typesetting %s." | |
125 (if (eq (process-status proc) 'exit) | |
126 "done" "ceased")) | |
127 ;; If buffer and mode line shows that the process | |
128 ;; is dead, we can delete it now. Otherwise it | |
129 ;; will stay around until M-x list-processes. | |
130 (delete-process proc) | |
131 ) | |
132 (setq YaTeX-typeset-process nil) | |
133 ;; Force mode line redisplay soon | |
134 (set-buffer-modified-p (buffer-modified-p)) | |
135 ) | |
136 (select-window owin) | |
137 (set-buffer obuf)))) | |
138 ) | |
139 | |
140 (defvar YaTeX-texput-file "texput.tex" | |
141 "*File name for temporary file of typeset-region." | |
142 ) | |
143 | |
144 (defun YaTeX-typeset-region () | |
52 | 145 "Paste the region to the file `texput.tex' and execute typesetter. |
146 The region is specified by the rule: | |
51 | 147 (1)If keyword `%#BEGIN' is found in the upper direction from (point). |
148 (1-1)if the keyword `%#END' is found after `%#BEGIN', | |
149 ->Assume the text between `%#BEGIN' and `%#END' as region. | |
150 (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN', | |
151 ->Assume the text after `%#BEGIN' as region. | |
152 (2)If no `%#BEGIN' usage is found before the (point), | |
153 ->Assume the text between current (point) and (mark) as region. | |
154 DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing | |
155 operation to the region." | |
156 (interactive) | |
157 (save-excursion | |
158 (let* | |
159 ((end "") typeout ;Type out message that tells the method of cutting. | |
160 (texput YaTeX-texput-file) | |
161 (cmd (concat (YaTeX-get-latex-command nil) " " texput)) | |
162 (buffer (current-buffer)) opoint preamble (subpreamble "") main | |
163 (hilit-auto-highlight nil) ;for Emacs19 with hilit19 | |
52 | 164 reg-begin reg-end lineinfo) |
51 | 165 |
166 (save-excursion | |
167 (if (search-backward "%#BEGIN" nil t) | |
168 (progn | |
169 (setq typeout "--- Region from BEGIN to " | |
170 end "the end of the buffer ---" | |
171 reg-begin (match-end 0)) | |
172 (if (search-forward "%#END" nil t) | |
173 (setq reg-end (match-beginning 0) | |
174 end "END ---") | |
175 (setq reg-end (point-max)))) | |
52 | 176 (setq typeout "=== Region from (point) to (mark) ===" |
177 reg-begin (point) reg-end (mark))) | |
178 (goto-char (min reg-begin reg-end)) | |
179 (setq lineinfo (count-lines (point-min) (point-end-of-line))) | |
51 | 180 (goto-char (point-min)) |
181 (while (search-forward "%#REQUIRE" nil t) | |
182 (setq subpreamble | |
183 (concat subpreamble | |
184 (cond | |
185 ((eolp) | |
186 (buffer-substring | |
187 (match-beginning 0) | |
188 (point-beginning-of-line))) | |
189 (t (buffer-substring | |
190 (match-end 0) | |
191 (point-end-of-line)))) | |
192 "\n")) | |
193 (goto-char (match-end 0)))) | |
194 (YaTeX-visit-main t) | |
195 (setq main (current-buffer)) | |
196 (setq opoint (point)) | |
197 (goto-char (point-min)) | |
198 (setq | |
199 preamble | |
200 (if (re-search-forward "^[ ]*\\\\begin.*{document}" nil t) | |
201 (buffer-substring (point-min) (match-end 0)) | |
202 (concat "\\documentstyle{" YaTeX-default-document-style "}\n" | |
203 "\\begin{document}"))) | |
204 (goto-char opoint) | |
205 ;;(set-buffer buffer) ;for clarity | |
52 | 206 (let ((hilit-auto-highlight nil)) |
207 (set-buffer (find-file-noselect texput))) | |
51 | 208 ;;(find-file YaTeX-texput-file) |
209 (erase-buffer) | |
210 (if YaTeX-need-nonstop | |
211 (insert "\\nonstopmode{}\n")) | |
212 (insert preamble "\n" subpreamble "\n") | |
52 | 213 (setq lineinfo (list (count-lines 1 (point-end-of-line)) lineinfo)) |
51 | 214 (insert-buffer-substring buffer reg-begin reg-end) |
215 (insert "\\typeout{" typeout end "}\n") ;Notice the selected method. | |
216 (insert "\n\\end{document}\n") | |
217 (basic-save-buffer) | |
218 (kill-buffer (current-buffer)) | |
219 (set-buffer main) ;return to parent file or itself. | |
220 (YaTeX-typeset cmd YaTeX-typeset-buffer) | |
221 (switch-to-buffer buffer) ;for Emacs-19 | |
52 | 222 (put 'dvi2-command 'region t) |
223 (put 'dvi2-command 'file buffer) | |
224 (put 'dvi2-command 'offset lineinfo) | |
225 )) | |
51 | 226 ) |
227 | |
228 (defun YaTeX-typeset-buffer () | |
229 "Typeset whole buffer. If %#! usage says other buffer is main text, | |
230 visit main buffer to confirm if its includeonly list contains current | |
231 buffer's file. And if it doesn't contain editing text, ask user which | |
232 action wants to be done, A:Add list, R:Replace list, %:comment-out list." | |
233 (interactive) | |
234 (YaTeX-save-buffers) | |
235 (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.))) | |
236 (mydir (file-name-directory (buffer-file-name))) | |
237 (cmd (YaTeX-get-latex-command t)) (cb (current-buffer))) | |
238 (if (YaTeX-main-file-p) nil | |
239 (save-excursion | |
240 (YaTeX-visit-main t) ;search into main buffer | |
241 (save-excursion | |
242 (push-mark (point) t) | |
243 (goto-char (point-min)) | |
244 (if (and (re-search-forward "^[ ]*\\\\begin{document}" nil t) | |
245 (re-search-backward "^[ ]*\\\\includeonly{" nil t)) | |
246 (let* | |
247 ((b (progn (skip-chars-forward "^{") (point))) | |
248 (e (progn (skip-chars-forward "^}") (1+ (point)))) | |
249 (s (buffer-substring b e)) c | |
250 (pardir (file-name-directory (buffer-file-name)))) | |
251 (if (string-match (concat "[{,/]" me "[,}]") s) | |
252 nil ; Nothing to do when it's already in includeonly. | |
253 (ding) | |
254 (switch-to-buffer (current-buffer));Display this buffer. | |
255 (setq | |
256 me ;;Rewrite my name(me) to contain sub directory name. | |
257 (concat | |
258 (if (string-match pardir mydir) ;if mydir is child of main | |
259 (substring mydir (length pardir)) ;cut absolute path | |
260 mydir) ;else concat absolute path name. | |
261 me)) | |
262 (message | |
263 "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? " | |
264 me) | |
265 (setq c (read-char)) | |
266 (cond | |
267 ((= c ?a) | |
268 (goto-char (1+ b)) | |
269 (insert me (if (string= s "{}") "" ","))) | |
270 ((= c ?r) | |
271 (delete-region (1+ b) (1- e)) (insert me)) | |
272 ((= c ?%) | |
273 (beginning-of-line) (insert "%")) | |
274 (t nil)) | |
275 (basic-save-buffer)))) | |
276 (exchange-point-and-mark))) | |
277 (switch-to-buffer cb)) ;for 19 | |
278 (YaTeX-typeset cmd YaTeX-typeset-buffer) | |
279 (put 'dvi2-command 'region nil)) | |
280 ) | |
281 | |
282 (defvar YaTeX-call-command-history nil | |
283 "Holds history list of YaTeX-call-command-on-file.") | |
284 (put 'YaTeX-call-command-history 'no-default t) | |
285 (defun YaTeX-call-command-on-file (base-cmd buffer) | |
286 (YaTeX-save-buffers) | |
287 (YaTeX-typeset | |
288 (read-string-with-history | |
289 "Call command: " | |
290 (concat base-cmd " " (YaTeX-get-preview-file-name)) | |
291 'YaTeX-call-command-history) | |
292 buffer) | |
293 ) | |
294 | |
295 (defun YaTeX-bibtex-buffer (cmd) | |
296 "Pass the bibliography data of editing file to bibtex." | |
297 (interactive) | |
298 (YaTeX-save-buffers) | |
299 (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" ) | |
300 ) | |
301 | |
302 (defun YaTeX-kill-typeset-process (proc) | |
303 "Kill process PROC after sending signal to PROC. | |
304 PROC should be process identifier." | |
305 (cond | |
306 (YaTeX-dos | |
307 (error "MS-DOS can't have concurrent process.")) | |
308 ((or (null proc) (not (eq (process-status proc) 'run))) | |
309 (message "Typesetting process is not running.")) | |
310 (t | |
311 (save-excursion | |
312 (set-buffer (process-buffer proc)) | |
313 (save-excursion | |
314 (goto-char (point-max)) | |
315 (beginning-of-line) | |
316 (if (looking-at "\\? +$") | |
317 (let ((mp (point-max))) | |
318 (process-send-string proc "x\n") | |
319 (while (= mp (point-max)) (sit-for 1)))))) | |
320 (if (eq (process-status proc) 'run) | |
321 (progn | |
322 (interrupt-process proc) | |
323 (delete-process proc))))) | |
324 ) | |
325 | |
326 (defun YaTeX-system (command buffer) | |
327 "Execute some command on buffer. Not a official function." | |
328 (save-excursion | |
329 (YaTeX-showup-buffer | |
330 buffer (function (lambda (x) (nth 3 (window-edges x))))) | |
331 (set-buffer (get-buffer-create buffer)) | |
332 (erase-buffer) | |
333 (if YaTeX-dos | |
334 (call-process | |
335 shell-file-name nil buffer nil YaTeX-shell-command-option command) | |
336 (set-process-buffer | |
337 (start-process | |
338 "system" buffer shell-file-name YaTeX-shell-command-option command) | |
339 (get-buffer buffer)))) | |
340 ) | |
341 | |
342 (defvar YaTeX-preview-command-history nil | |
343 "Holds minibuffer history of preview command.") | |
344 (put 'YaTeX-preview-command-history 'no-default t) | |
345 (defvar YaTeX-preview-file-history nil | |
346 "Holds minibuffer history of file to preview.") | |
347 (put 'YaTeX-preview-file-history 'no-default t) | |
348 (defun YaTeX-preview (preview-command preview-file) | |
349 "Execute xdvi (or other) to tex-preview." | |
350 (interactive | |
351 (list | |
352 (read-string-with-history | |
353 "Preview command: " dvi2-command 'YaTeX-preview-command-history) | |
354 (read-string-with-history | |
355 "Preview file[.dvi]: " | |
356 (if (get 'dvi2-command 'region) | |
357 (substring YaTeX-texput-file | |
358 0 (rindex YaTeX-texput-file ?.)) | |
359 (YaTeX-get-preview-file-name)) | |
360 'YaTeX-preview-file-history))) | |
361 (setq dvi2-command preview-command) ;`dvi2command' is buffer local | |
362 (save-excursion | |
363 (YaTeX-visit-main t) | |
364 (let ((pbuffer "*dvi-preview*") (dir default-directory)) | |
365 (YaTeX-showup-buffer | |
366 pbuffer (function (lambda (x) (nth 3 (window-edges x))))) | |
367 (set-buffer (get-buffer-create pbuffer)) | |
368 (erase-buffer) | |
369 (setq default-directory dir) ;for 18 | |
370 (cd dir) ;for 19 | |
371 (cond | |
372 (YaTeX-dos ;if MS-DOS | |
373 (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor | |
374 (call-process shell-file-name "con" "*dvi-preview*" nil | |
375 YaTeX-shell-command-option preview-command preview-file) | |
376 (send-string-to-terminal "\e[>5l") ;show cursor | |
377 (redraw-display)) | |
378 (t ;if UNIX | |
379 (set-process-buffer | |
380 (start-process "preview" "*dvi-preview*" shell-file-name | |
381 YaTeX-shell-command-option | |
382 (concat preview-command " " preview-file)) | |
383 (get-buffer pbuffer)) | |
384 (message | |
385 (concat "Starting " preview-command | |
386 " to preview " preview-file)))))) | |
387 ) | |
388 | |
52 | 389 (defun YaTeX-set-virtual-error-position (file-sym line-sym) |
390 "Replace the value of FILE-SYM, LINE-SYM by virtual error position." | |
391 (cond | |
392 ((and (get 'dvi2-command 'region) | |
393 (> (symbol-value line-sym) (car (get 'dvi2-command 'offset)))) | |
394 (set file-sym (get 'dvi2-command 'file)) | |
395 (set line-sym | |
396 (+ (- (apply '- (get 'dvi2-command 'offset))) | |
397 (symbol-value line-sym) | |
398 -1))))) | |
399 | |
51 | 400 (defun YaTeX-prev-error () |
401 "Visit previous typeset error. | |
402 To avoid making confliction of line numbers by editing, jump to | |
403 error or warning lines in reverse order." | |
404 (interactive) | |
405 (let ((cur-buf (buffer-name)) (cur-win (selected-window)) | |
406 error-line typeset-win error-buffer error-win) | |
407 (if (null (get-buffer YaTeX-typeset-buffer)) | |
408 (error "There is no typesetting buffer.")) | |
409 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t) | |
410 (setq typeset-win (selected-window)) | |
411 (if (re-search-backward | |
412 (concat "\\(" latex-error-regexp "\\)\\|\\(" | |
413 latex-warning-regexp "\\)") | |
414 nil t) | |
415 nil | |
416 (select-window cur-win) | |
417 (error "No more erros on %s" cur-buf)) | |
418 (goto-char (match-beginning 0)) | |
419 (skip-chars-forward "^0-9" (match-end 0)) | |
420 (setq error-line | |
421 (string-to-int | |
422 (buffer-substring | |
423 (point) | |
424 (progn (skip-chars-forward "0-9" (match-end 0)) (point)))) | |
52 | 425 error-buffer (YaTeX-get-error-file cur-buf)) |
51 | 426 (if (or (null error-line) (equal 0 error-line)) |
427 (error "Can't detect error position.")) | |
52 | 428 (YaTeX-set-virtual-error-position 'error-buffer 'error-line) |
429 (setq error-win (get-buffer-window error-buffer)) | |
51 | 430 (select-window cur-win) |
431 (cond | |
432 (error-win (select-window error-win)) | |
433 ((eq (get-lru-window) typeset-win) | |
434 (YaTeX-switch-to-buffer error-buffer)) | |
435 (t (select-window (get-lru-window)) | |
436 (YaTeX-switch-to-buffer error-buffer))) | |
437 (setq error-win (selected-window)) | |
438 (goto-line error-line) | |
439 (message "LaTeX %s in `%s' on line: %d." | |
440 (if (match-beginning 1) "error" "warning") | |
441 error-buffer error-line) | |
442 (select-window typeset-win) | |
443 (skip-chars-backward "0-9") | |
444 (recenter (/ (window-height) 2)) | |
445 (sit-for 3) | |
446 (goto-char (match-beginning 0)) | |
447 (select-window error-win)) | |
448 ) | |
449 | |
450 (defun YaTeX-jump-error-line () | |
451 "Jump to corresponding line on latex command's error message." | |
452 (interactive) | |
453 (let (error-line error-file error-buf) | |
454 (save-excursion | |
455 (beginning-of-line) | |
456 (setq error-line (re-search-forward "l[ ines]*\\.?\\([1-9][0-9]*\\)" | |
457 (point-end-of-line) t))) | |
458 (if (null error-line) | |
459 (if (eobp) (insert (this-command-keys)) | |
460 (error "No line number expression.")) | |
461 (goto-char (match-beginning 0)) | |
462 (setq error-line (string-to-int | |
463 (buffer-substring (match-beginning 1) (match-end 1))) | |
52 | 464 error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)) |
465 (YaTeX-set-virtual-error-position 'error-file 'error-line) | |
466 (setq error-buf (YaTeX-switch-to-buffer error-file t))) | |
51 | 467 (if (null error-buf) |
468 (error "`%s' is not found in this directory." error-file)) | |
469 (YaTeX-showup-buffer error-buf nil t) | |
52 | 470 (goto-line error-line)) |
51 | 471 ) |
472 | |
473 (defun YaTeX-send-string () | |
474 "Send string to current typeset process." | |
475 (interactive) | |
476 (if (and (eq (process-status YaTeX-typeset-process) 'run) | |
477 (>= (point) (process-mark YaTeX-typeset-process))) | |
478 (let ((b (process-mark YaTeX-typeset-process)) | |
479 (e (point-end-of-line))) | |
480 (goto-char b) | |
481 (skip-chars-forward " \t" e) | |
482 (setq b (point)) | |
483 (process-send-string | |
484 YaTeX-typeset-process (concat (buffer-substring b e) "\n")) | |
485 (goto-char e) | |
486 (insert "\n") | |
487 (set-marker (process-mark YaTeX-typeset-process) (point)) | |
488 (insert " ")) | |
489 (ding)) | |
490 ) | |
491 | |
492 (defun YaTeX-view-error () | |
493 (interactive) | |
494 (if (null (get-buffer YaTeX-typeset-buffer)) | |
495 (message "No typeset buffer found.") | |
496 (let ((win (selected-window))) | |
497 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t) | |
498 ;; Next 3 lines are obsolete because YaTeX-typesetting-buffer is | |
499 ;; automatically scrolled up at typesetting. | |
500 ;;(goto-char (point-max)) | |
501 ;;(forward-line -1) | |
502 ;;(recenter -1) | |
503 (select-window win))) | |
504 ) | |
505 | |
506 (defun YaTeX-get-error-file (default) | |
507 "Get current processing file from typesetting log." | |
508 (save-excursion | |
509 (let(s) | |
510 (condition-case () (up-list -1) | |
511 (error | |
512 (let ((list 0) found) | |
513 (while | |
514 (and (<= list 0) (not found) | |
515 (re-search-backward "\\((\\)\\|\\()\\)" nil t)) | |
516 (if (equal (match-beginning 0) (match-beginning 2)) ;close paren. | |
517 (setq list (1- list)) ;open paren | |
518 (setq list (1+ list)) | |
519 (if (= list 1) | |
520 (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty") | |
521 (setq found t) | |
522 (setq list (1- list))))))))) | |
523 (setq s | |
524 (buffer-substring | |
525 (progn (forward-char 1) (point)) | |
526 (progn (skip-chars-forward "^ \n" (point-end-of-line)) | |
527 (point)))) | |
528 (if (string= "" s) default s))) | |
529 ) | |
530 | |
531 (defun YaTeX-put-nonstopmode () | |
532 (if YaTeX-need-nonstop | |
533 (if (re-search-backward "\\\\nonstopmode{}" (point-min) t) | |
534 nil ;if already written in text then do nothing | |
535 (save-excursion | |
536 (YaTeX-visit-main t) | |
537 (goto-char (point-min)) | |
538 (insert "\\nonstopmode{}%_YaTeX_%\n"))) | |
539 ) | |
540 ) | |
541 | |
542 (defun YaTeX-remove-nonstopmode () | |
543 (if YaTeX-need-nonstop ;for speed | |
544 (save-excursion | |
545 (YaTeX-visit-main t) | |
546 (goto-char (point-min)) | |
547 (forward-line 1) | |
548 (narrow-to-region (point-min) (point)) | |
549 (goto-char (point-min)) | |
550 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$") | |
551 (widen))) | |
552 ) | |
553 | |
554 (defun YaTeX-get-preview-file-name () | |
555 "Get file name to preview by inquiring YaTeX-get-latex-command" | |
556 (let* ((latex-cmd (YaTeX-get-latex-command t)) | |
557 (rin (rindex latex-cmd ? )) | |
558 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) "")) | |
559 (period)) | |
560 (if (string= fname "") | |
561 (setq fname (substring (file-name-nondirectory | |
562 (buffer-file-name)) | |
563 0 -4)) | |
564 (setq period (rindex fname ?.)) | |
565 (setq fname (substring fname 0 (if (eq -1 period) nil period))) | |
566 )) | |
567 ) | |
568 | |
569 (defun YaTeX-get-latex-command (&optional switch) | |
570 "Specify the latex-command name and its argument. | |
571 If there is a line which begins with string: \"%#!\", the following | |
572 strings are assumed to be the latex-command and arguments. The | |
573 default value of latex-command is: | |
574 tex-command FileName | |
575 and if you write \"%#!jlatex\" in the beginning of certain line. | |
576 \"jlatex \" FileName | |
577 will be the latex-command, | |
578 and you write \"%#!jlatex main.tex\" on some line and argument SWITCH | |
579 is non-nil, then | |
580 \"jlatex main.tex\" | |
581 | |
582 will be given to the shell." | |
583 (let (magic command target) | |
584 (setq parent | |
585 (cond | |
586 (YaTeX-parent-file YaTeX-parent-file) | |
587 (t (save-excursion | |
588 (YaTeX-visit-main t) | |
589 (file-name-nondirectory (buffer-file-name))))) | |
590 magic (YaTeX-get-builtin "!")) | |
591 (cond | |
592 (magic | |
593 (cond | |
594 (switch (if (string-match "\\s " magic) magic | |
595 (concat magic " " parent))) | |
596 (t (concat (substring magic 0 (string-match "\\s " magic)) " ")))) | |
597 (t (concat tex-command " " (if switch parent))))) | |
598 ) | |
599 | |
600 (defvar YaTeX-lpr-command-history nil | |
601 "Holds command line history of YaTeX-lpr.") | |
602 (put 'YaTeX-lpr-command-history 'no-default t) | |
603 (defun YaTeX-lpr (arg) | |
604 "Print out. If prefix arg ARG is non nil, call print driver without | |
605 page range description." | |
606 (interactive "P") | |
607 (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)) | |
52 | 608 from to (lbuffer "*dvi-printing*") dir) |
51 | 609 (setq |
610 cmd | |
611 (YaTeX-replace-format | |
612 cmd "f" | |
613 (if (or arg (not (string-match "%f" cmd))) | |
614 "" | |
615 (YaTeX-replace-format | |
616 dviprint-from-format | |
617 "b" | |
618 (if (string= | |
619 (setq from (read-string "From page(default 1): ")) "") | |
620 "1" from)))) | |
621 ) | |
622 (setq | |
623 cmd | |
624 (YaTeX-replace-format | |
625 cmd "t" | |
626 (if (or arg (not (string-match "%t" cmd)) | |
627 (string= | |
628 (setq to (read-string "To page(default none): ")) "")) | |
629 "" | |
630 (YaTeX-replace-format dviprint-to-format "e" to))) | |
631 ) | |
632 (setq cmd | |
633 (read-string-with-history | |
634 "Edit command line: " | |
53
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
635 (format cmd |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
636 (if (get 'dvi2-command 'region) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
637 (substring YaTeX-texput-file |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
638 0 (rindex YaTeX-texput-file ?.)) |
5f4b18da14b3
Fix functions relating YaTeX-beginning-of-environment or
yuuji
parents:
52
diff
changeset
|
639 (YaTeX-get-preview-file-name))) |
51 | 640 'YaTeX-lpr-command-history)) |
641 (save-excursion | |
642 (YaTeX-visit-main t) ;;change execution directory | |
52 | 643 (setq dir default-directory) |
51 | 644 (YaTeX-showup-buffer |
645 lbuffer (function (lambda (x) (nth 3 (window-edges x))))) | |
646 (set-buffer (get-buffer-create lbuffer)) | |
647 (erase-buffer) | |
52 | 648 (cd dir) ;for 19 |
51 | 649 (cond |
650 (YaTeX-dos | |
651 (call-process shell-file-name "con" "*dvi-printing*" nil | |
652 YaTeX-shell-command-option cmd)) | |
653 (t | |
654 (set-process-buffer | |
655 (start-process "print" "*dvi-printing*" shell-file-name | |
656 YaTeX-shell-command-option cmd) | |
657 (get-buffer lbuffer)) | |
658 (message "Starting printing command: %s..." cmd))) | |
659 )) | |
660 ) | |
661 | |
662 (defun YaTeX-main-file-p () | |
663 "Return if current buffer is main LaTeX source." | |
664 (cond | |
52 | 665 (YaTeX-parent-file |
666 (eq (get-file-buffer YaTeX-parent-file) (current-buffer))) | |
51 | 667 ((YaTeX-get-builtin "!") |
668 (string-match (YaTeX-guess-parent (YaTeX-get-builtin "!")) (buffer-name))) | |
669 (t | |
670 (save-excursion | |
57 | 671 (let ((latex-main-id |
672 (concat "^\\s *" YaTeX-ec-regexp "document\\(style\\|class\\)"))) | |
51 | 673 (or (re-search-backward latex-main-id nil t) |
674 (re-search-forward latex-main-id nil t)))))) | |
675 ) | |
676 | |
677 (defun YaTeX-visit-main (&optional setbuf) | |
678 "Switch buffer to main LaTeX source. | |
679 Use set-buffer instead of switch-to-buffer if the optional second argument | |
680 SETBUF is t(Use it only from Emacs-Lisp program)." | |
681 (interactive "P") | |
682 (if (and (interactive-p) setbuf) (setq YaTeX-parent-file nil)) | |
683 (let (b-in main-file) | |
684 (if (setq b-in (YaTeX-get-builtin "!")) | |
685 (setq main-file (YaTeX-guess-parent b-in))) | |
686 (if YaTeX-parent-file | |
687 (setq main-file ;;(get-file-buffer YaTeX-parent-file) | |
688 YaTeX-parent-file)) | |
689 (if (YaTeX-main-file-p) | |
690 (if (interactive-p) (message "I think this is main LaTeX source.") nil) | |
691 (cond | |
692 ((and (interactive-p) main-file (get-file-buffer main-file)) | |
693 (goto-buffer-window main-file)) | |
694 ((and main-file (YaTeX-switch-to-buffer main-file setbuf))) | |
695 ((and main-file | |
696 (file-exists-p (setq main-file (concat "../" main-file))) | |
697 (y-or-n-p (concat (expand-file-name main-file) | |
698 " is main file?:"))) | |
699 (setq YaTeX-parent-file main-file) | |
700 (YaTeX-switch-to-buffer main-file setbuf)) | |
701 (t (setq main-file (read-file-name "Enter your main text: " nil nil 1)) | |
702 (setq YaTeX-parent-file main-file) | |
703 (YaTeX-switch-to-buffer main-file setbuf)) | |
704 ))) | |
705 nil | |
706 ) | |
707 | |
708 | |
709 (defun YaTeX-guess-parent (command-line) | |
710 (setq command-line | |
711 (if (string-match ".*\\s " command-line) | |
712 (substring command-line (match-end 0)) | |
713 (file-name-nondirectory (buffer-file-name))) | |
714 command-line | |
715 (concat (if (string-match "\\(.*\\)\\." command-line) | |
716 (substring command-line (match-beginning 1) (match-end 1)) | |
717 command-line) | |
718 ".tex")) | |
719 ) | |
720 | |
721 (defun YaTeX-visit-main-other-window () | |
722 "Switch to buffer main LaTeX source in other window." | |
723 (interactive) | |
724 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.") | |
725 (YaTeX-switch-to-buffer-other-window | |
726 (concat (YaTeX-get-preview-file-name) ".tex"))) | |
727 ) | |
728 | |
729 (defun YaTeX-get-builtin (key) | |
730 "Read source built-in command of %# usage." | |
731 (save-excursion | |
732 (goto-char (point-min)) | |
733 (if (and (re-search-forward | |
734 (concat "^" (regexp-quote (concat "%#" key))) nil t) | |
735 (not (eolp))) | |
736 (buffer-substring | |
737 (progn (skip-chars-forward " " (point-end-of-line))(point)) | |
738 (point-end-of-line)) | |
739 nil)) | |
740 ) | |
741 | |
742 (defun YaTeX-save-buffers () | |
743 "Save buffers which is in yatex-mode." | |
744 (basic-save-buffer) | |
745 (save-excursion | |
746 (mapcar '(lambda (buf) | |
747 (set-buffer buf) | |
748 (if (and (buffer-file-name buf) | |
749 (eq major-mode 'yatex-mode) | |
750 (buffer-modified-p buf) | |
751 (y-or-n-p (format "Save %s" (buffer-name buf)))) | |
752 (save-buffer buf))) | |
753 (buffer-list))) | |
754 ) | |
755 | |
756 (provide 'yatexprc) |