yatex

view yatexprc.el @ 34:c61405ef1bd1

Change the message of dictionary selection menu.
author yuuji
date Wed, 13 Jul 1994 16:11:27 +0000
parents b00c74813e56
children 1ce952ad9c24
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 Sat Jul 9 18:24:42 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 (if (search-backward "%#BEGIN" nil t)
141 (progn
142 (setq typeout "--- Region from BEGIN to "
143 end "the end of the buffer ---"
144 reg-begin (match-end 0))
145 (if (search-forward "%#END" nil t)
146 (setq reg-end (match-beginning 0)
147 end "END ---")
148 (setq reg-end (point-max))))
149 (setq typeout "=== Region from (point) to (mark) ===")
150 (setq reg-begin (point) reg-end (mark)))
151 (goto-char (point-min))
152 (while (search-forward "%#REQUIRE" nil t)
153 (setq subpreamble
154 (concat subpreamble
155 (cond
156 ((eolp)
157 (buffer-substring
158 (match-beginning 0)
159 (point-beginning-of-line)))
160 (t (buffer-substring
161 (match-end 0)
162 (point-end-of-line))))
163 "\n"))
164 (goto-char (match-end 0)))
165 (YaTeX-visit-main t)
166 (setq main (current-buffer))
167 (setq opoint (point))
168 (goto-char (point-min))
169 (setq
170 preamble
171 (if (re-search-forward "^[ ]*\\\\begin.*{document}" nil t)
172 (buffer-substring (point-min) (match-end 0))
173 (concat "\\documentstyle{" YaTeX-default-document-style "}\n"
174 "\\begin{document}")))
175 (goto-char opoint)
176 ;;(set-buffer buffer) ;for clarity
177 (set-buffer (find-file-noselect YaTeX-texput-file))
178 ;;(find-file YaTeX-texput-file)
179 (erase-buffer)
180 (if YaTeX-need-nonstop
181 (insert "\\nonstopmode{}\n"))
182 (insert preamble "\n" subpreamble "\n")
183 (insert-buffer-substring buffer reg-begin reg-end)
184 (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
185 (insert "\n\\end{document}\n")
186 (basic-save-buffer)
187 (kill-buffer (current-buffer))
188 (set-buffer main) ;return to parent file or itself.
189 (YaTeX-typeset cmd YaTeX-typeset-buffer)
190 (put 'dvi2-command 'region t)))
191 )
193 (defun YaTeX-typeset-buffer ()
194 "Typeset whole buffer. If %#! usage says other buffer is main text,
195 visit main buffer to confirm if its includeonly list contains current
196 buffer's file. And if it doesn't contain editing text, ask user which
197 action wants to be done, A:Add list, R:Replace list, %:comment-out list."
198 (interactive)
199 (YaTeX-save-buffers)
200 (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.)))
201 (mydir (file-name-directory (buffer-file-name)))
202 (cmd (YaTeX-get-latex-command t)))
203 (if (YaTeX-main-file-p) nil
204 (save-excursion
205 (YaTeX-visit-main t) ;search into main buffer
206 (save-excursion
207 (push-mark (point) t)
208 (goto-char (point-min))
209 (if (and (re-search-forward "^[ ]*\\\\begin{document}" nil t)
210 (re-search-backward "^[ ]*\\\\includeonly{" nil t))
211 (let*
212 ((b (progn (skip-chars-forward "^{") (point)))
213 (e (progn (skip-chars-forward "^}") (1+ (point))))
214 (s (buffer-substring b e)) c
215 (pardir (file-name-directory (buffer-file-name))))
216 (if (string-match (concat "[{,/]" me "[,}]") s)
217 nil ; Nothing to do when it's already in includeonly.
218 (ding)
219 (switch-to-buffer (current-buffer));Display this buffer.
220 (setq
221 me ;;Rewrite my name(me) to contain sub directory name.
222 (concat
223 (if (string-match pardir mydir) ;if mydir is child of main
224 (substring mydir (length pardir)) ;cut absolute path
225 mydir) ;else concat absolute path name.
226 me))
227 (message
228 "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? "
229 me)
230 (setq c (read-char))
231 (cond
232 ((= c ?a)
233 (goto-char (1+ b))
234 (insert me (if (string= s "{}") "" ",")))
235 ((= c ?r)
236 (delete-region (1+ b) (1- e)) (insert me))
237 ((= c ?%)
238 (beginning-of-line) (insert "%"))
239 (t nil))
240 (basic-save-buffer))))
241 (exchange-point-and-mark))
242 ))
243 (YaTeX-typeset cmd YaTeX-typeset-buffer)
244 (put 'dvi2-command 'region nil))
245 )
247 (defvar YaTeX-call-command-history nil
248 "Holds history list of YaTeX-call-command-on-file.")
249 (put 'YaTeX-call-command-history 'no-default t)
250 (defun YaTeX-call-command-on-file (base-cmd buffer)
251 (YaTeX-save-buffers)
252 (YaTeX-typeset
253 (let ((minibufer-history-symbol 'YaTeX-call-command-history))
254 (read-string "Call command: "
255 (concat base-cmd " " (YaTeX-get-preview-file-name))))
256 buffer)
257 )
259 (defun YaTeX-bibtex-buffer (cmd)
260 "Pass the bibliography data of editing file to bibtex."
261 (interactive)
262 (YaTeX-save-buffers)
263 (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" )
264 )
266 (defun YaTeX-kill-typeset-process (proc)
267 "Kill process PROC after sending signal to PROC.
268 PROC should be process identifier."
269 (cond
270 (YaTeX-dos
271 (error "MS-DOS can't have concurrent process."))
272 ((or (null proc) (not (eq (process-status proc) 'run)))
273 (error "No typesetting process."))
274 (t (interrupt-process proc)
275 (delete-process proc)))
276 )
278 (defun YaTeX-system (command buffer)
279 "Execute some command on buffer. Not a official function."
280 (save-excursion
281 (YaTeX-showup-buffer
282 buffer (function (lambda (x) (nth 3 (window-edges x)))))
283 (with-output-to-temp-buffer buffer
284 (if YaTeX-dos
285 (call-process shell-file-name nil buffer nil "/c " command)
286 (start-process "system" buffer shell-file-name "-c" command))))
287 )
289 (defvar YaTeX-preview-command-history nil
290 "Holds minibuffer history of preview command.")
291 (put 'YaTeX-preview-command-history 'no-default t)
292 (defvar YaTeX-preview-file-history nil
293 "Holds minibuffer history of file to preview.")
294 (put 'YaTeX-preview-file-history 'no-default t)
295 (defun YaTeX-preview (preview-command preview-file)
296 "Execute xdvi (or other) to tex-preview."
297 (interactive
298 (list
299 (let ((minibuffer-history-symbol 'YaTeX-preview-command-history))
300 (read-string "Preview command: " dvi2-command))
301 (let ((minibuffer-history-symbol 'YaTeX-preview-file-history))
302 (read-string "Preview file[.dvi]: "
303 (if (get 'dvi2-command 'region)
304 (substring YaTeX-texput-file
305 0 (rindex YaTeX-texput-file ?.))
306 (YaTeX-get-preview-file-name))
307 ))))
308 (setq dvi2-command preview-command) ;`dvi2command' is buffer local
309 (save-excursion
310 (YaTeX-visit-main t)
311 (let ((pbuffer "*dvi-preview*"))
312 (YaTeX-showup-buffer
313 pbuffer (function (lambda (x) (nth 3 (window-edges x)))))
314 (with-output-to-temp-buffer pbuffer
315 (if YaTeX-dos ;if MS-DOS
316 (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
317 (call-process shell-file-name "con" "*dvi-preview*" nil
318 "/c " preview-command preview-file)
319 (send-string-to-terminal "\e[>5l") ;show cursor
320 (redraw-display))
321 (start-process "preview" "*dvi-preview*" shell-file-name "-c"
322 (concat preview-command " " preview-file)) ;if UNIX
323 (message
324 (concat "Starting " preview-command
325 " to preview " preview-file))))))
326 )
328 (defun YaTeX-prev-error ()
329 "Visit previous typeset error.
330 To avoid making confliction of line numbers by editing, jump to
331 error or warning lines in reverse order."
332 (interactive)
333 (let ((cur-buf (buffer-name)) (cur-win (selected-window))
334 error-line typeset-win error-buffer error-win)
335 (if (null (get-buffer YaTeX-typeset-buffer))
336 (error "There is no typesetting buffer."))
337 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
338 (setq typeset-win (selected-window))
339 (if (re-search-backward
340 (concat "\\(" latex-error-regexp "\\)\\|\\("
341 latex-warning-regexp "\\)")
342 nil t)
343 nil
344 (select-window cur-win)
345 (error "No more erros on %s" cur-buf))
346 (goto-char (match-beginning 0))
347 (skip-chars-forward "^0-9" (match-end 0))
348 (setq error-line
349 (string-to-int
350 (buffer-substring
351 (point)
352 (progn (skip-chars-forward "0-9" (match-end 0)) (point))))
353 error-buffer (YaTeX-get-error-file cur-buf)
354 error-win (get-buffer-window error-buffer))
355 (if (or (null error-line) (equal 0 error-line))
356 (error "Can't detect error position."))
357 (select-window cur-win)
358 (cond
359 (error-win (select-window error-win))
360 ((eq (get-lru-window) typeset-win)
361 (YaTeX-switch-to-buffer error-buffer))
362 (t (select-window (get-lru-window))
363 (YaTeX-switch-to-buffer error-buffer)))
364 (setq error-win (selected-window))
365 (goto-line error-line)
366 (message "LaTeX %s in `%s' on line: %d."
367 (if (match-beginning 1) "error" "warning")
368 error-buffer error-line)
369 (select-window typeset-win)
370 (skip-chars-backward "0-9")
371 (recenter (/ (window-height) 2))
372 (sit-for 3)
373 (goto-char (match-beginning 0))
374 (select-window error-win))
375 )
377 (defun YaTeX-jump-error-line ()
378 "Jump to corresponding line on latex command's error message."
379 (interactive)
380 (let (error-line error-file error-buf)
381 (save-excursion
382 (beginning-of-line)
383 (setq error-line (re-search-forward "l[ ines]*\\.\\([1-9][0-9]*\\)"
384 (point-end-of-line) t)))
385 (if (null error-line)
386 (if (eobp) (insert (this-command-keys))
387 (error "No line number expression."))
388 (goto-char (match-beginning 0))
389 (setq error-line (string-to-int
390 (buffer-substring (match-beginning 1) (match-end 1)))
391 error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)
392 error-buf (YaTeX-switch-to-buffer error-file t))
393 (if (null error-buf)
394 (error "`%s' is not found in this directory." error-file))
395 (YaTeX-showup-buffer error-buf nil t)
396 (goto-line error-line)))
397 )
399 (defun YaTeX-send-string ()
400 "Send string to current typeset process."
401 (interactive)
402 (if (and (eq (process-status YaTeX-typeset-process) 'run)
403 (>= (point) (process-mark YaTeX-typeset-process)))
404 (let ((b (process-mark YaTeX-typeset-process))
405 (e (point-end-of-line)))
406 (goto-char b)
407 (skip-chars-forward " \t" e)
408 (setq b (point))
409 (process-send-string
410 YaTeX-typeset-process (concat (buffer-substring b e) "\n"))
411 (goto-char e)
412 (insert "\n")
413 (set-marker (process-mark YaTeX-typeset-process) (point))
414 (insert " "))
415 (ding))
416 )
418 (defun YaTeX-view-error ()
419 (interactive)
420 (if (null (get-buffer YaTeX-typeset-buffer))
421 (message "No typeset buffer found.")
422 (let ((win (selected-window)))
423 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
424 (goto-char (point-max))
425 (forward-line -1)
426 (recenter -1)
427 (select-window win)))
428 )
430 (defun YaTeX-get-error-file (default)
431 "Get current processing file from typesetting log."
432 (save-excursion
433 (let(s)
434 (condition-case () (up-list -1)
435 (error
436 (let ((list 0) found)
437 (while
438 (and (<= list 0) (not found)
439 (re-search-backward "\\((\\)\\|\\()\\)" nil t))
440 (if (equal (match-beginning 0) (match-beginning 2)) ;close paren.
441 (setq list (1- list)) ;open paren
442 (setq list (1+ list))
443 (if (= list 1)
444 (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty")
445 (setq found t)
446 (setq list (1- list)))))))))
447 (setq s
448 (buffer-substring
449 (progn (forward-char 1) (point))
450 (progn (skip-chars-forward "-A-Za-z0-9_/\.\\" (point-end-of-line))
451 (point))))
452 (if (string= "" s) default s)))
453 )
455 (defun YaTeX-put-nonstopmode ()
456 (if YaTeX-need-nonstop
457 (if (re-search-backward "\\\\nonstopmode{}" (point-min) t)
458 nil ;if already written in text then do nothing
459 (save-excursion
460 (YaTeX-visit-main t)
461 (goto-char (point-min))
462 (insert "\\nonstopmode{}%_YaTeX_%\n")))
463 )
464 )
466 (defun YaTeX-remove-nonstopmode ()
467 (if YaTeX-need-nonstop ;for speed
468 (save-excursion
469 (YaTeX-visit-main t)
470 (goto-char (point-min))
471 (forward-line 1)
472 (narrow-to-region (point-min) (point))
473 (goto-char (point-min))
474 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$")
475 (widen)))
476 )
478 (defun YaTeX-get-preview-file-name ()
479 "Get file name to preview by inquiring YaTeX-get-latex-command"
480 (let* ((latex-cmd (YaTeX-get-latex-command t))
481 (rin (rindex latex-cmd ? ))
482 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
483 (period))
484 (if (string= fname "")
485 (setq fname (substring (file-name-nondirectory
486 (buffer-file-name))
487 0 -4))
488 (setq period (rindex fname ?.))
489 (setq fname (substring fname 0 (if (eq -1 period) nil period)))
490 ))
491 )
493 (defun YaTeX-get-latex-command (&optional switch)
494 "Specify the latex-command name and its argument.
495 If there is a line which begins with string: \"%#!\", the following
496 strings are assumed to be the latex-command and arguments. The
497 default value of latex-command is:
498 tex-command FileName
499 and if you write \"%#!jlatex\" in the beginning of certain line.
500 \"jlatex \" FileName
501 will be the latex-command,
502 and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
503 is non-nil, then
504 \"jlatex main.tex\"
506 will be given to the shell."
507 (let (magic command target)
508 (setq parent
509 (cond
510 (YaTeX-parent-file YaTeX-parent-file)
511 (t (save-excursion
512 (YaTeX-visit-main t)
513 (file-name-nondirectory (buffer-file-name)))))
514 magic (YaTeX-get-builtin "!"))
515 (cond
516 (magic
517 (cond
518 (switch (if (string-match "\\s " magic) magic
519 (concat magic " " parent)))
520 (t (concat (substring magic 0 (string-match "\\s " magic)) " "))))
521 (t (concat tex-command " " (if switch parent)))))
522 )
524 (defvar YaTeX-lpr-command-history nil
525 "Holds command line history of YaTeX-lpr.")
526 (put 'YaTeX-lpr-command-history 'no-default t)
527 (defun YaTeX-lpr (arg)
528 "Print out. If prefix arg ARG is non nil, call print driver without
529 page range description."
530 (interactive "P")
531 (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format))
532 from to (lbuffer "*dvi-printing*"))
533 (setq
534 cmd
535 (YaTeX-replace-format
536 cmd "f"
537 (if (or arg (not (string-match "%f" cmd)))
538 ""
539 (YaTeX-replace-format
540 dviprint-from-format
541 "b"
542 (if (string=
543 (setq from (read-string "From page(default 1): ")) "")
544 "1" from))))
545 )
546 (setq
547 cmd
548 (YaTeX-replace-format
549 cmd "t"
550 (if (or arg (not (string-match "%t" cmd))
551 (string=
552 (setq to (read-string "To page(default none): ")) ""))
553 ""
554 (YaTeX-replace-format dviprint-to-format "e" to)))
555 )
556 (setq cmd
557 (let ((minibuffer-history-symbol 'YaTeX-lpr-command-history))
558 (read-string "Edit command line: "
559 (format cmd (YaTeX-get-preview-file-name)))))
560 (save-excursion
561 (YaTeX-visit-main t) ;;change execution directory
562 (YaTeX-showup-buffer
563 lbuffer (function (lambda (x) (nth 3 (window-edges x)))))
564 (with-output-to-temp-buffer lbuffer
565 (if YaTeX-dos
566 (call-process shell-file-name "con" "*dvi-printing*" nil
567 "/c " cmd)
568 (start-process "print" "*dvi-printing*" shell-file-name "-c" cmd)
569 (message (concat "Starting " cmd " to printing "
570 (YaTeX-get-preview-file-name))))
571 )))
572 )
574 (defun YaTeX-main-file-p ()
575 "Return if current buffer is main LaTeX source."
576 (cond
577 ((YaTeX-get-builtin "!")
578 (string-match (YaTeX-guess-parent (YaTeX-get-builtin "!")) (buffer-name)))
579 (t
580 (save-excursion
581 (let ((latex-main-id (concat "^\\s *" YaTeX-ec-regexp "documentstyle")))
582 (or (re-search-backward latex-main-id nil t)
583 (re-search-forward latex-main-id nil t))))))
584 )
586 (defun YaTeX-visit-main (&optional setbuf)
587 "Switch buffer to main LaTeX source.
588 Use set-buffer instead of switch-to-buffer if the optional second argument
589 SETBUF is t(Use it only from Emacs-Lisp program)."
590 (interactive)
591 (let (b-in main-file)
592 (if (setq b-in (YaTeX-get-builtin "!"))
593 (setq main-file (YaTeX-guess-parent b-in)))
594 (if YaTeX-parent-file
595 (setq main-file ;;(get-file-buffer YaTeX-parent-file)
596 YaTeX-parent-file))
597 (if (YaTeX-main-file-p)
598 (if (interactive-p) (message "I think this is main LaTeX source.") nil)
599 (cond
600 ((and (interactive-p) main-file (get-buffer-window main-file))
601 (select-window (get-buffer-window main-file)))
602 ((and main-file (YaTeX-switch-to-buffer main-file setbuf)))
603 ((and main-file
604 (file-exists-p (setq main-file (concat "../" main-file)))
605 (y-or-n-p (concat (expand-file-name main-file)
606 " is main file?:")))
607 (YaTeX-switch-to-buffer main-file setbuf))
608 (t (setq main-file (read-file-name "Enter your main text: " nil nil 1))
609 (setq YaTeX-parent-file main-file)
610 (find-file main-file))
611 )))
612 nil
613 )
616 (defun YaTeX-guess-parent (command-line)
617 (setq command-line
618 (if (string-match ".*\\s " command-line)
619 (substring command-line (match-end 0))
620 (file-name-nondirectory (buffer-file-name)))
621 command-line
622 (concat (if (string-match "\\(.*\\)\\." command-line)
623 (substring command-line (match-beginning 1) (match-end 1))
624 command-line)
625 ".tex"))
626 )
628 (defun YaTeX-visit-main-other-window ()
629 "Switch to buffer main LaTeX source in other window."
630 (interactive)
631 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
632 (YaTeX-switch-to-buffer-other-window
633 (concat (YaTeX-get-preview-file-name) ".tex")))
634 )
636 (defun YaTeX-get-builtin (key)
637 "Read source built-in command of %# usage."
638 (save-excursion
639 (goto-char (point-min))
640 (if (and (re-search-forward
641 (concat "^" (regexp-quote (concat "%#" key))) nil t)
642 (not (eolp)))
643 (buffer-substring
644 (progn (skip-chars-forward " " (point-end-of-line))(point))
645 (point-end-of-line))
646 nil))
647 )
649 (defun YaTeX-save-buffers ()
650 "Save buffers which is in yatex-mode."
651 (basic-save-buffer)
652 (save-excursion
653 (mapcar '(lambda (buf)
654 (set-buffer buf)
655 (if (and (buffer-file-name buf)
656 (eq major-mode 'yatex-mode)
657 (buffer-modified-p buf)
658 (y-or-n-p (format "Save %s" (buffer-name buf))))
659 (save-buffer buf)))
660 (buffer-list)))
661 )
663 (provide 'yatexprc)