yatex

view yatexprc.el @ 15:cd762e854337

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