yatex

view yatexprc.el @ 49:eb0512bfcb7f

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