yatex

changeset 47:d7e7b4654058

Support special popup frame. Refine highlightening method. On Emacs-19, couldn't save user completion table correctly, fixed.
author yuuji
date Mon, 24 Oct 1994 17:26:47 +0000
parents cd1b63102eed
children a0640ff3f72f
files docs/yatexgen.doc yatex.el yatex.new yatex19.el yatexlib.el yatexmth.el yatexprc.el
diffstat 7 files changed, 762 insertions(+), 686 deletions(-) [+]
line diff
     1.1 --- a/docs/yatexgen.doc	Mon Sep 19 16:54:19 1994 +0000
     1.2 +++ b/docs/yatexgen.doc	Mon Oct 24 17:26:47 1994 +0000
     1.3 @@ -42,10 +42,10 @@
     1.4  	(実際にはないよー)
     1.5  
     1.6  		\epsinput[t](250,50){hoge.eps}{plain}{ほげほげの絵}
     1.7 -		         (a)  (b)     (1)      (2)      (3)
     1.8 -		(a)位置を指定するオプション引数(なくても良い)
     1.9 +		         (A)  (B)     (1)      (2)      (3)
    1.10 +		(A)位置を指定するオプション引数(なくても良い)
    1.11  		   t(top) b(bottom) l(left) r(right) のどれかが入る
    1.12 -		(b)枠の最大の大きさ
    1.13 +		(B)枠の最大の大きさ
    1.14  		(1)第1引数は取り込むEPSファイル名
    1.15  		(2)第2引数は取り込む時に
    1.16  			plain		何もしない
    1.17 @@ -67,8 +67,8 @@
    1.18  
    1.19    (o)追加型付加関数を作る
    1.20  
    1.21 -	(a),(b)の部分はオプション引数なので、追加型付加関数で補完します。
    1.22 -	(1)〜(3)は実際の引数なので引数型付加関数で補完します。では(a)を補
    1.23 +	(A),(B)の部分はオプション引数なので、追加型付加関数で補完します。
    1.24 +	(1)〜(3)は実際の引数なので引数型付加関数で補完します。では(A)を補
    1.25  	完するための関数を作りましょう。
    1.26  
    1.27  		M-x YaTeX-generate-simple RET
    1.28 @@ -90,14 +90,14 @@
    1.29  		Coord.		座標を読み込む
    1.30  		Quit		おしまい
    1.31  
    1.32 -	さて(a)はEPSファイルを配置する場所指定オプションなので補完タイプは 
    1.33 +	さて(A)はEPSファイルを配置する場所指定オプションなので補完タイプは 
    1.34  	Position、さらにその候補は t, b, l, r のどれかなので、以下のように
    1.35  	操作します。
    1.36  
    1.37  		Read type(1).... 		p
    1.38  		Acceptable characters:		tblr RET
    1.39  
    1.40 -	次の(b)は座標なので補完タイプは coOrd. 最大サイズと言う意味のプロ
    1.41 +	次の(B)は座標なので補完タイプは coOrd. 最大サイズと言う意味のプロ
    1.42  	ンプトを出したいので次のようにします。
    1.43  
    1.44  		Read type(2)....		o
     2.1 Binary file yatex.el has changed
     3.1 --- a/yatex.new	Mon Sep 19 16:54:19 1994 +0000
     3.2 +++ b/yatex.new	Mon Oct 24 17:26:47 1994 +0000
     3.3 @@ -1,6 +1,12 @@
     3.4  	Yet Another tex-mode for Emacs
     3.5  	yatex.el 各バージョンの変更点について。
     3.6  
     3.7 +1.52	外部プロセス用テンポラリバッファが別frameにある時には現frameにテ
     3.8 +	ンポラリバッファをpopupしないようにした。
     3.9 +	Hilightening に独自のタグを導入し、reverseVideo がON/OFFの時両方
    3.10 +	に対応した。
    3.11 +	Emacs-19で新単語の更新がうまくいかなかったのを直した。
    3.12 +
    3.13  1.51	メニューバーへのメニュー登録。
    3.14  	YaTeX-fill-item(C-c C-i) と YaTeX-indent-line (C-i)が賢くなった。
    3.15  	hilit19をロードしておくとセクション区切りが目立つように色が付く。
     4.1 --- a/yatex19.el	Mon Sep 19 16:54:19 1994 +0000
     4.2 +++ b/yatex19.el	Mon Oct 24 17:26:47 1994 +0000
     4.3 @@ -1,7 +1,7 @@
     4.4  ;;; -*- Emacs-Lisp -*-
     4.5  ;;; YaTeX facilities for Emacs 19
     4.6  ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     4.7 -;;; Last modified Sat Sep 17 12:53:23 1994 on figaro
     4.8 +;;; Last modified Fri Sep 23 04:30:27 1994 on figaro
     4.9  ;;; $Id$
    4.10  
    4.11  ;;; $B$H$j$"$($:(B hilit19 $B$r;H$C$F$$$k;~$K?'$,IU$/$h$&$K$7$F(B
    4.12 @@ -9,6 +9,8 @@
    4.13  ;;; $B$$$C$?$$C/$,%a%K%e!<%P!<;H$C$F(BLaTeX$B%=!<%9=q$/$s$@$m$&$+(B?
    4.14  ;;; $B$^$"$$$$$dN}=,N}=,!#8e$m$NJ}$K$A$g$C$H%3%a%s%H$"$j!#(B
    4.15  
    4.16 +(require 'yatex)
    4.17 +
    4.18  (defun YaTeX-19-define-sub-menu (map vec &rest bindings)
    4.19    "Define sub-menu-item in MAP at vector VEC as BINDINGS.
    4.20  BINDINGS is a form with optional length: (symbol title binding).
    4.21 @@ -111,7 +113,7 @@
    4.22   '(comment	"Comment region or environment" YaTeX-comment-region)
    4.23   '(uncomment	"Unomment region or environment" YaTeX-uncomment-region)
    4.24   '(commentp	"Comment paragraph" YaTeX-comment-paragraph)
    4.25 - '(uncommentp	"Unomment paragraph" YaTeX-uncomment-paragraph)
    4.26 + '(uncommentp	"Uncomment paragraph" YaTeX-uncomment-paragraph)
    4.27   '(sepcom	"--"	nil)
    4.28  )
    4.29  
    4.30 @@ -139,7 +141,7 @@
    4.31    (cons "Section-type region(long name)"
    4.32  	(make-sparse-keymap "Enclose region with section-type macro")))
    4.33  (define-key YaTeX-mode-map [menu-bar yatex section]
    4.34 -  (cons "Sectio-type(long name)"
    4.35 +  (cons "Section-type(long name)"
    4.36  	(make-sparse-keymap "Section-type macro")))
    4.37  (let ((sorted-section
    4.38         (sort
    4.39 @@ -214,12 +216,23 @@
    4.40      'sectioning))
    4.41    "Adjustment for hilit19's LaTeX hilit pattern.")
    4.42  (defvar YaTeX-hilit-sectioning-face
    4.43 -  'yellow/cornflowerblue)
    4.44 +  '(yellow/dodgerblue yellow/cornflowerblue))
    4.45 +(defvar YaTeX-hilit-singlecmd-face
    4.46 +  '(slateblue2 aquamarine))
    4.47  (defun YaTeX-19-collect-macro ()
    4.48    (cond
    4.49     ((and (featurep 'hilit19) (fboundp 'hilit-translate))
    4.50 -    (hilit-translate sectioning YaTeX-hilit-sectioning-face)
    4.51 -    (setq hilit-patterns-alist		;Remove at the first time.
    4.52 +    (let ((get-face
    4.53 +	   (function
    4.54 +	    (lambda (table)
    4.55 +	      (cond
    4.56 +	       ((eq hilit-background-mode 'light) (car table))
    4.57 +	       ((eq hilit-background-mode 'dark) (car (cdr table)))
    4.58 +	       (t nil))))))
    4.59 +      (hilit-translate
    4.60 +       sectioning (funcall get-face YaTeX-hilit-sectioning-face)
    4.61 +       macro (funcall get-face YaTeX-hilit-singlecmd-face)))
    4.62 +    (setq hilit-patterns-alist		;Remove at first.
    4.63  	  (delq 'yatex-mode hilit-patterns-alist)
    4.64  	  hilit-patterns-alist
    4.65  	  (cons
    4.66 @@ -235,7 +248,15 @@
    4.67  			     (append user-section-table tmp-section-table)
    4.68  			     "\\|")
    4.69  			    "\\){")
    4.70 -		    "}" 'keyword))))
    4.71 +		    "}" 'keyword)
    4.72 +		   (list
    4.73 +		    (concat "\\\\\\("
    4.74 +			    (mapconcat
    4.75 +			     (function (lambda (s) (regexp-quote (car s))))
    4.76 +			     (append user-singlecmd-table tmp-singlecmd-table)
    4.77 +			     "\\|")
    4.78 +			    "\\)")
    4.79 +		    0 'macro))))
    4.80  	   hilit-patterns-alist)))))
    4.81  (YaTeX-19-collect-macro)
    4.82  (defun YaTeX-hilit-recenter (arg)
     5.1 --- a/yatexlib.el	Mon Sep 19 16:54:19 1994 +0000
     5.2 +++ b/yatexlib.el	Mon Oct 24 17:26:47 1994 +0000
     5.3 @@ -2,7 +2,7 @@
     5.4  ;;; YaTeX library of general functions.
     5.5  ;;; yatexlib.el
     5.6  ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     5.7 -;;; Last modified Fri Sep 16 01:50:34 1994 on figaro
     5.8 +;;; Last modified Mon Oct 10 22:14:14 1994 on VFR
     5.9  ;;; $Id$
    5.10  
    5.11  ;;;###autoload
    5.12 @@ -123,9 +123,25 @@
    5.13  that gives the maximum value by the FUNC.  FUNC should take an argument
    5.14  of its window object.  Non-nil for optional third argument SELECT selects
    5.15  that window."
    5.16 -  (or (and (get-buffer-window buffer)
    5.17 -	   (progn (if select (select-window (get-buffer-window buffer)))
    5.18 -		  t))
    5.19 +  (or (and (if YaTeX-emacs-19
    5.20 +	       (get-buffer-window buffer t)
    5.21 +	     (get-buffer-window buffer))
    5.22 +	   (progn
    5.23 +	     (if select
    5.24 +		 (cond
    5.25 +		  (YaTeX-emacs-19
    5.26 +		   (let ((frame (window-frame (get-buffer-window buffer t))))
    5.27 +		     (select-frame frame)
    5.28 +		     (focus-frame frame)
    5.29 +		     (set-mouse-position frame 0 0)
    5.30 +		     (raise-frame frame)
    5.31 +		     (select-window (get-buffer-window buffer))
    5.32 +		     (if (and (featurep 'windows)
    5.33 +			      (win:frame-window frame))
    5.34 +			 (win:adjust-window))))
    5.35 +		  (t
    5.36 +		   (select-window (get-buffer-window buffer)))))
    5.37 +	     t))
    5.38        (let ((window (selected-window))
    5.39  	    (wlist (YaTeX-window-list)) win w (x 0))
    5.40  	(cond
    5.41 @@ -147,6 +163,8 @@
    5.42  	  (or select (select-window window)))
    5.43  	 (t				;if one-window
    5.44  	  (cond
    5.45 +	   ((and YaTeX-emacs-19 (get-buffer-window buffer t))
    5.46 +	    nil)			;if found in other frame
    5.47  	   (YaTeX-default-pop-window-height
    5.48  	    (split-window
    5.49  	     (selected-window)
    5.50 @@ -182,7 +200,7 @@
    5.51  where ever it appears."
    5.52    (mapcar
    5.53     (function (lambda (key) (define-key keymap key newdef)))
    5.54 -   (where-is-internal olddef))
    5.55 +   (where-is-internal olddef keymap))
    5.56  )
    5.57  
    5.58  ;;;###autoload
     6.1 --- a/yatexmth.el	Mon Sep 19 16:54:19 1994 +0000
     6.2 +++ b/yatexmth.el	Mon Oct 24 17:26:47 1994 +0000
     6.3 @@ -2,7 +2,7 @@
     6.4  ;;; YaTeX math-mode-specific functions.
     6.5  ;;; yatexmth.el rev.2
     6.6  ;;; (c )1993-1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
     6.7 -;;; Last modified Thu Jul 14 22:42:05 1994 on figaro
     6.8 +;;; Last modified Tue Oct 11 22:57:43 1994 on figaro
     6.9  ;;; $Id$
    6.10  
    6.11  ;;; [Customization guide]
    6.12 @@ -214,7 +214,7 @@
    6.13     ("==>"	"Longrightarrow" "==>")
    6.14     ("<->"	"leftrightarrow" ("<->"		"←→"))
    6.15     ("<-->"	"longleftrightarrow" ("<---->"	"←--→"))
    6.16 -   ("<=>"	"leftrightarrow" "<=>")
    6.17 +   ("<=>"	"Leftrightarrow" "<=>")
    6.18     ("<==>"	"Longleftrightarrow" "<==>")
    6.19     ("^|"	"uparrow"	("^\n|" "↑"))
    6.20     ("\C-p"	"uparrow"	("^\n|" "↑"))
     7.1 --- a/yatexprc.el	Mon Sep 19 16:54:19 1994 +0000
     7.2 +++ b/yatexprc.el	Mon Oct 24 17:26:47 1994 +0000
     7.3 @@ -1,665 +1,696 @@
     7.4 -;;; -*- Emacs-Lisp -*-
     7.5 -;;; YaTeX process handler.
     7.6 -;;; yatexprc.el
     7.7 -;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     7.8 -;;; Last modified Fri Sep 16 01:50:36 1994 on figaro
     7.9 -;;; $Id$
    7.10 -
    7.11 -(require 'yatex)
    7.12 -
    7.13 -(defvar YaTeX-typeset-process nil
    7.14 -  "Process identifier for jlatex"
    7.15 -)
    7.16 -(defvar YaTeX-typeset-buffer "*YaTeX-typesetting*"
    7.17 -  "Process buffer for jlatex")
    7.18 -
    7.19 -(defvar YaTeX-typeset-buffer-syntax nil
    7.20 -  "*Syntax table for typesetting buffer")
    7.21 -
    7.22 -(defvar YaTeX-current-TeX-buffer nil
    7.23 -  "Keeps the buffer on which recently typeset run.")
    7.24 -
    7.25 -(if YaTeX-typeset-buffer-syntax nil
    7.26 -  (setq YaTeX-typeset-buffer-syntax
    7.27 -	(make-syntax-table (standard-syntax-table)))
    7.28 -  (modify-syntax-entry ?\{ "w" YaTeX-typeset-buffer-syntax)
    7.29 -  (modify-syntax-entry ?\} "w" YaTeX-typeset-buffer-syntax)
    7.30 -  (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax)
    7.31 -  (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax)
    7.32 -)
    7.33 -
    7.34 -(defun YaTeX-typeset (command buffer)
    7.35 -  "Execute jlatex (or other) to LaTeX typeset."
    7.36 -  (interactive)
    7.37 -  (let ((window (selected-window)))
    7.38 -    (if (and YaTeX-typeset-process
    7.39 -	     (eq (process-status YaTeX-typeset-process) 'run))
    7.40 -	;; if tex command is halting.
    7.41 -	(YaTeX-kill-typeset-process YaTeX-typeset-process))
    7.42 -    (YaTeX-visit-main t);;execution directory
    7.43 -    ;;Select lower-most window if there are more than 2 windows and
    7.44 -    ;;typeset buffer not seen.
    7.45 -    (YaTeX-showup-buffer
    7.46 -     buffer (function (lambda (x) (nth 3 (window-edges x)))))
    7.47 -    (with-output-to-temp-buffer buffer
    7.48 -      (if YaTeX-dos			;if MS-DOS
    7.49 -	  (progn
    7.50 -	    (message (format "Calling `%s'..." command))
    7.51 -	    (YaTeX-put-nonstopmode)
    7.52 -	    (call-process shell-file-name
    7.53 -			  nil buffer nil "/c" command)
    7.54 -	    (YaTeX-remove-nonstopmode))
    7.55 -	(setq YaTeX-typeset-process	;if UNIX
    7.56 -	      (start-process "LaTeX" buffer shell-file-name "-c"
    7.57 -			     command))
    7.58 -	(set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
    7.59 -    (setq YaTeX-current-TeX-buffer (buffer-name))
    7.60 -    (select-window (get-buffer-window buffer))
    7.61 -    (use-local-map YaTeX-typesetting-mode-map)
    7.62 -    (set-syntax-table YaTeX-typeset-buffer-syntax)
    7.63 -    (setq mode-name "typeset")
    7.64 -    (if YaTeX-typeset-process		; if process is running (maybe on UNIX)
    7.65 -	(cond ((boundp 'MULE)
    7.66 -	       (set-current-process-coding-system
    7.67 -		YaTeX-latex-message-code YaTeX-coding-system))
    7.68 -	      ((boundp 'NEMACS)
    7.69 -	       (set-kanji-process-code YaTeX-latex-message-code))))
    7.70 -    (goto-char (point-max))
    7.71 -    (if YaTeX-dos (message "Done.")
    7.72 -      (insert " ")
    7.73 -      (set-marker (process-mark YaTeX-typeset-process) (1- (point))))
    7.74 -    (if (bolp) (forward-line -1))
    7.75 -    (recenter -1)
    7.76 -    (select-window window))
    7.77 -)
    7.78 -
    7.79 -(defun YaTeX-typeset-sentinel (proc mes)
    7.80 -  (cond ((null (buffer-name (process-buffer proc)))
    7.81 -         ;; buffer killed
    7.82 -         (set-process-buffer proc nil))
    7.83 -        ((memq (process-status proc) '(signal exit))
    7.84 -         (let* ((obuf (current-buffer)) (pbuf (process-buffer proc))
    7.85 -		(pwin (get-buffer-window pbuf))
    7.86 -		(owin (selected-window)) win)
    7.87 -           ;; save-excursion isn't the right thing if
    7.88 -           ;;  process-buffer is current-buffer
    7.89 -           (unwind-protect
    7.90 -               (progn
    7.91 -                 ;; Write something in *typesetting* and hack its mode line
    7.92 -		 (if pwin
    7.93 -		     (select-window pwin)
    7.94 -		   (set-buffer pbuf))
    7.95 -		 ;;(YaTeX-showup-buffer pbuf nil t)
    7.96 -                 (goto-char (point-max))
    7.97 -		 (if pwin (recenter -3))
    7.98 -                 (insert ?\n "latex typesetting " mes)
    7.99 -                 (forward-char -1)
   7.100 -                 (insert " at " (substring (current-time-string) 0 -5) "\n")
   7.101 -                 (forward-char 1)
   7.102 -                 (setq mode-line-process
   7.103 -                       (concat ": "
   7.104 -                               (symbol-name (process-status proc))))
   7.105 -		 (message "latex typesetting done.")
   7.106 -                 ;; If buffer and mode line shows that the process
   7.107 -                 ;; is dead, we can delete it now.  Otherwise it
   7.108 -                 ;; will stay around until M-x list-processes.
   7.109 -                 (delete-process proc)
   7.110 -		 )
   7.111 -             (setq YaTeX-typesetting-process nil)
   7.112 -             ;; Force mode line redisplay soon
   7.113 -             (set-buffer-modified-p (buffer-modified-p))
   7.114 -	     )
   7.115 -	   (select-window owin)
   7.116 -	   (set-buffer obuf))))
   7.117 -)
   7.118 -
   7.119 -(defvar YaTeX-texput-file "texput.tex"
   7.120 -  "*File name for temporary file of typeset-region."
   7.121 -)
   7.122 -
   7.123 -(defun YaTeX-typeset-region ()
   7.124 -  "Paste the region to the file `texput.tex' and execute jlatex (or other)
   7.125 -to LaTeX typeset.  The region is specified by the rule:
   7.126 -	(1)If keyword `%#BEGIN' is found in the upper direction from (point).
   7.127 -	  (1-1)if the keyword `%#END' is found after `%#BEGIN',
   7.128 -		->Assume the text between `%#BEGIN' and `%#END' as region.
   7.129 -	  (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN',
   7.130 -		->Assume the text after `%#BEGIN' as region.
   7.131 -	(2)If no `%#BEGIN' usage is found before the (point),
   7.132 -		->Assume the text between current (point) and (mark) as region.
   7.133 -DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing
   7.134 -operation to the region."
   7.135 -  (interactive)
   7.136 -  (save-excursion
   7.137 -    (let*
   7.138 -	((end "") typeout ;Type out message that tells the method of cutting.
   7.139 -	 (cmd (concat (YaTeX-get-latex-command nil) " " YaTeX-texput-file))
   7.140 -	 (buffer (current-buffer)) opoint preamble (subpreamble "") main
   7.141 -	 reg-begin reg-end)
   7.142 -
   7.143 -      (save-excursion
   7.144 -	(if (search-backward "%#BEGIN" nil t)
   7.145 -	    (progn
   7.146 -	      (setq typeout "--- Region from BEGIN to "
   7.147 -		    end "the end of the buffer ---"
   7.148 -		    reg-begin (match-end 0))
   7.149 -	      (if (search-forward "%#END" nil t)
   7.150 -		  (setq reg-end (match-beginning 0)
   7.151 -			end "END ---")
   7.152 -		(setq reg-end (point-max))))
   7.153 -	  (setq typeout "=== Region from (point) to (mark) ===")
   7.154 -	  (setq reg-begin (point) reg-end (mark)))
   7.155 -	(goto-char (point-min))
   7.156 -	(while (search-forward "%#REQUIRE" nil t)
   7.157 -	  (setq subpreamble
   7.158 -		(concat subpreamble
   7.159 -			(cond
   7.160 -			 ((eolp)
   7.161 -			  (buffer-substring
   7.162 -			   (match-beginning 0)
   7.163 -			   (point-beginning-of-line)))
   7.164 -			 (t (buffer-substring
   7.165 -			     (match-end 0)
   7.166 -			     (point-end-of-line))))
   7.167 -			"\n"))
   7.168 -	  (goto-char (match-end 0))))
   7.169 -      (YaTeX-visit-main t)
   7.170 -      (setq main (current-buffer))
   7.171 -      (setq opoint (point))
   7.172 -      (goto-char (point-min))
   7.173 -      (setq
   7.174 -       preamble
   7.175 -       (if (re-search-forward "^[ 	]*\\\\begin.*{document}" nil t)
   7.176 -	   (buffer-substring (point-min) (match-end 0))
   7.177 -	 (concat "\\documentstyle{" YaTeX-default-document-style "}\n"
   7.178 -		 "\\begin{document}")))
   7.179 -      (goto-char opoint)
   7.180 -      ;;(set-buffer buffer)		;for clarity
   7.181 -      (set-buffer (find-file-noselect YaTeX-texput-file))
   7.182 -      ;;(find-file YaTeX-texput-file)
   7.183 -      (erase-buffer)
   7.184 -      (if YaTeX-need-nonstop
   7.185 -	  (insert "\\nonstopmode{}\n"))
   7.186 -      (insert preamble "\n" subpreamble "\n")
   7.187 -      (insert-buffer-substring buffer reg-begin reg-end)
   7.188 -      (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
   7.189 -      (insert "\n\\end{document}\n")
   7.190 -      (basic-save-buffer)
   7.191 -      (kill-buffer (current-buffer))
   7.192 -      (set-buffer main)		;return to parent file or itself.
   7.193 -      (YaTeX-typeset cmd YaTeX-typeset-buffer)
   7.194 -      (switch-to-buffer buffer)		;for Emacs-19
   7.195 -      (put 'dvi2-command 'region t)))
   7.196 -)
   7.197 -
   7.198 -(defun YaTeX-typeset-buffer ()
   7.199 -  "Typeset whole buffer.  If %#! usage says other buffer is main text,
   7.200 -visit main buffer to confirm if its includeonly list contains current
   7.201 -buffer's file.  And if it doesn't contain editing text, ask user which
   7.202 -action wants to be done, A:Add list, R:Replace list, %:comment-out list."
   7.203 -  (interactive)
   7.204 -  (YaTeX-save-buffers)
   7.205 -  (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.)))
   7.206 -	(mydir (file-name-directory (buffer-file-name)))
   7.207 -	(cmd (YaTeX-get-latex-command t)))
   7.208 -    (if (YaTeX-main-file-p) nil
   7.209 -      (save-excursion
   7.210 -	(YaTeX-visit-main t)	;search into main buffer
   7.211 -	(save-excursion
   7.212 -	  (push-mark (point) t)
   7.213 -	  (goto-char (point-min))
   7.214 -	  (if (and (re-search-forward "^[ 	]*\\\\begin{document}" nil t)
   7.215 -		   (re-search-backward "^[ 	]*\\\\includeonly{" nil t))
   7.216 -	      (let*
   7.217 -		  ((b (progn (skip-chars-forward "^{") (point)))
   7.218 -		   (e (progn (skip-chars-forward "^}") (1+ (point))))
   7.219 -		   (s (buffer-substring b e)) c
   7.220 -		   (pardir (file-name-directory (buffer-file-name))))
   7.221 -		(if (string-match (concat "[{,/]" me "[,}]") s)
   7.222 -		    nil ; Nothing to do when it's already in includeonly.
   7.223 -		  (ding)
   7.224 -		  (switch-to-buffer (current-buffer));Display this buffer.
   7.225 -		  (setq
   7.226 -		   me	  ;;Rewrite my name(me) to contain sub directory name.
   7.227 -		   (concat
   7.228 -		    (if (string-match pardir mydir) ;if mydir is child of main
   7.229 -			(substring mydir (length pardir)) ;cut absolute path
   7.230 -		      mydir) ;else concat absolute path name.
   7.231 -		    me))
   7.232 -		  (message
   7.233 -		   "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? "
   7.234 -		   me)
   7.235 -		  (setq c (read-char))
   7.236 -		  (cond
   7.237 -		   ((= c ?a)
   7.238 -		    (goto-char (1+ b))
   7.239 -		    (insert me (if (string= s "{}") "" ",")))
   7.240 -		   ((= c ?r)
   7.241 -		    (delete-region (1+ b) (1- e)) (insert me))
   7.242 -		   ((= c ?%)
   7.243 -		    (beginning-of-line) (insert "%"))
   7.244 -		   (t nil))
   7.245 -		  (basic-save-buffer))))
   7.246 -	  (exchange-point-and-mark))
   7.247 -	))
   7.248 -    (YaTeX-typeset cmd YaTeX-typeset-buffer)
   7.249 -    (put 'dvi2-command 'region nil))
   7.250 -)
   7.251 -
   7.252 -(defvar YaTeX-call-command-history nil
   7.253 -  "Holds history list of YaTeX-call-command-on-file.")
   7.254 -(put 'YaTeX-call-command-history 'no-default t)
   7.255 -(defun YaTeX-call-command-on-file (base-cmd buffer)
   7.256 -  (YaTeX-save-buffers)
   7.257 -  (YaTeX-typeset
   7.258 -   (let ((minibufer-history-symbol 'YaTeX-call-command-history))
   7.259 -     (read-string "Call command: "
   7.260 -		  (concat base-cmd " " (YaTeX-get-preview-file-name))))
   7.261 -   buffer)
   7.262 -)
   7.263 -
   7.264 -(defun YaTeX-bibtex-buffer (cmd)
   7.265 -  "Pass the bibliography data of editing file to bibtex."
   7.266 -  (interactive)
   7.267 -  (YaTeX-save-buffers)
   7.268 -  (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" )
   7.269 -)
   7.270 -
   7.271 -(defun YaTeX-kill-typeset-process (proc)
   7.272 -  "Kill process PROC after sending signal to PROC.
   7.273 -PROC should be process identifier."
   7.274 -  (cond
   7.275 -   (YaTeX-dos
   7.276 -    (error "MS-DOS can't have concurrent process."))
   7.277 -   ((or (null proc) (not (eq (process-status proc) 'run)))
   7.278 -    (error "No typesetting process."))
   7.279 -   (t (interrupt-process proc)
   7.280 -      (delete-process proc)))
   7.281 -)
   7.282 -
   7.283 -(defun YaTeX-system (command buffer)
   7.284 -  "Execute some command on buffer.  Not a official function."
   7.285 -  (save-excursion
   7.286 -    (YaTeX-showup-buffer
   7.287 -     buffer (function (lambda (x) (nth 3 (window-edges x)))))
   7.288 -    (with-output-to-temp-buffer buffer
   7.289 -      (if YaTeX-dos
   7.290 -	  (call-process shell-file-name nil buffer nil "/c " command)
   7.291 -	(start-process "system" buffer shell-file-name "-c" command))))
   7.292 -)
   7.293 -
   7.294 -(defvar YaTeX-preview-command-history nil
   7.295 -  "Holds minibuffer history of preview command.")
   7.296 -(put 'YaTeX-preview-command-history 'no-default t)
   7.297 -(defvar YaTeX-preview-file-history nil
   7.298 -  "Holds minibuffer history of file to preview.")
   7.299 -(put 'YaTeX-preview-file-history 'no-default t)
   7.300 -(defun YaTeX-preview (preview-command preview-file)
   7.301 -  "Execute xdvi (or other) to tex-preview."
   7.302 -  (interactive
   7.303 -   (list
   7.304 -    (let ((minibuffer-history-symbol 'YaTeX-preview-command-history))
   7.305 -      (read-string "Preview command: " dvi2-command))
   7.306 -    (let ((minibuffer-history-symbol 'YaTeX-preview-file-history))
   7.307 -      (read-string "Preview file[.dvi]: "
   7.308 -		   (if (get 'dvi2-command 'region)
   7.309 -		       (substring YaTeX-texput-file
   7.310 -				  0 (rindex YaTeX-texput-file ?.))
   7.311 -		     (YaTeX-get-preview-file-name))
   7.312 -		   ))))
   7.313 -  (setq dvi2-command preview-command)	;`dvi2command' is buffer local
   7.314 -  (save-excursion
   7.315 -    (YaTeX-visit-main t)
   7.316 -    (let ((pbuffer "*dvi-preview*"))
   7.317 -      (YaTeX-showup-buffer
   7.318 -       pbuffer (function (lambda (x) (nth 3 (window-edges x)))))
   7.319 -      (with-output-to-temp-buffer pbuffer
   7.320 -	(if YaTeX-dos			;if MS-DOS
   7.321 -	    (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
   7.322 -		   (call-process shell-file-name "con" "*dvi-preview*" nil
   7.323 -				 "/c " preview-command preview-file)
   7.324 -		   (send-string-to-terminal "\e[>5l") ;show cursor
   7.325 -		   (redraw-display))
   7.326 -	  (start-process "preview" "*dvi-preview*" shell-file-name "-c"
   7.327 -			 (concat preview-command " " preview-file)) ;if UNIX
   7.328 -	  (message
   7.329 -	   (concat "Starting " preview-command
   7.330 -		   " to preview " preview-file))))))
   7.331 -)
   7.332 -
   7.333 -(defun YaTeX-prev-error ()
   7.334 -  "Visit previous typeset error.
   7.335 -  To avoid making confliction of line numbers by editing, jump to
   7.336 -error or warning lines in reverse order."
   7.337 -  (interactive)
   7.338 -  (let ((cur-buf (buffer-name)) (cur-win (selected-window))
   7.339 -	error-line typeset-win error-buffer error-win)
   7.340 -    (if (null (get-buffer YaTeX-typeset-buffer))
   7.341 -	(error "There is no typesetting buffer."))
   7.342 -    (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
   7.343 -    (setq typeset-win (selected-window))
   7.344 -    (if (re-search-backward
   7.345 -	 (concat "\\(" latex-error-regexp "\\)\\|\\("
   7.346 -		 latex-warning-regexp "\\)")
   7.347 -	 nil t)
   7.348 -	nil
   7.349 -      (select-window cur-win)
   7.350 -      (error "No more erros on %s" cur-buf))
   7.351 -    (goto-char (match-beginning 0))
   7.352 -    (skip-chars-forward "^0-9" (match-end 0))
   7.353 -    (setq error-line
   7.354 -	  (string-to-int
   7.355 -	   (buffer-substring
   7.356 -	    (point)
   7.357 -	    (progn (skip-chars-forward "0-9" (match-end 0)) (point))))
   7.358 -	  error-buffer (YaTeX-get-error-file cur-buf)
   7.359 -	  error-win (get-buffer-window error-buffer))
   7.360 -    (if (or (null error-line) (equal 0 error-line))
   7.361 -	(error "Can't detect error position."))
   7.362 -    (select-window cur-win)
   7.363 -    (cond
   7.364 -     (error-win (select-window error-win))
   7.365 -     ((eq (get-lru-window) typeset-win)
   7.366 -      (YaTeX-switch-to-buffer error-buffer))
   7.367 -     (t (select-window (get-lru-window))
   7.368 -	(YaTeX-switch-to-buffer error-buffer)))
   7.369 -    (setq error-win (selected-window))
   7.370 -    (goto-line error-line)
   7.371 -    (message "LaTeX %s in `%s' on line: %d."
   7.372 -	     (if (match-beginning 1) "error" "warning")
   7.373 -	     error-buffer error-line)
   7.374 -    (select-window typeset-win)
   7.375 -    (skip-chars-backward "0-9")
   7.376 -    (recenter (/ (window-height) 2))
   7.377 -    (sit-for 3)
   7.378 -    (goto-char (match-beginning 0))
   7.379 -    (select-window error-win))
   7.380 -)
   7.381 -
   7.382 -(defun YaTeX-jump-error-line ()
   7.383 -  "Jump to corresponding line on latex command's error message."
   7.384 -  (interactive)
   7.385 -  (let (error-line error-file error-buf)
   7.386 -    (save-excursion
   7.387 -      (beginning-of-line)
   7.388 -      (setq error-line (re-search-forward "l[ ines]*\\.\\([1-9][0-9]*\\)"
   7.389 -					  (point-end-of-line) t)))
   7.390 -    (if (null error-line)
   7.391 -	(if (eobp) (insert (this-command-keys))
   7.392 -	  (error "No line number expression."))
   7.393 -      (goto-char (match-beginning 0))
   7.394 -      (setq error-line (string-to-int
   7.395 -			(buffer-substring (match-beginning 1) (match-end 1)))
   7.396 -	    error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)
   7.397 -	    error-buf (YaTeX-switch-to-buffer error-file t))
   7.398 -      (if (null error-buf)
   7.399 -	  (error "`%s' is not found in this directory." error-file))
   7.400 -      (YaTeX-showup-buffer error-buf nil t)
   7.401 -      (goto-line error-line)))
   7.402 -)
   7.403 -
   7.404 -(defun YaTeX-send-string ()
   7.405 -  "Send string to current typeset process."
   7.406 -  (interactive)
   7.407 -  (if (and (eq (process-status YaTeX-typeset-process) 'run)
   7.408 -	   (>= (point) (process-mark YaTeX-typeset-process)))
   7.409 -      (let ((b (process-mark YaTeX-typeset-process))
   7.410 -	    (e (point-end-of-line)))
   7.411 -	(goto-char b)
   7.412 -	(skip-chars-forward " \t" e)
   7.413 -	(setq b (point))
   7.414 -	(process-send-string
   7.415 -	 YaTeX-typeset-process (concat (buffer-substring b e) "\n"))
   7.416 -	(goto-char e)
   7.417 -	(insert "\n")
   7.418 -	(set-marker (process-mark YaTeX-typeset-process) (point))
   7.419 -	(insert " "))
   7.420 -    (ding))
   7.421 -)
   7.422 -
   7.423 -(defun YaTeX-view-error ()
   7.424 -  (interactive)
   7.425 -  (if (null (get-buffer YaTeX-typeset-buffer))
   7.426 -      (message "No typeset buffer found.")
   7.427 -    (let ((win (selected-window)))
   7.428 -      (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
   7.429 -      (goto-char (point-max))
   7.430 -      (forward-line -1)
   7.431 -      (recenter -1)
   7.432 -      (select-window win)))
   7.433 -)
   7.434 -
   7.435 -(defun YaTeX-get-error-file (default)
   7.436 -  "Get current processing file from typesetting log."
   7.437 -  (save-excursion
   7.438 -    (let(s)
   7.439 -      (condition-case () (up-list -1)
   7.440 -	(error
   7.441 -	 (let ((list 0) found)
   7.442 -	   (while
   7.443 -	       (and (<= list 0) (not found)
   7.444 -		    (re-search-backward "\\((\\)\\|\\()\\)" nil t))
   7.445 -	     (if (equal (match-beginning 0) (match-beginning 2)) ;close paren.
   7.446 -		 (setq list (1- list)) ;open paren
   7.447 -	       (setq list (1+ list))
   7.448 -	       (if (= list 1)
   7.449 -		   (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty")
   7.450 -		       (setq found t)
   7.451 -		     (setq list (1- list)))))))))
   7.452 -      (setq s
   7.453 -	    (buffer-substring
   7.454 -	     (progn (forward-char 1) (point))
   7.455 -	     (progn (skip-chars-forward "-A-Za-z0-9_/\.\\" (point-end-of-line))
   7.456 -		    (point))))
   7.457 -      (if (string= "" s) default s)))
   7.458 -)
   7.459 -      
   7.460 -(defun YaTeX-put-nonstopmode ()
   7.461 -  (if YaTeX-need-nonstop
   7.462 -      (if (re-search-backward "\\\\nonstopmode{}" (point-min) t)
   7.463 -	  nil                    ;if already written in text then do nothing
   7.464 -	(save-excursion
   7.465 -	  (YaTeX-visit-main t)
   7.466 -	  (goto-char (point-min))
   7.467 -	  (insert "\\nonstopmode{}%_YaTeX_%\n")))
   7.468 -    )
   7.469 -)
   7.470 -
   7.471 -(defun YaTeX-remove-nonstopmode ()
   7.472 -  (if YaTeX-need-nonstop ;for speed
   7.473 -      (save-excursion
   7.474 -	(YaTeX-visit-main t)
   7.475 -	(goto-char (point-min))
   7.476 -	(forward-line 1)
   7.477 -	(narrow-to-region (point-min) (point))
   7.478 -	(goto-char (point-min))
   7.479 -	(delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$")
   7.480 -	(widen)))
   7.481 -)
   7.482 -
   7.483 -(defun YaTeX-get-preview-file-name ()
   7.484 -  "Get file name to preview by inquiring YaTeX-get-latex-command"
   7.485 -  (let* ((latex-cmd (YaTeX-get-latex-command t))
   7.486 -	 (rin (rindex latex-cmd ? ))
   7.487 -	 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
   7.488 -	 (period))
   7.489 -    (if (string= fname "")
   7.490 -	(setq fname (substring (file-name-nondirectory
   7.491 -				(buffer-file-name))
   7.492 -			       0 -4))
   7.493 -      (setq period (rindex fname ?.))
   7.494 -      (setq fname (substring fname 0 (if (eq -1 period) nil period)))
   7.495 -      ))
   7.496 -)
   7.497 -
   7.498 -(defun YaTeX-get-latex-command (&optional switch)
   7.499 -  "Specify the latex-command name and its argument.
   7.500 -If there is a line which begins with string: \"%#!\", the following
   7.501 -strings are assumed to be the latex-command and arguments.  The
   7.502 -default value of latex-command is:
   7.503 -	tex-command FileName
   7.504 -and if you write \"%#!jlatex\" in the beginning of certain line.
   7.505 -	\"jlatex \" FileName
   7.506 -will be the latex-command,
   7.507 -and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
   7.508 -is non-nil, then
   7.509 -	\"jlatex main.tex\"
   7.510 -
   7.511 -will be given to the shell."
   7.512 -  (let (magic command target)
   7.513 -    (setq parent
   7.514 -	  (cond
   7.515 -	   (YaTeX-parent-file YaTeX-parent-file)
   7.516 -	   (t (save-excursion
   7.517 -		(YaTeX-visit-main t)
   7.518 -		(file-name-nondirectory (buffer-file-name)))))
   7.519 -	  magic (YaTeX-get-builtin "!"))
   7.520 -    (cond
   7.521 -     (magic
   7.522 -      (cond
   7.523 -       (switch (if (string-match "\\s " magic) magic
   7.524 -		 (concat magic " " parent)))
   7.525 -       (t (concat (substring magic 0 (string-match "\\s " magic)) " "))))
   7.526 -     (t (concat tex-command " " (if switch parent)))))
   7.527 -)
   7.528 -
   7.529 -(defvar YaTeX-lpr-command-history nil
   7.530 -  "Holds command line history of YaTeX-lpr.")
   7.531 -(put 'YaTeX-lpr-command-history 'no-default t)
   7.532 -(defun YaTeX-lpr (arg)
   7.533 -  "Print out.  If prefix arg ARG is non nil, call print driver without
   7.534 -page range description."
   7.535 -  (interactive "P")
   7.536 -  (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format))
   7.537 -	from to (lbuffer "*dvi-printing*"))
   7.538 -    (setq
   7.539 -     cmd 
   7.540 -     (YaTeX-replace-format
   7.541 -      cmd "f"
   7.542 -      (if (or arg (not (string-match "%f" cmd)))
   7.543 -	      ""
   7.544 -	    (YaTeX-replace-format
   7.545 -	     dviprint-from-format
   7.546 -	     "b"
   7.547 -	     (if (string=
   7.548 -		  (setq from (read-string "From page(default 1): ")) "")
   7.549 -		 "1" from))))
   7.550 -       )
   7.551 -    (setq
   7.552 -     cmd
   7.553 -     (YaTeX-replace-format
   7.554 -      cmd "t"
   7.555 -      (if (or arg (not (string-match "%t" cmd))
   7.556 -	      (string= 
   7.557 -	       (setq to (read-string "To page(default none): ")) ""))
   7.558 -	  ""
   7.559 -	(YaTeX-replace-format dviprint-to-format "e" to)))
   7.560 -     )
   7.561 -    (setq cmd
   7.562 -	  (let ((minibuffer-history-symbol 'YaTeX-lpr-command-history))
   7.563 -	    (read-string "Edit command line: "
   7.564 -			 (format cmd (YaTeX-get-preview-file-name)))))
   7.565 -    (save-excursion
   7.566 -      (YaTeX-visit-main t) ;;change execution directory
   7.567 -      (YaTeX-showup-buffer
   7.568 -       lbuffer (function (lambda (x) (nth 3 (window-edges x)))))
   7.569 -      (with-output-to-temp-buffer lbuffer
   7.570 -	(if YaTeX-dos
   7.571 -	    (call-process shell-file-name "con" "*dvi-printing*" nil
   7.572 -			  "/c " cmd)
   7.573 -	  (start-process "print" "*dvi-printing*" shell-file-name "-c" cmd)
   7.574 -	  (message (concat "Starting " cmd " to printing "
   7.575 -			   (YaTeX-get-preview-file-name))))
   7.576 -    )))
   7.577 -)
   7.578 -
   7.579 -(defun YaTeX-main-file-p ()
   7.580 -  "Return if current buffer is main LaTeX source."
   7.581 -  (cond
   7.582 -   ((YaTeX-get-builtin "!")
   7.583 -    (string-match (YaTeX-guess-parent (YaTeX-get-builtin "!")) (buffer-name)))
   7.584 -   (t
   7.585 -    (save-excursion
   7.586 -      (let ((latex-main-id (concat "^\\s *" YaTeX-ec-regexp "documentstyle")))
   7.587 -	(or (re-search-backward latex-main-id nil t)
   7.588 -	    (re-search-forward latex-main-id nil t))))))
   7.589 -)
   7.590 -
   7.591 -(defun YaTeX-visit-main (&optional setbuf)
   7.592 -  "Switch buffer to main LaTeX source.
   7.593 -Use set-buffer instead of switch-to-buffer if the optional second argument
   7.594 -SETBUF is t(Use it only from Emacs-Lisp program)."
   7.595 -  (interactive)
   7.596 -  (let (b-in main-file)
   7.597 -    (if (setq b-in (YaTeX-get-builtin "!"))
   7.598 -	(setq main-file (YaTeX-guess-parent b-in)))
   7.599 -    (if YaTeX-parent-file
   7.600 -	(setq main-file ;;(get-file-buffer YaTeX-parent-file)
   7.601 -	      YaTeX-parent-file))
   7.602 -    (if (YaTeX-main-file-p)
   7.603 -	(if (interactive-p) (message "I think this is main LaTeX source.") nil)
   7.604 -      (cond
   7.605 -       ((and (interactive-p) main-file (get-buffer-window main-file))
   7.606 -	(select-window (get-buffer-window main-file)))
   7.607 -       ((and main-file (YaTeX-switch-to-buffer main-file setbuf)))
   7.608 -       ((and main-file
   7.609 -	     (file-exists-p (setq main-file (concat "../" main-file)))
   7.610 -	     (y-or-n-p (concat (expand-file-name main-file)
   7.611 -			       " is main file?:")))
   7.612 -	(YaTeX-switch-to-buffer main-file setbuf))
   7.613 -       (t (setq main-file (read-file-name "Enter your main text: " nil nil 1))
   7.614 -	  (setq YaTeX-parent-file main-file)
   7.615 -	  (find-file main-file))
   7.616 -       )))
   7.617 -  nil
   7.618 -)
   7.619 -
   7.620 -
   7.621 -(defun YaTeX-guess-parent (command-line)
   7.622 -  (setq command-line
   7.623 -	(if (string-match ".*\\s " command-line)
   7.624 -	    (substring command-line (match-end 0))
   7.625 -	  (file-name-nondirectory (buffer-file-name)))
   7.626 -	command-line
   7.627 -	(concat (if (string-match "\\(.*\\)\\." command-line)
   7.628 -		    (substring command-line (match-beginning 1) (match-end 1))
   7.629 -		  command-line)
   7.630 -		".tex"))
   7.631 -)
   7.632 -
   7.633 -(defun YaTeX-visit-main-other-window ()
   7.634 -  "Switch to buffer main LaTeX source in other window."
   7.635 -  (interactive)
   7.636 -  (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
   7.637 -      (YaTeX-switch-to-buffer-other-window
   7.638 -       (concat (YaTeX-get-preview-file-name) ".tex")))
   7.639 -)
   7.640 -
   7.641 -(defun YaTeX-get-builtin (key)
   7.642 -  "Read source built-in command of %# usage."
   7.643 -  (save-excursion
   7.644 -    (goto-char (point-min))
   7.645 -    (if (and (re-search-forward
   7.646 -	      (concat "^" (regexp-quote (concat "%#" key))) nil t)
   7.647 -	     (not (eolp)))
   7.648 -	(buffer-substring
   7.649 -	 (progn (skip-chars-forward " 	" (point-end-of-line))(point))
   7.650 -	 (point-end-of-line))
   7.651 -      nil))
   7.652 -)
   7.653 -
   7.654 -(defun YaTeX-save-buffers ()
   7.655 -  "Save buffers which is in yatex-mode."
   7.656 -  (basic-save-buffer)
   7.657 -  (save-excursion
   7.658 -    (mapcar '(lambda (buf)
   7.659 -	       (set-buffer buf)
   7.660 -	       (if (and (buffer-file-name buf)
   7.661 -			(eq major-mode 'yatex-mode)
   7.662 -			(buffer-modified-p buf)
   7.663 -			(y-or-n-p (format "Save %s" (buffer-name buf))))
   7.664 -		   (save-buffer buf)))
   7.665 -	    (buffer-list)))
   7.666 -)
   7.667 -
   7.668 -(provide 'yatexprc)
   7.669 +;;; -*- Emacs-Lisp -*-
   7.670 +;;; YaTeX process handler.
   7.671 +;;; yatexprc.el
   7.672 +;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
   7.673 +;;; Last modified Thu Oct 20 16:48:41 1994 on figaro
   7.674 +;;; $Id$
   7.675 +
   7.676 +(require 'yatex)
   7.677 +
   7.678 +(defvar YaTeX-typeset-process nil
   7.679 +  "Process identifier for jlatex"
   7.680 +)
   7.681 +(defvar YaTeX-typeset-buffer "*YaTeX-typesetting*"
   7.682 +  "Process buffer for jlatex")
   7.683 +
   7.684 +(defvar YaTeX-typeset-buffer-syntax nil
   7.685 +  "*Syntax table for typesetting buffer")
   7.686 +
   7.687 +(defvar YaTeX-current-TeX-buffer nil
   7.688 +  "Keeps the buffer on which recently typeset run.")
   7.689 +
   7.690 +(if YaTeX-typeset-buffer-syntax nil
   7.691 +  (setq YaTeX-typeset-buffer-syntax
   7.692 +	(make-syntax-table (standard-syntax-table)))
   7.693 +  (modify-syntax-entry ?\{ "w" YaTeX-typeset-buffer-syntax)
   7.694 +  (modify-syntax-entry ?\} "w" YaTeX-typeset-buffer-syntax)
   7.695 +  (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax)
   7.696 +  (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax)
   7.697 +)
   7.698 +
   7.699 +(defun YaTeX-typeset (command buffer)
   7.700 +  "Execute jlatex (or other) to LaTeX typeset."
   7.701 +  (interactive)
   7.702 +  (save-excursion
   7.703 +    (let ((p (point)) (window (selected-window)) execdir)
   7.704 +      (if (and YaTeX-typeset-process
   7.705 +	       (eq (process-status YaTeX-typeset-process) 'run))
   7.706 +	  ;; if tex command is halting.
   7.707 +	  (YaTeX-kill-typeset-process YaTeX-typeset-process))
   7.708 +      (YaTeX-visit-main t);;execution directory
   7.709 +      (setq execdir default-directory)
   7.710 +      ;;Select lower-most window if there are more than 2 windows and
   7.711 +      ;;typeset buffer not seen.
   7.712 +      (YaTeX-showup-buffer
   7.713 +       buffer (function (lambda (x) (nth 3 (window-edges x)))))
   7.714 +      (set-buffer (get-buffer-create buffer))
   7.715 +      (setq default-directory execdir)
   7.716 +      (cd execdir)
   7.717 +      (erase-buffer)
   7.718 +      (cond
   7.719 +       (YaTeX-dos			;if MS-DOS
   7.720 +	(YaTeX-put-nonstopmode)
   7.721 +	(call-process shell-file-name nil buffer nil "/c" command)
   7.722 +	(YaTeX-remove-nonstopmode))
   7.723 +       (t				;if UNIX
   7.724 +	(set-process-buffer
   7.725 +	 (setq YaTeX-typeset-process
   7.726 +	       (start-process "LaTeX" buffer shell-file-name "-c" command))
   7.727 +	 (get-buffer buffer))
   7.728 +	(set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
   7.729 +      (message (format "Calling `%s'..." command))
   7.730 +      (setq YaTeX-current-TeX-buffer (buffer-name))
   7.731 +      (use-local-map YaTeX-typesetting-mode-map)
   7.732 +      (set-syntax-table YaTeX-typeset-buffer-syntax)
   7.733 +      (setq mode-name "typeset")
   7.734 +      (if YaTeX-typeset-process		; if process is running (maybe on UNIX)
   7.735 +	  (cond ((boundp 'MULE)
   7.736 +		 (set-current-process-coding-system
   7.737 +		  YaTeX-latex-message-code YaTeX-coding-system))
   7.738 +		((boundp 'NEMACS)
   7.739 +		 (set-kanji-process-code YaTeX-latex-message-code))))
   7.740 +      (if YaTeX-dos (message "Done.")
   7.741 +	(insert " ")
   7.742 +	(set-marker (process-mark YaTeX-typeset-process) (1- (point))))
   7.743 +      (if (bolp) (forward-line -1))	;what for?
   7.744 +      (if YaTeX-emacs-19
   7.745 +	  (let ((win (get-buffer-window buffer t)) owin)
   7.746 +	    (select-frame (window-frame win))
   7.747 +	    (setq owin (selected-window))
   7.748 +	    (select-window win)
   7.749 +	    (goto-char (point-max))
   7.750 +	    (recenter -1)
   7.751 +	    (select-window owin))
   7.752 +	(select-window (get-buffer-window buffer))
   7.753 +	(goto-char (point-max))
   7.754 +	(recenter -1))
   7.755 +      (select-window window)))
   7.756 +)
   7.757 +
   7.758 +(defun YaTeX-typeset-sentinel (proc mes)
   7.759 +  (cond ((null (buffer-name (process-buffer proc)))
   7.760 +         ;; buffer killed
   7.761 +         (set-process-buffer proc nil))
   7.762 +        ((memq (process-status proc) '(signal exit))
   7.763 +         (let* ((obuf (current-buffer)) (pbuf (process-buffer proc))
   7.764 +		(pwin (get-buffer-window pbuf))
   7.765 +		(owin (selected-window)) win)
   7.766 +           ;; save-excursion isn't the right thing if
   7.767 +           ;;  process-buffer is current-buffer
   7.768 +           (unwind-protect
   7.769 +               (progn
   7.770 +                 ;; Write something in *typesetting* and hack its mode line
   7.771 +		 (if pwin
   7.772 +		     (select-window pwin)
   7.773 +		   (set-buffer pbuf))
   7.774 +		 ;;(YaTeX-showup-buffer pbuf nil t)
   7.775 +                 (goto-char (point-max))
   7.776 +		 (if pwin (recenter -3))
   7.777 +                 (insert ?\n "latex typesetting " mes)
   7.778 +                 (forward-char -1)
   7.779 +                 (insert " at " (substring (current-time-string) 0 -5) "\n")
   7.780 +                 (forward-char 1)
   7.781 +                 (setq mode-line-process
   7.782 +                       (concat ": "
   7.783 +                               (symbol-name (process-status proc))))
   7.784 +		 (message "latex typesetting %s."
   7.785 +			  (if (eq (process-status proc) 'exit)
   7.786 +			      "done" "ceased"))
   7.787 +                 ;; If buffer and mode line shows that the process
   7.788 +                 ;; is dead, we can delete it now.  Otherwise it
   7.789 +                 ;; will stay around until M-x list-processes.
   7.790 +                 (delete-process proc)
   7.791 +		 )
   7.792 +             (setq YaTeX-typesetting-process nil)
   7.793 +             ;; Force mode line redisplay soon
   7.794 +             (set-buffer-modified-p (buffer-modified-p))
   7.795 +	     )
   7.796 +	   (select-window owin)
   7.797 +	   (set-buffer obuf))))
   7.798 +)
   7.799 +
   7.800 +(defvar YaTeX-texput-file "texput.tex"
   7.801 +  "*File name for temporary file of typeset-region."
   7.802 +)
   7.803 +
   7.804 +(defun YaTeX-typeset-region ()
   7.805 +  "Paste the region to the file `texput.tex' and execute jlatex (or other)
   7.806 +to LaTeX typeset.  The region is specified by the rule:
   7.807 +	(1)If keyword `%#BEGIN' is found in the upper direction from (point).
   7.808 +	  (1-1)if the keyword `%#END' is found after `%#BEGIN',
   7.809 +		->Assume the text between `%#BEGIN' and `%#END' as region.
   7.810 +	  (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN',
   7.811 +		->Assume the text after `%#BEGIN' as region.
   7.812 +	(2)If no `%#BEGIN' usage is found before the (point),
   7.813 +		->Assume the text between current (point) and (mark) as region.
   7.814 +DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing
   7.815 +operation to the region."
   7.816 +  (interactive)
   7.817 +  (save-excursion
   7.818 +    (let*
   7.819 +	((end "") typeout ;Type out message that tells the method of cutting.
   7.820 +	 (cmd (concat (YaTeX-get-latex-command nil) " " YaTeX-texput-file))
   7.821 +	 (buffer (current-buffer)) opoint preamble (subpreamble "") main
   7.822 +	 (hilit-auto-highlight nil)	;for Emacs19 with hilit19
   7.823 +	 reg-begin reg-end)
   7.824 +
   7.825 +      (save-excursion
   7.826 +	(if (search-backward "%#BEGIN" nil t)
   7.827 +	    (progn
   7.828 +	      (setq typeout "--- Region from BEGIN to "
   7.829 +		    end "the end of the buffer ---"
   7.830 +		    reg-begin (match-end 0))
   7.831 +	      (if (search-forward "%#END" nil t)
   7.832 +		  (setq reg-end (match-beginning 0)
   7.833 +			end "END ---")
   7.834 +		(setq reg-end (point-max))))
   7.835 +	  (setq typeout "=== Region from (point) to (mark) ===")
   7.836 +	  (setq reg-begin (point) reg-end (mark)))
   7.837 +	(goto-char (point-min))
   7.838 +	(while (search-forward "%#REQUIRE" nil t)
   7.839 +	  (setq subpreamble
   7.840 +		(concat subpreamble
   7.841 +			(cond
   7.842 +			 ((eolp)
   7.843 +			  (buffer-substring
   7.844 +			   (match-beginning 0)
   7.845 +			   (point-beginning-of-line)))
   7.846 +			 (t (buffer-substring
   7.847 +			     (match-end 0)
   7.848 +			     (point-end-of-line))))
   7.849 +			"\n"))
   7.850 +	  (goto-char (match-end 0))))
   7.851 +      (YaTeX-visit-main t)
   7.852 +      (setq main (current-buffer))
   7.853 +      (setq opoint (point))
   7.854 +      (goto-char (point-min))
   7.855 +      (setq
   7.856 +       preamble
   7.857 +       (if (re-search-forward "^[ 	]*\\\\begin.*{document}" nil t)
   7.858 +	   (buffer-substring (point-min) (match-end 0))
   7.859 +	 (concat "\\documentstyle{" YaTeX-default-document-style "}\n"
   7.860 +		 "\\begin{document}")))
   7.861 +      (goto-char opoint)
   7.862 +      ;;(set-buffer buffer)		;for clarity
   7.863 +      (set-buffer (find-file-noselect YaTeX-texput-file))
   7.864 +      ;;(find-file YaTeX-texput-file)
   7.865 +      (erase-buffer)
   7.866 +      (if YaTeX-need-nonstop
   7.867 +	  (insert "\\nonstopmode{}\n"))
   7.868 +      (insert preamble "\n" subpreamble "\n")
   7.869 +      (insert-buffer-substring buffer reg-begin reg-end)
   7.870 +      (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
   7.871 +      (insert "\n\\end{document}\n")
   7.872 +      (basic-save-buffer)
   7.873 +      (kill-buffer (current-buffer))
   7.874 +      (set-buffer main)		;return to parent file or itself.
   7.875 +      (YaTeX-typeset cmd YaTeX-typeset-buffer)
   7.876 +      (switch-to-buffer buffer)		;for Emacs-19
   7.877 +      (put 'dvi2-command 'region t)))
   7.878 +)
   7.879 +
   7.880 +(defun YaTeX-typeset-buffer ()
   7.881 +  "Typeset whole buffer.  If %#! usage says other buffer is main text,
   7.882 +visit main buffer to confirm if its includeonly list contains current
   7.883 +buffer's file.  And if it doesn't contain editing text, ask user which
   7.884 +action wants to be done, A:Add list, R:Replace list, %:comment-out list."
   7.885 +  (interactive)
   7.886 +  (YaTeX-save-buffers)
   7.887 +  (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.)))
   7.888 +	(mydir (file-name-directory (buffer-file-name)))
   7.889 +	(cmd (YaTeX-get-latex-command t)))
   7.890 +    (if (YaTeX-main-file-p) nil
   7.891 +      (save-excursion
   7.892 +	(YaTeX-visit-main t)	;search into main buffer
   7.893 +	(save-excursion
   7.894 +	  (push-mark (point) t)
   7.895 +	  (goto-char (point-min))
   7.896 +	  (if (and (re-search-forward "^[ 	]*\\\\begin{document}" nil t)
   7.897 +		   (re-search-backward "^[ 	]*\\\\includeonly{" nil t))
   7.898 +	      (let*
   7.899 +		  ((b (progn (skip-chars-forward "^{") (point)))
   7.900 +		   (e (progn (skip-chars-forward "^}") (1+ (point))))
   7.901 +		   (s (buffer-substring b e)) c
   7.902 +		   (pardir (file-name-directory (buffer-file-name))))
   7.903 +		(if (string-match (concat "[{,/]" me "[,}]") s)
   7.904 +		    nil ; Nothing to do when it's already in includeonly.
   7.905 +		  (ding)
   7.906 +		  (switch-to-buffer (current-buffer));Display this buffer.
   7.907 +		  (setq
   7.908 +		   me	  ;;Rewrite my name(me) to contain sub directory name.
   7.909 +		   (concat
   7.910 +		    (if (string-match pardir mydir) ;if mydir is child of main
   7.911 +			(substring mydir (length pardir)) ;cut absolute path
   7.912 +		      mydir) ;else concat absolute path name.
   7.913 +		    me))
   7.914 +		  (message
   7.915 +		   "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? "
   7.916 +		   me)
   7.917 +		  (setq c (read-char))
   7.918 +		  (cond
   7.919 +		   ((= c ?a)
   7.920 +		    (goto-char (1+ b))
   7.921 +		    (insert me (if (string= s "{}") "" ",")))
   7.922 +		   ((= c ?r)
   7.923 +		    (delete-region (1+ b) (1- e)) (insert me))
   7.924 +		   ((= c ?%)
   7.925 +		    (beginning-of-line) (insert "%"))
   7.926 +		   (t nil))
   7.927 +		  (basic-save-buffer))))
   7.928 +	  (exchange-point-and-mark))
   7.929 +	))
   7.930 +    (YaTeX-typeset cmd YaTeX-typeset-buffer)
   7.931 +    (put 'dvi2-command 'region nil))
   7.932 +)
   7.933 +
   7.934 +(defvar YaTeX-call-command-history nil
   7.935 +  "Holds history list of YaTeX-call-command-on-file.")
   7.936 +(put 'YaTeX-call-command-history 'no-default t)
   7.937 +(defun YaTeX-call-command-on-file (base-cmd buffer)
   7.938 +  (YaTeX-save-buffers)
   7.939 +  (YaTeX-typeset
   7.940 +   (let ((minibufer-history-symbol 'YaTeX-call-command-history))
   7.941 +     (read-string "Call command: "
   7.942 +		  (concat base-cmd " " (YaTeX-get-preview-file-name))))
   7.943 +   buffer)
   7.944 +)
   7.945 +
   7.946 +(defun YaTeX-bibtex-buffer (cmd)
   7.947 +  "Pass the bibliography data of editing file to bibtex."
   7.948 +  (interactive)
   7.949 +  (YaTeX-save-buffers)
   7.950 +  (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" )
   7.951 +)
   7.952 +
   7.953 +(defun YaTeX-kill-typeset-process (proc)
   7.954 +  "Kill process PROC after sending signal to PROC.
   7.955 +PROC should be process identifier."
   7.956 +  (cond
   7.957 +   (YaTeX-dos
   7.958 +    (error "MS-DOS can't have concurrent process."))
   7.959 +   ((or (null proc) (not (eq (process-status proc) 'run)))
   7.960 +    (error "No typesetting process."))
   7.961 +   (t (interrupt-process proc)
   7.962 +      (delete-process proc)))
   7.963 +)
   7.964 +
   7.965 +(defun YaTeX-system (command buffer)
   7.966 +  "Execute some command on buffer.  Not a official function."
   7.967 +  (save-excursion
   7.968 +    (YaTeX-showup-buffer
   7.969 +     buffer (function (lambda (x) (nth 3 (window-edges x)))))
   7.970 +    (set-buffer (get-buffer-create buffer))
   7.971 +    (erase-buffer)
   7.972 +    (if YaTeX-dos
   7.973 +	(call-process shell-file-name nil buffer nil "/c " command)
   7.974 +      (set-process-buffer
   7.975 +       (start-process "system" buffer shell-file-name "-c" command)
   7.976 +       (get-buffer buffer))))
   7.977 +)
   7.978 +
   7.979 +(defvar YaTeX-preview-command-history nil
   7.980 +  "Holds minibuffer history of preview command.")
   7.981 +(put 'YaTeX-preview-command-history 'no-default t)
   7.982 +(defvar YaTeX-preview-file-history nil
   7.983 +  "Holds minibuffer history of file to preview.")
   7.984 +(put 'YaTeX-preview-file-history 'no-default t)
   7.985 +(defun YaTeX-preview (preview-command preview-file)
   7.986 +  "Execute xdvi (or other) to tex-preview."
   7.987 +  (interactive
   7.988 +   (list
   7.989 +    (let ((minibuffer-history-symbol 'YaTeX-preview-command-history))
   7.990 +      (read-string "Preview command: " dvi2-command))
   7.991 +    (let ((minibuffer-history-symbol 'YaTeX-preview-file-history))
   7.992 +      (read-string "Preview file[.dvi]: "
   7.993 +		   (if (get 'dvi2-command 'region)
   7.994 +		       (substring YaTeX-texput-file
   7.995 +				  0 (rindex YaTeX-texput-file ?.))
   7.996 +		     (YaTeX-get-preview-file-name))
   7.997 +		   ))))
   7.998 +  (setq dvi2-command preview-command)	;`dvi2command' is buffer local
   7.999 +  (save-excursion
  7.1000 +    (YaTeX-visit-main t)
  7.1001 +    (let ((pbuffer "*dvi-preview*"))
  7.1002 +      (YaTeX-showup-buffer
  7.1003 +       pbuffer (function (lambda (x) (nth 3 (window-edges x)))))
  7.1004 +      (set-buffer (get-buffer-create pbuffer))
  7.1005 +      (erase-buffer)
  7.1006 +      (cond
  7.1007 +       (YaTeX-dos			;if MS-DOS
  7.1008 +	(send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
  7.1009 +	(call-process shell-file-name "con" "*dvi-preview*" nil
  7.1010 +		      "/c " preview-command preview-file)
  7.1011 +	(send-string-to-terminal "\e[>5l") ;show cursor
  7.1012 +	(redraw-display))
  7.1013 +       (t				;if UNIX
  7.1014 +	(set-process-buffer
  7.1015 +	 (start-process "preview" "*dvi-preview*" shell-file-name "-c"
  7.1016 +			(concat preview-command " " preview-file))
  7.1017 +	 (get-buffer pbuffer))
  7.1018 +	(message
  7.1019 +	 (concat "Starting " preview-command
  7.1020 +		 " to preview " preview-file))))))
  7.1021 +)
  7.1022 +
  7.1023 +(defun YaTeX-prev-error ()
  7.1024 +  "Visit previous typeset error.
  7.1025 +  To avoid making confliction of line numbers by editing, jump to
  7.1026 +error or warning lines in reverse order."
  7.1027 +  (interactive)
  7.1028 +  (let ((cur-buf (buffer-name)) (cur-win (selected-window))
  7.1029 +	error-line typeset-win error-buffer error-win)
  7.1030 +    (if (null (get-buffer YaTeX-typeset-buffer))
  7.1031 +	(error "There is no typesetting buffer."))
  7.1032 +    (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
  7.1033 +    (setq typeset-win (selected-window))
  7.1034 +    (if (re-search-backward
  7.1035 +	 (concat "\\(" latex-error-regexp "\\)\\|\\("
  7.1036 +		 latex-warning-regexp "\\)")
  7.1037 +	 nil t)
  7.1038 +	nil
  7.1039 +      (select-window cur-win)
  7.1040 +      (error "No more erros on %s" cur-buf))
  7.1041 +    (goto-char (match-beginning 0))
  7.1042 +    (skip-chars-forward "^0-9" (match-end 0))
  7.1043 +    (setq error-line
  7.1044 +	  (string-to-int
  7.1045 +	   (buffer-substring
  7.1046 +	    (point)
  7.1047 +	    (progn (skip-chars-forward "0-9" (match-end 0)) (point))))
  7.1048 +	  error-buffer (YaTeX-get-error-file cur-buf)
  7.1049 +	  error-win (get-buffer-window error-buffer))
  7.1050 +    (if (or (null error-line) (equal 0 error-line))
  7.1051 +	(error "Can't detect error position."))
  7.1052 +    (select-window cur-win)
  7.1053 +    (cond
  7.1054 +     (error-win (select-window error-win))
  7.1055 +     ((eq (get-lru-window) typeset-win)
  7.1056 +      (YaTeX-switch-to-buffer error-buffer))
  7.1057 +     (t (select-window (get-lru-window))
  7.1058 +	(YaTeX-switch-to-buffer error-buffer)))
  7.1059 +    (setq error-win (selected-window))
  7.1060 +    (goto-line error-line)
  7.1061 +    (message "LaTeX %s in `%s' on line: %d."
  7.1062 +	     (if (match-beginning 1) "error" "warning")
  7.1063 +	     error-buffer error-line)
  7.1064 +    (select-window typeset-win)
  7.1065 +    (skip-chars-backward "0-9")
  7.1066 +    (recenter (/ (window-height) 2))
  7.1067 +    (sit-for 3)
  7.1068 +    (goto-char (match-beginning 0))
  7.1069 +    (select-window error-win))
  7.1070 +)
  7.1071 +
  7.1072 +(defun YaTeX-jump-error-line ()
  7.1073 +  "Jump to corresponding line on latex command's error message."
  7.1074 +  (interactive)
  7.1075 +  (let (error-line error-file error-buf)
  7.1076 +    (save-excursion
  7.1077 +      (beginning-of-line)
  7.1078 +      (setq error-line (re-search-forward "l[ ines]*\\.?\\([1-9][0-9]*\\)"
  7.1079 +					  (point-end-of-line) t)))
  7.1080 +    (if (null error-line)
  7.1081 +	(if (eobp) (insert (this-command-keys))
  7.1082 +	  (error "No line number expression."))
  7.1083 +      (goto-char (match-beginning 0))
  7.1084 +      (setq error-line (string-to-int
  7.1085 +			(buffer-substring (match-beginning 1) (match-end 1)))
  7.1086 +	    error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)
  7.1087 +	    error-buf (YaTeX-switch-to-buffer error-file t))
  7.1088 +      (if (null error-buf)
  7.1089 +	  (error "`%s' is not found in this directory." error-file))
  7.1090 +      (YaTeX-showup-buffer error-buf nil t)
  7.1091 +      (goto-line error-line)))
  7.1092 +)
  7.1093 +
  7.1094 +(defun YaTeX-send-string ()
  7.1095 +  "Send string to current typeset process."
  7.1096 +  (interactive)
  7.1097 +  (if (and (eq (process-status YaTeX-typeset-process) 'run)
  7.1098 +	   (>= (point) (process-mark YaTeX-typeset-process)))
  7.1099 +      (let ((b (process-mark YaTeX-typeset-process))
  7.1100 +	    (e (point-end-of-line)))
  7.1101 +	(goto-char b)
  7.1102 +	(skip-chars-forward " \t" e)
  7.1103 +	(setq b (point))
  7.1104 +	(process-send-string
  7.1105 +	 YaTeX-typeset-process (concat (buffer-substring b e) "\n"))
  7.1106 +	(goto-char e)
  7.1107 +	(insert "\n")
  7.1108 +	(set-marker (process-mark YaTeX-typeset-process) (point))
  7.1109 +	(insert " "))
  7.1110 +    (ding))
  7.1111 +)
  7.1112 +
  7.1113 +(defun YaTeX-view-error ()
  7.1114 +  (interactive)
  7.1115 +  (if (null (get-buffer YaTeX-typeset-buffer))
  7.1116 +      (message "No typeset buffer found.")
  7.1117 +    (let ((win (selected-window)))
  7.1118 +      (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
  7.1119 +      ;; Next 3 lines are obsolete because YaTeX-typesetting-buffer is
  7.1120 +      ;; automatically scrolled up at typesetting.
  7.1121 +      ;;(goto-char (point-max))
  7.1122 +      ;;(forward-line -1)
  7.1123 +      ;;(recenter -1)
  7.1124 +      (select-window win)))
  7.1125 +)
  7.1126 +
  7.1127 +(defun YaTeX-get-error-file (default)
  7.1128 +  "Get current processing file from typesetting log."
  7.1129 +  (save-excursion
  7.1130 +    (let(s)
  7.1131 +      (condition-case () (up-list -1)
  7.1132 +	(error
  7.1133 +	 (let ((list 0) found)
  7.1134 +	   (while
  7.1135 +	       (and (<= list 0) (not found)
  7.1136 +		    (re-search-backward "\\((\\)\\|\\()\\)" nil t))
  7.1137 +	     (if (equal (match-beginning 0) (match-beginning 2)) ;close paren.
  7.1138 +		 (setq list (1- list)) ;open paren
  7.1139 +	       (setq list (1+ list))
  7.1140 +	       (if (= list 1)
  7.1141 +		   (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty")
  7.1142 +		       (setq found t)
  7.1143 +		     (setq list (1- list)))))))))
  7.1144 +      (setq s
  7.1145 +	    (buffer-substring
  7.1146 +	     (progn (forward-char 1) (point))
  7.1147 +	     (progn (skip-chars-forward "-A-Za-z0-9_/\.\\" (point-end-of-line))
  7.1148 +		    (point))))
  7.1149 +      (if (string= "" s) default s)))
  7.1150 +)
  7.1151 +      
  7.1152 +(defun YaTeX-put-nonstopmode ()
  7.1153 +  (if YaTeX-need-nonstop
  7.1154 +      (if (re-search-backward "\\\\nonstopmode{}" (point-min) t)
  7.1155 +	  nil                    ;if already written in text then do nothing
  7.1156 +	(save-excursion
  7.1157 +	  (YaTeX-visit-main t)
  7.1158 +	  (goto-char (point-min))
  7.1159 +	  (insert "\\nonstopmode{}%_YaTeX_%\n")))
  7.1160 +    )
  7.1161 +)
  7.1162 +
  7.1163 +(defun YaTeX-remove-nonstopmode ()
  7.1164 +  (if YaTeX-need-nonstop ;for speed
  7.1165 +      (save-excursion
  7.1166 +	(YaTeX-visit-main t)
  7.1167 +	(goto-char (point-min))
  7.1168 +	(forward-line 1)
  7.1169 +	(narrow-to-region (point-min) (point))
  7.1170 +	(goto-char (point-min))
  7.1171 +	(delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$")
  7.1172 +	(widen)))
  7.1173 +)
  7.1174 +
  7.1175 +(defun YaTeX-get-preview-file-name ()
  7.1176 +  "Get file name to preview by inquiring YaTeX-get-latex-command"
  7.1177 +  (let* ((latex-cmd (YaTeX-get-latex-command t))
  7.1178 +	 (rin (rindex latex-cmd ? ))
  7.1179 +	 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
  7.1180 +	 (period))
  7.1181 +    (if (string= fname "")
  7.1182 +	(setq fname (substring (file-name-nondirectory
  7.1183 +				(buffer-file-name))
  7.1184 +			       0 -4))
  7.1185 +      (setq period (rindex fname ?.))
  7.1186 +      (setq fname (substring fname 0 (if (eq -1 period) nil period)))
  7.1187 +      ))
  7.1188 +)
  7.1189 +
  7.1190 +(defun YaTeX-get-latex-command (&optional switch)
  7.1191 +  "Specify the latex-command name and its argument.
  7.1192 +If there is a line which begins with string: \"%#!\", the following
  7.1193 +strings are assumed to be the latex-command and arguments.  The
  7.1194 +default value of latex-command is:
  7.1195 +	tex-command FileName
  7.1196 +and if you write \"%#!jlatex\" in the beginning of certain line.
  7.1197 +	\"jlatex \" FileName
  7.1198 +will be the latex-command,
  7.1199 +and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
  7.1200 +is non-nil, then
  7.1201 +	\"jlatex main.tex\"
  7.1202 +
  7.1203 +will be given to the shell."
  7.1204 +  (let (magic command target)
  7.1205 +    (setq parent
  7.1206 +	  (cond
  7.1207 +	   (YaTeX-parent-file YaTeX-parent-file)
  7.1208 +	   (t (save-excursion
  7.1209 +		(YaTeX-visit-main t)
  7.1210 +		(file-name-nondirectory (buffer-file-name)))))
  7.1211 +	  magic (YaTeX-get-builtin "!"))
  7.1212 +    (cond
  7.1213 +     (magic
  7.1214 +      (cond
  7.1215 +       (switch (if (string-match "\\s " magic) magic
  7.1216 +		 (concat magic " " parent)))
  7.1217 +       (t (concat (substring magic 0 (string-match "\\s " magic)) " "))))
  7.1218 +     (t (concat tex-command " " (if switch parent)))))
  7.1219 +)
  7.1220 +
  7.1221 +(defvar YaTeX-lpr-command-history nil
  7.1222 +  "Holds command line history of YaTeX-lpr.")
  7.1223 +(put 'YaTeX-lpr-command-history 'no-default t)
  7.1224 +(defun YaTeX-lpr (arg)
  7.1225 +  "Print out.  If prefix arg ARG is non nil, call print driver without
  7.1226 +page range description."
  7.1227 +  (interactive "P")
  7.1228 +  (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format))
  7.1229 +	from to (lbuffer "*dvi-printing*"))
  7.1230 +    (setq
  7.1231 +     cmd 
  7.1232 +     (YaTeX-replace-format
  7.1233 +      cmd "f"
  7.1234 +      (if (or arg (not (string-match "%f" cmd)))
  7.1235 +	      ""
  7.1236 +	    (YaTeX-replace-format
  7.1237 +	     dviprint-from-format
  7.1238 +	     "b"
  7.1239 +	     (if (string=
  7.1240 +		  (setq from (read-string "From page(default 1): ")) "")
  7.1241 +		 "1" from))))
  7.1242 +       )
  7.1243 +    (setq
  7.1244 +     cmd
  7.1245 +     (YaTeX-replace-format
  7.1246 +      cmd "t"
  7.1247 +      (if (or arg (not (string-match "%t" cmd))
  7.1248 +	      (string= 
  7.1249 +	       (setq to (read-string "To page(default none): ")) ""))
  7.1250 +	  ""
  7.1251 +	(YaTeX-replace-format dviprint-to-format "e" to)))
  7.1252 +     )
  7.1253 +    (setq cmd
  7.1254 +	  (let ((minibuffer-history-symbol 'YaTeX-lpr-command-history))
  7.1255 +	    (read-string "Edit command line: "
  7.1256 +			 (format cmd (YaTeX-get-preview-file-name)))))
  7.1257 +    (save-excursion
  7.1258 +      (YaTeX-visit-main t) ;;change execution directory
  7.1259 +      (YaTeX-showup-buffer
  7.1260 +       lbuffer (function (lambda (x) (nth 3 (window-edges x)))))
  7.1261 +      (set-buffer (get-buffer-create lbuffer))
  7.1262 +      (erase-buffer)
  7.1263 +      (cond
  7.1264 +       (YaTeX-dos
  7.1265 +	(call-process shell-file-name "con" "*dvi-printing*" nil "/c " cmd))
  7.1266 +       (t
  7.1267 +	(set-process-buffer
  7.1268 +	 (start-process "print" "*dvi-printing*" shell-file-name "-c" cmd)
  7.1269 +	 (get-buffer lbuffer))
  7.1270 +	(message (concat "Starting " cmd " to printing "
  7.1271 +			 (YaTeX-get-preview-file-name)))))
  7.1272 +    ))
  7.1273 +)
  7.1274 +
  7.1275 +(defun YaTeX-main-file-p ()
  7.1276 +  "Return if current buffer is main LaTeX source."
  7.1277 +  (cond
  7.1278 +   ((YaTeX-get-builtin "!")
  7.1279 +    (string-match (YaTeX-guess-parent (YaTeX-get-builtin "!")) (buffer-name)))
  7.1280 +   (t
  7.1281 +    (save-excursion
  7.1282 +      (let ((latex-main-id (concat "^\\s *" YaTeX-ec-regexp "documentstyle")))
  7.1283 +	(or (re-search-backward latex-main-id nil t)
  7.1284 +	    (re-search-forward latex-main-id nil t))))))
  7.1285 +)
  7.1286 +
  7.1287 +(defun YaTeX-visit-main (&optional setbuf)
  7.1288 +  "Switch buffer to main LaTeX source.
  7.1289 +Use set-buffer instead of switch-to-buffer if the optional second argument
  7.1290 +SETBUF is t(Use it only from Emacs-Lisp program)."
  7.1291 +  (interactive)
  7.1292 +  (let (b-in main-file)
  7.1293 +    (if (setq b-in (YaTeX-get-builtin "!"))
  7.1294 +	(setq main-file (YaTeX-guess-parent b-in)))
  7.1295 +    (if YaTeX-parent-file
  7.1296 +	(setq main-file ;;(get-file-buffer YaTeX-parent-file)
  7.1297 +	      YaTeX-parent-file))
  7.1298 +    (if (YaTeX-main-file-p)
  7.1299 +	(if (interactive-p) (message "I think this is main LaTeX source.") nil)
  7.1300 +      (cond
  7.1301 +       ((and (interactive-p) main-file (get-buffer-window main-file))
  7.1302 +	(select-window (get-buffer-window main-file)))
  7.1303 +       ((and main-file (YaTeX-switch-to-buffer main-file setbuf)))
  7.1304 +       ((and main-file
  7.1305 +	     (file-exists-p (setq main-file (concat "../" main-file)))
  7.1306 +	     (y-or-n-p (concat (expand-file-name main-file)
  7.1307 +			       " is main file?:")))
  7.1308 +	(YaTeX-switch-to-buffer main-file setbuf))
  7.1309 +       (t (setq main-file (read-file-name "Enter your main text: " nil nil 1))
  7.1310 +	  (setq YaTeX-parent-file main-file)
  7.1311 +	  (find-file main-file))
  7.1312 +       )))
  7.1313 +  nil
  7.1314 +)
  7.1315 +
  7.1316 +
  7.1317 +(defun YaTeX-guess-parent (command-line)
  7.1318 +  (setq command-line
  7.1319 +	(if (string-match ".*\\s " command-line)
  7.1320 +	    (substring command-line (match-end 0))
  7.1321 +	  (file-name-nondirectory (buffer-file-name)))
  7.1322 +	command-line
  7.1323 +	(concat (if (string-match "\\(.*\\)\\." command-line)
  7.1324 +		    (substring command-line (match-beginning 1) (match-end 1))
  7.1325 +		  command-line)
  7.1326 +		".tex"))
  7.1327 +)
  7.1328 +
  7.1329 +(defun YaTeX-visit-main-other-window ()
  7.1330 +  "Switch to buffer main LaTeX source in other window."
  7.1331 +  (interactive)
  7.1332 +  (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
  7.1333 +      (YaTeX-switch-to-buffer-other-window
  7.1334 +       (concat (YaTeX-get-preview-file-name) ".tex")))
  7.1335 +)
  7.1336 +
  7.1337 +(defun YaTeX-get-builtin (key)
  7.1338 +  "Read source built-in command of %# usage."
  7.1339 +  (save-excursion
  7.1340 +    (goto-char (point-min))
  7.1341 +    (if (and (re-search-forward
  7.1342 +	      (concat "^" (regexp-quote (concat "%#" key))) nil t)
  7.1343 +	     (not (eolp)))
  7.1344 +	(buffer-substring
  7.1345 +	 (progn (skip-chars-forward " 	" (point-end-of-line))(point))
  7.1346 +	 (point-end-of-line))
  7.1347 +      nil))
  7.1348 +)
  7.1349 +
  7.1350 +(defun YaTeX-save-buffers ()
  7.1351 +  "Save buffers which is in yatex-mode."
  7.1352 +  (basic-save-buffer)
  7.1353 +  (save-excursion
  7.1354 +    (mapcar '(lambda (buf)
  7.1355 +	       (set-buffer buf)
  7.1356 +	       (if (and (buffer-file-name buf)
  7.1357 +			(eq major-mode 'yatex-mode)
  7.1358 +			(buffer-modified-p buf)
  7.1359 +			(y-or-n-p (format "Save %s" (buffer-name buf))))
  7.1360 +		   (save-buffer buf)))
  7.1361 +	    (buffer-list)))
  7.1362 +)
  7.1363 +
  7.1364 +(provide 'yatexprc)