yatex

view yatexprc.el @ 46:cd1b63102eed

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