yatex

view yatexprc.el @ 12:a7f397790cdc

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