yatex

changeset 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
files docs/yatex.ref docs/yatexadd.doc docs/yatexgen.doc yatex.el yatex.new yatexadd.el yatexgen.el yatexmth.el yatexprc.el
diffstat 9 files changed, 170 insertions(+), 131 deletions(-) [+]
line diff
     1.1 --- a/docs/yatex.ref	Sat Jan 29 07:59:59 1994 +0000
     1.2 +++ b/docs/yatex.ref	Fri Apr 22 17:35:25 1994 +0000
     1.3 @@ -23,6 +23,7 @@
     1.4  	◆large型補完(領域指定)		[prefix] L
     1.5  	◆maketitle型補完		[prefix] m
     1.6  	◆section型補完			[prefix] s
     1.7 +	◆section型補完(領域指定)	[prefix] S
     1.8  	◆随時補完			[prefix] SPC
     1.9  
    1.10  	  即時begin型補完の、環境名の頭文字の対応については、yatex.doc を
    1.11 @@ -101,8 +102,8 @@
    1.12  
    1.13  	◆コマンド削除			[prefix] k
    1.14  
    1.15 -	  \begin{}, \end{} のペア、または %#BEGIN, %#END のペアを一挙に削
    1.16 -	除します。
    1.17 +	  \begin{}, \end{} のペア、%#BEGIN, %#END のペア、括弧のペア、ま
    1.18 +	たはsection型コマンドを一挙に削除します。
    1.19  
    1.20  	◆領域を()で括る		[prefix] )
    1.21  	◆領域を{}で括る		[prefix] }
    1.22 @@ -114,10 +115,9 @@
    1.23  
    1.24  	◆%# 記法の編集			[prefix] %
    1.25  
    1.26 -								   広瀬雄二
    1.27 -							yuuji@ae.keio.ac.jp
    1.28 -							pcs39334(ASCII-NET)
    1.29 -
    1.30 +							       広瀬雄二
    1.31 +						    yuuji@ae.keio.ac.jp
    1.32 +						pcs39334@asciinet.or.jp
    1.33  
    1.34  Local variables:
    1.35  mode: text
     2.1 --- a/docs/yatexadd.doc	Sat Jan 29 07:59:59 1994 +0000
     2.2 +++ b/docs/yatexadd.doc	Fri Apr 22 17:35:25 1994 +0000
     2.3 @@ -161,6 +161,6 @@
     2.4  	思います。
     2.5  
     2.6  
     2.7 -								   広瀬雄二
     2.8 -							yuuji@ae.keio.ac.jp
     2.9 -							pcs39334(ASCII-NET)
    2.10 +							       広瀬雄二
    2.11 +						    yuuji@ae.keio.ac.jp
    2.12 +						pcs39334@asciinet.or.jp
     3.1 --- a/docs/yatexgen.doc	Sat Jan 29 07:59:59 1994 +0000
     3.2 +++ b/docs/yatexgen.doc	Fri Apr 22 17:35:25 1994 +0000
     3.3 @@ -50,7 +50,6 @@
     3.4  	ら、幸福感に浸るだけにして、決して筆者まで送ったりしないで下さい。
     3.5  	yatexgen が作るんだから、ろくな関数じゃないことは分かってます:-p。
     3.6  
     3.7 -
     3.8 -								   広瀬雄二
     3.9 -							yuuji@ae.keio.ac.jp
    3.10 -							pcs39334(ASCII-NET)
    3.11 +							       広瀬雄二
    3.12 +						    yuuji@ae.keio.ac.jp
    3.13 +						pcs39334@asciinet.or.jp
     4.1 Binary file yatex.el has changed
     5.1 --- a/yatex.new	Sat Jan 29 07:59:59 1994 +0000
     5.2 +++ b/yatex.new	Fri Apr 22 17:35:25 1994 +0000
     5.3 @@ -2,6 +2,13 @@
     5.4  	Yet Another tex-mode for Emacs
     5.5  	yatex.el 各バージョンの変更点について。
     5.6  
     5.7 +1.46	リジョン指定つき section 型補完の追加。
     5.8 +	[prefix] k で section 型コマンドの削除、対応する括弧の削除。
     5.9 +	エラー行ジャンプの適正化。
    5.10 +	再帰的 section 型補完時のバグフィクス。
    5.11 +	親ファイルを手入力した時に二度目以降もそのファイルを親とみなす。
    5.12 +	\verbのアドイン関数追加。
    5.13 +
    5.14  1.45:	comment-region を begin/end 行で起動した時にメッセージを出す。
    5.15  	yatexmth:イメージ補完で複数の補完テーブルが使えるようにし、
    5.16  	/で始まるギリシャ文字補完を追加。
     6.1 --- a/yatexadd.el	Sat Jan 29 07:59:59 1994 +0000
     6.2 +++ b/yatexadd.el	Fri Apr 22 17:35:25 1994 +0000
     6.3 @@ -1,8 +1,8 @@
     6.4  ;;; -*- Emacs-Lisp -*-
     6.5  ;;; YaTeX add-in functions.
     6.6 -;;; yatexadd.el rev.6
     6.7 -;;; (c )1991-1993 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     6.8 -;;; Last modified Sat Jan 29 16:55:09 1994 on gloria
     6.9 +;;; yatexadd.el rev.7
    6.10 +;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
    6.11 +;;; Last modified Sat Apr 23 02:26:47 1994 on pajero
    6.12  ;;; $Id$
    6.13  
    6.14  (provide 'yatexadd)
    6.15 @@ -152,6 +152,17 @@
    6.16        (concat ULchar "{" bndry "}")))
    6.17  )
    6.18  
    6.19 +(defun YaTeX:verb ()
    6.20 +  "Enclose \\verb's contents with the same characters."
    6.21 +  (let ((quote-char (read-string "Quoting char: " "|"))
    6.22 +	(contents (read-string "Quoted contents: ")))
    6.23 +    (concat quote-char contents quote-char))
    6.24 +)
    6.25 +
    6.26 +;;;
    6.27 +;;Subroutine
    6.28 +;;;
    6.29 +
    6.30  (defun YaTeX:check-completion-type (type)
    6.31    "Check valid completion type."
    6.32    (if (not (eq type YaTeX-current-completion-type))
     7.1 --- a/yatexgen.el	Sat Jan 29 07:59:59 1994 +0000
     7.2 +++ b/yatexgen.el	Fri Apr 22 17:35:25 1994 +0000
     7.3 @@ -1,8 +1,8 @@
     7.4  ;;; -*- Emacs-Lisp -*-
     7.5  ;;; Generate add-in functions for YaTeX.
     7.6  ;;; yatexgen.el rev.1(beta2)
     7.7 -;;; (c )1991-1993 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     7.8 -;;; Last modified Sat Jan 29 16:55:07 1994 on gloria
     7.9 +;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
    7.10 +;;; Last modified Sat Apr 23 02:26:34 1994 on pajero
    7.11  ;;; $Id$
    7.12  
    7.13  (require 'yatex)
     8.1 --- a/yatexmth.el	Sat Jan 29 07:59:59 1994 +0000
     8.2 +++ b/yatexmth.el	Fri Apr 22 17:35:25 1994 +0000
     8.3 @@ -1,8 +1,8 @@
     8.4  ;;; -*- Emacs-Lisp -*-
     8.5  ;;; YaTeX interface for math-mode.
     8.6  ;;; yatexmth.el rev.2
     8.7 -;;; (c )1993 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
     8.8 -;;; Last modified Sat Jan 29 16:55:03 1994 on gloria
     8.9 +;;; (c )1993-1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
    8.10 +;;; Last modified Sat Apr 23 02:26:57 1994 on pajero
    8.11  ;;; $Id$
    8.12  
    8.13  ;;; [Customization guide]
     9.1 --- a/yatexprc.el	Sat Jan 29 07:59:59 1994 +0000
     9.2 +++ b/yatexprc.el	Fri Apr 22 17:35:25 1994 +0000
     9.3 @@ -1,8 +1,8 @@
     9.4  ;;; -*- Emacs-Lisp -*-
     9.5  ;;; YaTeX process handler.
     9.6  ;;; yatexprc.el
     9.7 -;;; (c )1993 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     9.8 -;;; Last modified Sat Jan 29 16:54:54 1994 on gloria
     9.9 +;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
    9.10 +;;; Last modified Sat Apr 23 02:34:07 1994 on pajero
    9.11  ;;; $Id$
    9.12  
    9.13  (require 'yatex)
    9.14 @@ -16,6 +16,9 @@
    9.15  (defvar YaTeX-typeset-buffer-syntax nil
    9.16    "*Syntax table for typesetting buffer")
    9.17  
    9.18 +(defvar YaTeX-current-TeX-buffer nil
    9.19 +  "Keeps the buffer on which recently typeset run.")
    9.20 +
    9.21  (if YaTeX-typeset-buffer-syntax nil
    9.22    (setq YaTeX-typeset-buffer-syntax
    9.23  	(make-syntax-table (standard-syntax-table)))
    9.24 @@ -34,7 +37,7 @@
    9.25  	;; if tex command is halting.
    9.26  	(YaTeX-kill-typeset-process YaTeX-typeset-process))
    9.27      (YaTeX-visit-main t);;execution directory
    9.28 -    ;;Select under-most window if there are more than 2 windows and
    9.29 +    ;;Select lower-most window if there are more than 2 windows and
    9.30      ;;typeset buffer not seen.
    9.31      (YaTeX-showup-buffer
    9.32       buffer (function (lambda (x) (nth 3 (window-edges x)))))
    9.33 @@ -50,7 +53,7 @@
    9.34  	      (start-process "LaTeX" buffer shell-file-name "-c"
    9.35  			     command))
    9.36  	(set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
    9.37 -    (setq current-TeX-buffer (buffer-name))
    9.38 +    (setq YaTeX-current-TeX-buffer (buffer-name))
    9.39      (select-window (get-buffer-window buffer))
    9.40      (use-local-map YaTeX-typesetting-mode-map)
    9.41      (set-syntax-table YaTeX-typeset-buffer-syntax)
    9.42 @@ -264,7 +267,6 @@
    9.43    (interactive
    9.44     (list (read-string "Preview command: " dvi2-command)
    9.45  	 (read-string "Preview file[.dvi]: "
    9.46 -		      ;;(substring (buffer-name) 0 -4)
    9.47  		      (if (get 'dvi2-command 'region)
    9.48  			  (substring YaTeX-texput-file
    9.49  				     0 (rindex YaTeX-texput-file ?.))
    9.50 @@ -287,85 +289,74 @@
    9.51  )
    9.52  
    9.53  (defun YaTeX-prev-error ()
    9.54 -  "Visit previous error.  The reason why not NEXT-error is to
    9.55 -avoid making confliction of line numbers by editing."
    9.56 +  "Visit previous typeset error.
    9.57 +  To avoid making confliction of line numbers by editing, jump to
    9.58 +error or warning lines in reverse order."
    9.59    (interactive)
    9.60    (let ((cur-buf (buffer-name)) (cur-win (selected-window))
    9.61 -	YaTeX-error-line typeset-win error-buffer error-win)
    9.62 +	error-line typeset-win error-buffer error-win)
    9.63      (if (null (get-buffer YaTeX-typeset-buffer))
    9.64 -	(message "There is no output buffer of typesetting.")
    9.65 -      (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
    9.66 -      (setq typeset-win (selected-window))
    9.67 -      (if YaTeX-dos
    9.68 -	  (if (search-backward latex-dos-emergency-message nil t)
    9.69 -	      (progn (goto-char (point-max))
    9.70 -		     (setq error-regexp latex-error-regexp))
    9.71 -	    (beginning-of-line)
    9.72 -	    (forward-char -1)
    9.73 -	    (setq error-regexp latex-warning-regexp))
    9.74 -	(if YaTeX-typeset-process      ; if jlatex on UNIX
    9.75 -	    (if (eq (process-status YaTeX-typeset-process) 'run)
    9.76 -		(progn
    9.77 -		  (goto-char (point-max))
    9.78 -		  (setq error-regexp latex-error-regexp))
    9.79 -	      (beginning-of-line)
    9.80 -	      (setq error-regexp latex-warning-regexp))))
    9.81 -      (if (re-search-backward error-regexp nil t)
    9.82 -	  (setq YaTeX-error-line
    9.83 -		(string-to-int
    9.84 -		 (buffer-substring
    9.85 -		  (progn (goto-char (match-beginning 0))
    9.86 -			 (skip-chars-forward "^0-9")
    9.87 -			 (point))
    9.88 -		  (progn (skip-chars-forward "0-9") (point)))))
    9.89 -	(message "No more errors on %s" cur-buf)
    9.90 -	(ding))
    9.91 -      (setq error-buffer (YaTeX-get-error-file cur-buf)); arg. is default buf.
    9.92 -      (setq error-win (get-buffer-window error-buffer))
    9.93 +	(error "There is no typesetting buffer."))
    9.94 +    (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
    9.95 +    (setq typeset-win (selected-window))
    9.96 +    (if (re-search-backward
    9.97 +	 (concat "\\(" latex-error-regexp "\\)\\|\\("
    9.98 +		 latex-warning-regexp "\\)")
    9.99 +	 nil t)
   9.100 +	nil
   9.101        (select-window cur-win)
   9.102 -      (if (or (null YaTeX-error-line) (equal 0 YaTeX-error-line))
   9.103 -	  nil
   9.104 -	;; if warning or error found
   9.105 -	(if error-win (select-window error-win)
   9.106 -	  (select-window (get-lru-window))
   9.107 -	  (YaTeX-switch-to-buffer error-buffer)
   9.108 -	  (setq error-win (selected-window)))
   9.109 -	(goto-line YaTeX-error-line)
   9.110 -	(message "latex error or warning in '%s' at line: %d"
   9.111 -		 error-buffer YaTeX-error-line)
   9.112 -	(select-window typeset-win)
   9.113 -	(skip-chars-backward "[0-9]")
   9.114 -	(recenter (/ (window-height) 2))
   9.115 -	(sit-for 3)
   9.116 -	(forward-char -1)
   9.117 -	(select-window error-win)
   9.118 -	)))
   9.119 +      (error "No more erros on %s" cur-buf))
   9.120 +    (goto-char (match-beginning 0))
   9.121 +    (skip-chars-forward "^0-9" (match-end 0))
   9.122 +    (setq error-line
   9.123 +	  (string-to-int
   9.124 +	   (buffer-substring
   9.125 +	    (point)
   9.126 +	    (progn (skip-chars-forward "0-9" (match-end 0)) (point))))
   9.127 +	  error-buffer (YaTeX-get-error-file cur-buf)
   9.128 +	  error-win (get-buffer-window error-buffer))
   9.129 +    (if (or (null error-line) (equal 0 error-line))
   9.130 +	(error "Can't detect error position."))
   9.131 +    (select-window cur-win)
   9.132 +    (cond
   9.133 +     (error-win (select-window error-win))
   9.134 +     ((eq (get-lru-window) typeset-win)
   9.135 +      (YaTeX-switch-to-buffer error-buffer))
   9.136 +     (t (select-window (get-lru-window))
   9.137 +	(YaTeX-switch-to-buffer error-buffer)))
   9.138 +    (setq error-win (selected-window))
   9.139 +    (goto-line error-line)
   9.140 +    (message "LaTeX %s in `%s' on line: %d."
   9.141 +	     (if (match-beginning 1) "error" "warning")
   9.142 +	     error-buffer error-line)
   9.143 +    (select-window typeset-win)
   9.144 +    (skip-chars-backward "0-9")
   9.145 +    (recenter (/ (window-height) 2))
   9.146 +    (sit-for 3)
   9.147 +    (goto-char (match-beginning 0))
   9.148 +    (select-window error-win))
   9.149  )
   9.150  
   9.151  (defun YaTeX-jump-error-line ()
   9.152    "Jump to corresponding line on latex command's error message."
   9.153    (interactive)
   9.154 -  (let ((p (point))
   9.155 -	(end (progn (end-of-line) (point)))
   9.156 -	(begin (progn (beginning-of-line)(point))))
   9.157 -    (if (null (re-search-forward "l[ ines]*\\.*[1-9][0-9]*" end t))
   9.158 -	(if (save-excursion (end-of-line) (eobp))
   9.159 -	    (progn (goto-char p) (insert (this-command-keys)))
   9.160 -	  (message "No line number expression"))
   9.161 +  (let (error-line error-file error-buf)
   9.162 +    (save-excursion
   9.163 +      (beginning-of-line)
   9.164 +      (setq error-line (re-search-forward "l[ ines]*\\.\\([1-9][0-9]*\\)"
   9.165 +					  (point-end-of-line) t)))
   9.166 +    (if (null error-line)
   9.167 +	(if (eobp) (insert (this-command-keys))
   9.168 +	  (error "No line number expression."))
   9.169        (goto-char (match-beginning 0))
   9.170 -      (re-search-forward "[1-9][0-9]*" end t)
   9.171 -      (save-restriction
   9.172 -	(let ((error-line
   9.173 -	       (string-to-int (buffer-substring (match-beginning 0)
   9.174 -						(match-end 0))))
   9.175 -	      (error-file (YaTeX-get-error-file current-TeX-buffer)))
   9.176 -	  ;;(goto-char (match-beginning 0))
   9.177 -	  (other-window -1)
   9.178 -	  (message "errors in %s" error-file)
   9.179 -	  ;(switch-to-buffer current-TeX-buffer)
   9.180 -	  (if (not (YaTeX-switch-to-buffer error-file))
   9.181 -	      (error "%s is not found in this directory."))
   9.182 -	  (goto-line error-line)))))
   9.183 +      (setq error-line (string-to-int
   9.184 +			(buffer-substring (match-beginning 1) (match-end 1)))
   9.185 +	    error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)
   9.186 +	    error-buf (YaTeX-switch-to-buffer error-file t))
   9.187 +      (if (null error-buf)
   9.188 +	  (error "`%s' is not found in this directory." error-file))
   9.189 +      (YaTeX-showup-buffer error-buf nil t)
   9.190 +      (goto-line error-line)))
   9.191  )
   9.192  
   9.193  (defun YaTeX-send-string ()
   9.194 @@ -425,7 +416,7 @@
   9.195        
   9.196  (defun YaTeX-put-nonstopmode ()
   9.197    (if YaTeX-need-nonstop
   9.198 -      (if (re-search-backward "\\nonstopmode{}" (point-min) t)
   9.199 +      (if (re-search-backward "\\\\nonstopmode{}" (point-min) t)
   9.200  	  nil                    ;if already written in text then do nothing
   9.201  	(save-excursion
   9.202  	  (YaTeX-visit-main t)
   9.203 @@ -453,7 +444,9 @@
   9.204  	 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
   9.205  	 (period))
   9.206      (if (string= fname "")
   9.207 -	(setq fname (substring (buffer-name) 0 -4))
   9.208 +	(setq fname (substring (file-name-nondirectory
   9.209 +				(buffer-file-name))
   9.210 +			       0 -4))
   9.211        (setq period (rindex fname ?.))
   9.212        (setq fname (substring fname 0 (if (eq -1 period) nil period)))
   9.213        ))
   9.214 @@ -461,21 +454,24 @@
   9.215  
   9.216  (defun YaTeX-get-latex-command (&optional switch)
   9.217    "Specify the latex-command name and its argument.
   9.218 -If there is a line which begins by string: \"%#!\", the following
   9.219 +If there is a line which begins with string: \"%#!\", the following
   9.220  strings are assumed to be the latex-command and arguments.  The
   9.221  default value of latex-command is:
   9.222 -	tex-command (buffer-name)
   9.223 +	tex-command FileName
   9.224  and if you write \"%#!jlatex\" in the beginning of certain line.
   9.225 -	\"jlatex \" (buffer-name)
   9.226 +	\"jlatex \" FileName
   9.227  will be the latex-command,
   9.228  and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
   9.229 -is t, then
   9.230 +is non-nil, then
   9.231  	\"jlatex main.tex\"
   9.232  will be given to the shell."
   9.233 -  (let*
   9.234 -      ((default-command
   9.235 -	 (concat tex-command " "
   9.236 -		 (if switch (buffer-name) ""))));default value
   9.237 +  (let*((target (file-name-nondirectory
   9.238 +		 (or YaTeX-parent-file
   9.239 +		     (save-excursion
   9.240 +		       (YaTeX-visit-main t)
   9.241 +		       (buffer-file-name)))))
   9.242 +	(default-command
   9.243 +	  (concat tex-command " " (if switch target ""))));default value
   9.244      (save-excursion
   9.245        (goto-char (point-min))
   9.246        (if (null (re-search-forward "^%#!" (point-max) t))
   9.247 @@ -486,16 +482,16 @@
   9.248  	  (let ((s (point)))
   9.249  	    (skip-chars-forward "^ 	" (point-end-of-line)) ;Skip command
   9.250  	    (skip-chars-forward " 	" (point-end-of-line))
   9.251 -	    ;(setq YaTeX-latex-command (buffer-substring s (point)))
   9.252  	    (cond
   9.253  	     ((null switch)
   9.254  	      (buffer-substring s (point)))
   9.255  	     ((eolp)			 ;Only return command name
   9.256 -	      (concat (buffer-substring s (point)) " " (buffer-name)))
   9.257 +	      (concat (buffer-substring s (point)) " "
   9.258 +		      (file-name-nondirectory
   9.259 +		       (or YaTeX-parent-file (buffer-file-name)))))
   9.260  	     (t(end-of-line)		   ;Change entire command name
   9.261  	       (buffer-substring s (point))) ;including arguments.
   9.262 -	    ))
   9.263 -	))))
   9.264 +	    ))))))
   9.265  )
   9.266  
   9.267  (defun YaTeX-lpr (arg)
   9.268 @@ -542,26 +538,42 @@
   9.269  
   9.270  (defun YaTeX-main-file-p ()
   9.271    "Return if current buffer is main LaTeX source."
   9.272 -  (string-match (concat "^" (YaTeX-get-preview-file-name) ".tex")(buffer-name))
   9.273 +  (cond
   9.274 +   ((YaTeX-get-builtin "!")
   9.275 +    (string-match
   9.276 +     (concat "^" (YaTeX-get-preview-file-name) ".tex")(buffer-name)))
   9.277 +   (t
   9.278 +    (save-excursion
   9.279 +      (let ((latex-main-id (concat "^\\s *" YaTeX-ec-regexp "documentstyle")))
   9.280 +	(or (re-search-backward latex-main-id nil t)
   9.281 +	    (re-search-forward latex-main-id nil t))))))
   9.282  )
   9.283  
   9.284  (defun YaTeX-visit-main (&optional setbuf)
   9.285    "Switch to buffer main LaTeX source.  Use set-buffer instead of
   9.286 -switch-to-buffer if optional second argument SETBUF is t(Use it only
   9.287 +switch-to-buffer if the optional second argument SETBUF is t(Use it only
   9.288  in Emacs-Lisp program)."
   9.289    (interactive)
   9.290 -  (let ((main-file (YaTeX-get-preview-file-name)))
   9.291 -    (if (string-match (concat "^" main-file ".tex") (buffer-name))
   9.292 +  (let (main-file)
   9.293 +    (if (YaTeX-get-builtin "!")
   9.294 +	(setq main-file (concat (YaTeX-get-preview-file-name) ".tex")))
   9.295 +    (if YaTeX-parent-file
   9.296 +	(setq main-file YaTeX-parent-file))
   9.297 +    (if (YaTeX-main-file-p)
   9.298  	(if (interactive-p) (message "I think this is main LaTeX source.") nil)
   9.299        (cond
   9.300 -       ((YaTeX-switch-to-buffer (setq main-file (concat main-file ".tex"))
   9.301 -				setbuf))
   9.302 -       ((and (file-exists-p (setq main-file (concat "../" main-file)))
   9.303 +       ((and (interactive-p) main-file (get-buffer-window main-file))
   9.304 +	(select-window (get-buffer-window main-file)))
   9.305 +       ((and main-file (YaTeX-switch-to-buffer main-file setbuf)))
   9.306 +       ((and main-file
   9.307 +	     (file-exists-p (setq main-file (concat "../" main-file)))
   9.308  	     (y-or-n-p (concat (expand-file-name main-file)
   9.309  			       " is main file?:")))
   9.310  	(YaTeX-switch-to-buffer main-file setbuf))
   9.311 -       (t (find-file (read-file-name "Enter your main text: " nil nil 1)))
   9.312 -	)))
   9.313 +       (t (setq main-file (read-file-name "Enter your main text: " nil nil 1))
   9.314 +	  (setq YaTeX-parent-file main-file)
   9.315 +	  (find-file main-file))
   9.316 +       )))
   9.317    nil
   9.318  )
   9.319  
   9.320 @@ -605,22 +617,32 @@
   9.321      (pop-to-buffer buffer))
   9.322  )
   9.323  
   9.324 -(defun YaTeX-showup-buffer (buffer &optional func)
   9.325 +(defun YaTeX-showup-buffer (buffer &optional func select)
   9.326    "Make BUFFER show up in certain window (but current window)
   9.327  that gives the maximum value by the FUNC.  FUNC should take an argument
   9.328 -of its window object"
   9.329 -  (or (get-buffer-window buffer)
   9.330 -      (< (length (YaTeX-window-list)) 3)
   9.331 -      (let ((window (selected-window)) (list (YaTeX-window-list)) win w (x 0))
   9.332 -	(while list
   9.333 -	  (setq w (car list))
   9.334 -	    (if (and (not (eq window w))
   9.335 -		     (> (funcall func w) x))
   9.336 -		(setq win w x (funcall func w)))
   9.337 -	    (setq list (cdr list)))
   9.338 -	(select-window win)
   9.339 -	(switch-to-buffer buffer)
   9.340 -	(select-window window)))
   9.341 +of its window object.  Non-nil for optional third argument SELECT selects
   9.342 +that window."
   9.343 +  (or (and (get-buffer-window buffer)
   9.344 +	   (progn (if select (select-window (get-buffer-window buffer))) t))
   9.345 +      (cond
   9.346 +       ((> (length (YaTeX-window-list)) 2)
   9.347 +	(let ((window (selected-window))
   9.348 +	      (list (YaTeX-window-list)) win w (x 0))
   9.349 +	  (if func
   9.350 +	      (while list
   9.351 +		(setq w (car list))
   9.352 +		(if (and (not (eq window w))
   9.353 +			 (> (funcall func w) x))
   9.354 +		    (setq win w x (funcall func w)))
   9.355 +		(setq list (cdr list)))
   9.356 +	    (setq win (get-lru-window)))
   9.357 +	  (select-window win)
   9.358 +	  (switch-to-buffer buffer)
   9.359 +	  (or select (select-window window))))
   9.360 +       ((= (length (YaTeX-window-list)) 2)
   9.361 +	(other-window 1)
   9.362 +	(switch-to-buffer buffer))
   9.363 +       (t nil)))
   9.364  )
   9.365  
   9.366  (defun YaTeX-window-list ()