yatex

diff yatexprc.el @ 24:21a751ddf614

Initial revision
author yuuji
date Thu, 07 Jul 1994 16:45:12 +0000
parents adc2f1472409
children 23737513bf5f
line diff
     1.1 --- a/yatexprc.el	Mon May 16 09:30:52 1994 +0000
     1.2 +++ b/yatexprc.el	Thu Jul 07 16:45:12 1994 +0000
     1.3 @@ -2,7 +2,7 @@
     1.4  ;;; YaTeX process handler.
     1.5  ;;; yatexprc.el
     1.6  ;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     1.7 -;;; Last modified Fri May 13 01:22:54 1994 on 98fa
     1.8 +;;; Last modified Fri Jul  1 02:44:32 1994 on figaro
     1.9  ;;; $Id$
    1.10  
    1.11  (require 'yatex)
    1.12 @@ -44,7 +44,7 @@
    1.13      (with-output-to-temp-buffer buffer
    1.14        (if YaTeX-dos			;if MS-DOS
    1.15  	  (progn
    1.16 -	    (message (concat "Typesetting " (buffer-name) "..."))
    1.17 +	    (message (format "Calling `%s'..." command))
    1.18  	    (YaTeX-put-nonstopmode)
    1.19  	    (call-process shell-file-name
    1.20  			  nil buffer nil "/c" command)
    1.21 @@ -64,10 +64,9 @@
    1.22  		YaTeX-latex-message-code YaTeX-coding-system))
    1.23  	      ((boundp 'NEMACS)
    1.24  	       (set-kanji-process-code YaTeX-latex-message-code))))
    1.25 -    (message "Type SPC to continue.")
    1.26      (goto-char (point-max))
    1.27      (if YaTeX-dos (message "Done.")
    1.28 -      (insert (message " "))
    1.29 +      (insert " ")
    1.30        (set-marker (process-mark YaTeX-typeset-process) (1- (point))))
    1.31      (if (bolp) (forward-line -1))
    1.32      (recenter -1)
    1.33 @@ -80,16 +79,19 @@
    1.34           (set-process-buffer proc nil))
    1.35          ((memq (process-status proc) '(signal exit))
    1.36           (let* ((obuf (current-buffer)) (pbuf (process-buffer proc))
    1.37 +		(pwin (get-buffer-window pbuf))
    1.38  		(owin (selected-window)) win)
    1.39             ;; save-excursion isn't the right thing if
    1.40             ;;  process-buffer is current-buffer
    1.41             (unwind-protect
    1.42                 (progn
    1.43                   ;; Write something in *typesetting* and hack its mode line
    1.44 -		 (YaTeX-pop-to-buffer pbuf)
    1.45 -		 (set-buffer (process-buffer proc))
    1.46 +		 (if pwin
    1.47 +		     (select-window pwin)
    1.48 +		   (set-buffer pbuf))
    1.49 +		 ;;(YaTeX-showup-buffer pbuf nil t)
    1.50                   (goto-char (point-max))
    1.51 -		 (recenter -3)
    1.52 +		 (if pwin (recenter -3))
    1.53                   (insert ?\n "latex typesetting " mes)
    1.54                   (forward-char -1)
    1.55                   (insert " at " (substring (current-time-string) 0 -5) "\n")
    1.56 @@ -132,19 +134,34 @@
    1.57      (let*
    1.58  	((end "") typeout ;Type out message that tells the method of cutting.
    1.59  	 (cmd (concat (YaTeX-get-latex-command nil) " " YaTeX-texput-file))
    1.60 -	 (buffer (current-buffer)) opoint preamble main
    1.61 +	 (buffer (current-buffer)) opoint preamble (subpreamble "") main
    1.62  	 reg-begin reg-end)
    1.63 -      
    1.64 -      (if (re-search-backward "%#BEGIN" nil t)
    1.65 +
    1.66 +      (if (search-backward "%#BEGIN" nil t)
    1.67  	  (progn
    1.68 -	    (setq typeout "--- Region from BEGIN to " end "END ---"
    1.69 +	    (setq typeout "--- Region from BEGIN to "
    1.70 +		  end "the end of the buffer ---"
    1.71  		  reg-begin (match-end 0))
    1.72 -	    (if (re-search-forward "%#END" nil t)
    1.73 +	    (if (search-forward "%#END" nil t)
    1.74  		(setq reg-end (match-beginning 0)
    1.75 -		      end "end of buffer ---")
    1.76 +		      end "END ---")
    1.77  	      (setq reg-end (point-max))))
    1.78  	(setq typeout "=== Region from (point) to (mark) ===")
    1.79  	(setq reg-begin (point) reg-end (mark)))
    1.80 +      (goto-char (point-min))
    1.81 +      (while (search-forward "%#REQUIRE" nil t)
    1.82 +	(setq subpreamble
    1.83 +	      (concat subpreamble
    1.84 +		      (cond
    1.85 +		       ((eolp)
    1.86 +			(buffer-substring
    1.87 +			 (match-beginning 0)
    1.88 +			 (point-beginning-of-line)))
    1.89 +		       (t (buffer-substring
    1.90 +			   (match-end 0)
    1.91 +			   (point-end-of-line))))
    1.92 +		      "\n"))
    1.93 +	(goto-char (match-end 0)))
    1.94        (YaTeX-visit-main t)
    1.95        (setq main (current-buffer))
    1.96        (setq opoint (point))
    1.97 @@ -162,7 +179,7 @@
    1.98        (erase-buffer)
    1.99        (if YaTeX-need-nonstop
   1.100  	  (insert "\\nonstopmode{}\n"))
   1.101 -      (insert preamble "\n")
   1.102 +      (insert preamble "\n" subpreamble "\n")
   1.103        (insert-buffer-substring buffer reg-begin reg-end)
   1.104        (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
   1.105        (insert "\n\\end{document}\n")
   1.106 @@ -261,6 +278,8 @@
   1.107  (defun YaTeX-system (command buffer)
   1.108    "Execute some command on buffer.  Not a official function."
   1.109    (save-excursion
   1.110 +    (YaTeX-showup-buffer
   1.111 +     buffer (function (lambda (x) (nth 3 (window-edges x)))))
   1.112      (with-output-to-temp-buffer buffer
   1.113        (if YaTeX-dos
   1.114  	  (call-process shell-file-name nil buffer nil "/c " command)
   1.115 @@ -286,20 +305,24 @@
   1.116  				  0 (rindex YaTeX-texput-file ?.))
   1.117  		     (YaTeX-get-preview-file-name))
   1.118  		   ))))
   1.119 -  (setq dvi2-command preview-command)
   1.120 +  (setq dvi2-command preview-command)	;`dvi2command' is buffer local
   1.121    (save-excursion
   1.122      (YaTeX-visit-main t)
   1.123 -    (with-output-to-temp-buffer "*dvi-preview*"
   1.124 -      (if YaTeX-dos			;if MS-DOS
   1.125 -	  (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
   1.126 -		 (call-process shell-file-name "con" "*dvi-preview*" nil
   1.127 -			       "/c " dvi2-command preview-file)
   1.128 -		 (send-string-to-terminal "\e[>5l") ;show cursor
   1.129 -		 (redraw-display))
   1.130 -	(start-process "preview" "*dvi-preview*" shell-file-name "-c"
   1.131 -		       (concat dvi2-command " " preview-file)) ;if UNIX
   1.132 -	(message
   1.133 -	 (concat "Starting " dvi2-command " to preview " preview-file)))))
   1.134 +    (let ((pbuffer "*dvi-preview*"))
   1.135 +      (YaTeX-showup-buffer
   1.136 +       pbuffer (function (x) (nth 3 (window-edges x))))
   1.137 +      (with-output-to-temp-buffer pbuffer
   1.138 +	(if YaTeX-dos			;if MS-DOS
   1.139 +	    (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
   1.140 +		   (call-process shell-file-name "con" "*dvi-preview*" nil
   1.141 +				 "/c " preview-command preview-file)
   1.142 +		   (send-string-to-terminal "\e[>5l") ;show cursor
   1.143 +		   (redraw-display))
   1.144 +	  (start-process "preview" "*dvi-preview*" shell-file-name "-c"
   1.145 +			 (concat preview-command " " preview-file)) ;if UNIX
   1.146 +	  (message
   1.147 +	   (concat "Starting " preview-command
   1.148 +		   " to preview " preview-file))))))
   1.149  )
   1.150  
   1.151  (defun YaTeX-prev-error ()
   1.152 @@ -311,7 +334,7 @@
   1.153  	error-line typeset-win error-buffer error-win)
   1.154      (if (null (get-buffer YaTeX-typeset-buffer))
   1.155  	(error "There is no typesetting buffer."))
   1.156 -    (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
   1.157 +    (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
   1.158      (setq typeset-win (selected-window))
   1.159      (if (re-search-backward
   1.160  	 (concat "\\(" latex-error-regexp "\\)\\|\\("
   1.161 @@ -397,8 +420,9 @@
   1.162    (if (null (get-buffer YaTeX-typeset-buffer))
   1.163        (message "No typeset buffer found.")
   1.164      (let ((win (selected-window)))
   1.165 -      (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
   1.166 +      (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
   1.167        (goto-char (point-max))
   1.168 +      (forward-line -1)
   1.169        (recenter -1)
   1.170        (select-window win)))
   1.171  )
   1.172 @@ -504,7 +528,8 @@
   1.173    "Print out.  If prefix arg ARG is non nil, call print driver without
   1.174  page range description."
   1.175    (interactive "P")
   1.176 -  (let*(from to (cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)))
   1.177 +  (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format))
   1.178 +	from to (lbuffer "*dvi-printing*"))
   1.179      (setq
   1.180       cmd 
   1.181       (YaTeX-replace-format
   1.182 @@ -534,7 +559,9 @@
   1.183  			 (format cmd (YaTeX-get-preview-file-name)))))
   1.184      (save-excursion
   1.185        (YaTeX-visit-main t) ;;change execution directory
   1.186 -      (with-output-to-temp-buffer "*dvi-printing*"
   1.187 +      (YaTeX-showup-buffer
   1.188 +       lbuffer (function (lambda (x) (nth 3 (window-edges x)))))
   1.189 +      (with-output-to-temp-buffer lbuffer
   1.190  	(if YaTeX-dos
   1.191  	    (call-process shell-file-name "con" "*dvi-printing*" nil
   1.192  			  "/c " cmd)
   1.193 @@ -565,7 +592,8 @@
   1.194      (if (setq b-in (YaTeX-get-builtin "!"))
   1.195  	(setq main-file (YaTeX-guess-parent b-in)))
   1.196      (if YaTeX-parent-file
   1.197 -	(setq main-file (get-file-buffer YaTeX-parent-file)))
   1.198 +	(setq main-file ;;(get-file-buffer YaTeX-parent-file)
   1.199 +	      YaTeX-parent-file))
   1.200      (if (YaTeX-main-file-p)
   1.201  	(if (interactive-p) (message "I think this is main LaTeX source.") nil)
   1.202        (cond
   1.203 @@ -632,47 +660,4 @@
   1.204  	    (buffer-list)))
   1.205  )
   1.206  
   1.207 -(defun YaTeX-pop-to-buffer (buffer &optional win)
   1.208 -  (if (setq win (get-buffer-window buffer))
   1.209 -      (select-window win)
   1.210 -    (pop-to-buffer buffer))
   1.211 -)
   1.212 -
   1.213 -(defun YaTeX-showup-buffer (buffer &optional func select)
   1.214 -  "Make BUFFER show up in certain window (but current window)
   1.215 -that gives the maximum value by the FUNC.  FUNC should take an argument
   1.216 -of its window object.  Non-nil for optional third argument SELECT selects
   1.217 -that window."
   1.218 -  (or (and (get-buffer-window buffer)
   1.219 -	   (progn (if select (select-window (get-buffer-window buffer)))
   1.220 -		  t))
   1.221 -      (cond
   1.222 -       ((> (length (YaTeX-window-list)) 2)
   1.223 -	(let ((window (selected-window))
   1.224 -	      (list (YaTeX-window-list)) win w (x 0))
   1.225 -	  (if func
   1.226 -	      (while list
   1.227 -		(setq w (car list))
   1.228 -		(if (and (not (eq window w))
   1.229 -			 (> (funcall func w) x))
   1.230 -		    (setq win w x (funcall func w)))
   1.231 -		(setq list (cdr list)))
   1.232 -	    (setq win (get-lru-window)))
   1.233 -	  (select-window win)
   1.234 -	  (switch-to-buffer buffer)
   1.235 -	  (or select (select-window window))))
   1.236 -       ((= (length (YaTeX-window-list)) 2)
   1.237 -	(let ((window (selected-window)))
   1.238 -	  (other-window 1)
   1.239 -	  (switch-to-buffer buffer)
   1.240 -	  (or select (select-window window))))
   1.241 -       (t nil)))
   1.242 -)
   1.243 -
   1.244 -(defun YaTeX-window-list ()
   1.245 -  (let*((curw (selected-window)) (win curw) (wlist (list curw)))
   1.246 -    (while (not (eq curw (setq win (next-window win))))
   1.247 -      (setq wlist (cons win wlist)))
   1.248 -    wlist)
   1.249 -)
   1.250  (provide 'yatexprc)