yatex

view yatexprc.el @ 14:b7b023a74293

Region-based section-type completion. Kill section-type command and parens (sometimes with font) with [prefix] k. Rewrite error-jump functions. Fix the bug of recursive section-type completion.
author yuuji
date Fri, 22 Apr 1994 17:35:25 +0000
parents eafae54794a0
children cd762e854337
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 Apr 23 02:34:07 1994 on pajero
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\"
467 will be given to the shell."
468 (let*((target (file-name-nondirectory
469 (or YaTeX-parent-file
470 (save-excursion
471 (YaTeX-visit-main t)
472 (buffer-file-name)))))
473 (default-command
474 (concat tex-command " " (if switch target ""))));default value
475 (save-excursion
476 (goto-char (point-min))
477 (if (null (re-search-forward "^%#!" (point-max) t))
478 default-command
479 (skip-chars-forward "%#! ")
480 (if (eolp)
481 default-command
482 (let ((s (point)))
483 (skip-chars-forward "^ " (point-end-of-line)) ;Skip command
484 (skip-chars-forward " " (point-end-of-line))
485 (cond
486 ((null switch)
487 (buffer-substring s (point)))
488 ((eolp) ;Only return command name
489 (concat (buffer-substring s (point)) " "
490 (file-name-nondirectory
491 (or YaTeX-parent-file (buffer-file-name)))))
492 (t(end-of-line) ;Change entire command name
493 (buffer-substring s (point))) ;including arguments.
494 ))))))
495 )
497 (defun YaTeX-lpr (arg)
498 "Print out. If prefix arg ARG is non nil, call print driver without
499 page range description."
500 (interactive "P")
501 (let*(from to (cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)))
502 (setq
503 cmd
504 (YaTeX-replace-format
505 cmd "f"
506 (if (or arg (not (string-match "%f" cmd)))
507 ""
508 (YaTeX-replace-format
509 dviprint-from-format
510 "b"
511 (if (string=
512 (setq from (read-string "From page(default 1): ")) "")
513 "1" from))))
514 )
515 (setq
516 cmd
517 (YaTeX-replace-format
518 cmd "t"
519 (if (or arg (not (string-match "%t" cmd))
520 (string=
521 (setq to (read-string "To page(default none): ")) ""))
522 ""
523 (YaTeX-replace-format dviprint-to-format "e" to)))
524 )
525 (setq cmd (read-string "Edit command line: "
526 (format cmd (YaTeX-get-preview-file-name))))
527 (save-excursion
528 (YaTeX-visit-main t) ;;change execution directory
529 (with-output-to-temp-buffer "*dvi-printing*"
530 (if YaTeX-dos
531 (call-process shell-file-name "con" "*dvi-printing*" nil
532 "/c " cmd)
533 (start-process "print" "*dvi-printing*" shell-file-name "-c" cmd)
534 (message (concat "Starting " cmd " to printing "
535 (YaTeX-get-preview-file-name))))
536 )))
537 )
539 (defun YaTeX-main-file-p ()
540 "Return if current buffer is main LaTeX source."
541 (cond
542 ((YaTeX-get-builtin "!")
543 (string-match
544 (concat "^" (YaTeX-get-preview-file-name) ".tex")(buffer-name)))
545 (t
546 (save-excursion
547 (let ((latex-main-id (concat "^\\s *" YaTeX-ec-regexp "documentstyle")))
548 (or (re-search-backward latex-main-id nil t)
549 (re-search-forward latex-main-id nil t))))))
550 )
552 (defun YaTeX-visit-main (&optional setbuf)
553 "Switch to buffer main LaTeX source. Use set-buffer instead of
554 switch-to-buffer if the optional second argument SETBUF is t(Use it only
555 in Emacs-Lisp program)."
556 (interactive)
557 (let (main-file)
558 (if (YaTeX-get-builtin "!")
559 (setq main-file (concat (YaTeX-get-preview-file-name) ".tex")))
560 (if YaTeX-parent-file
561 (setq main-file YaTeX-parent-file))
562 (if (YaTeX-main-file-p)
563 (if (interactive-p) (message "I think this is main LaTeX source.") nil)
564 (cond
565 ((and (interactive-p) main-file (get-buffer-window main-file))
566 (select-window (get-buffer-window main-file)))
567 ((and main-file (YaTeX-switch-to-buffer main-file setbuf)))
568 ((and main-file
569 (file-exists-p (setq main-file (concat "../" main-file)))
570 (y-or-n-p (concat (expand-file-name main-file)
571 " is main file?:")))
572 (YaTeX-switch-to-buffer main-file setbuf))
573 (t (setq main-file (read-file-name "Enter your main text: " nil nil 1))
574 (setq YaTeX-parent-file main-file)
575 (find-file main-file))
576 )))
577 nil
578 )
580 (defun YaTeX-visit-main-other-window ()
581 "Switch to buffer main LaTeX source in other window."
582 (interactive)
583 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
584 (YaTeX-switch-to-buffer-other-window
585 (concat (YaTeX-get-preview-file-name) ".tex")))
586 )
588 (defun YaTeX-get-builtin (key)
589 "Read source built-in command of %# usage."
590 (save-excursion
591 (goto-char (point-min))
592 (if (and (search-forward (concat "%#" key) nil t)
593 (not (eolp)))
594 (buffer-substring
595 (progn (skip-chars-forward " " (point-end-of-line))(point))
596 (point-end-of-line))
597 nil))
598 )
600 (defun YaTeX-save-buffers ()
601 "Save buffers which is in yatex-mode."
602 (basic-save-buffer)
603 (save-excursion
604 (mapcar '(lambda (buf)
605 (set-buffer buf)
606 (if (and (buffer-file-name buf)
607 (eq major-mode 'yatex-mode)
608 (buffer-modified-p buf)
609 (y-or-n-p (format "Save %s" (buffer-name buf))))
610 (save-buffer buf)))
611 (buffer-list)))
612 )
614 (defun YaTeX-pop-to-buffer (buffer &optional win)
615 (if (setq win (get-buffer-window buffer))
616 (select-window win)
617 (pop-to-buffer buffer))
618 )
620 (defun YaTeX-showup-buffer (buffer &optional func select)
621 "Make BUFFER show up in certain window (but current window)
622 that gives the maximum value by the FUNC. FUNC should take an argument
623 of its window object. Non-nil for optional third argument SELECT selects
624 that window."
625 (or (and (get-buffer-window buffer)
626 (progn (if select (select-window (get-buffer-window buffer))) t))
627 (cond
628 ((> (length (YaTeX-window-list)) 2)
629 (let ((window (selected-window))
630 (list (YaTeX-window-list)) win w (x 0))
631 (if func
632 (while list
633 (setq w (car list))
634 (if (and (not (eq window w))
635 (> (funcall func w) x))
636 (setq win w x (funcall func w)))
637 (setq list (cdr list)))
638 (setq win (get-lru-window)))
639 (select-window win)
640 (switch-to-buffer buffer)
641 (or select (select-window window))))
642 ((= (length (YaTeX-window-list)) 2)
643 (other-window 1)
644 (switch-to-buffer buffer))
645 (t nil)))
646 )
648 (defun YaTeX-window-list ()
649 (let*((curw (selected-window)) (win curw) (wlist (list curw)))
650 (while (not (eq curw (setq win (next-window win))))
651 (setq wlist (cons win wlist)))
652 wlist)
653 )
654 (provide 'yatexprc)