yatex

changeset 7:9a56acb6c287

Fill-paragraph and (un)comment-paragraph work fine. Fix kill range of YaTeX-kill-some-pairs. Ignore begin/end in verb or verbatim. Indent rigidly initial space between begin/end pairs. Add yatex-mode-load-hook. Go to corresponding \label or \ref.
author yuuji
date Tue, 04 May 1993 12:57:27 +0000
parents 49be9ccb0b65
children c746646cecf5
files docs/yatex.ref yatex.el yatex.new yatex.prj yatexprc.el
diffstat 5 files changed, 752 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docs/yatex.ref	Tue May 04 12:57:27 1993 +0000
     1.3 @@ -0,0 +1,119 @@
     1.4 +----------------------------------------------------------------------------
     1.5 +                                 『野鳥』
     1.6 +                           クイックリファレンス
     1.7 +----------------------------------------------------------------------------
     1.8 +
     1.9 +
    1.10 +【注意】
    1.11 +
    1.12 +	  野鳥では、prefix キーをカスタマイズできるため(標準ではC-c)これを
    1.13 +	[prefix] と表記します。C-c のまま変更していない場合、[prefix] a は
    1.14 +	C-c a を表わします。
    1.15 +
    1.16 +
    1.17 +【補完】
    1.18 +
    1.19 +	◆アクセント補完		[prefix] a
    1.20 +	◆begin型補完			[prefix] b SPC
    1.21 +	◆begin型補完(領域指定)		[prefix] B SPC
    1.22 +	◆begin型補完(即時)		[prefix] b 環境の頭文字
    1.23 +	◆begin型補完(〃領域指定)	[prefix] B 環境の頭文字
    1.24 +	◆end補完			[prefix] e
    1.25 +	◆large型補完			[prefix] l
    1.26 +	◆large型補完(領域指定)		[prefix] L
    1.27 +	◆maketitle型補完		[prefix] m
    1.28 +	◆section型補完			[prefix] s
    1.29 +	◆随時補完			[prefix] SPC
    1.30 +
    1.31 +	  即時begin型補完の、環境名の頭文字の対応については、yatex.doc を
    1.32 +	ご覧ください。領域指定モードでは、マークした位置とポイントの間を
    1.33 +	\begin{center}…\end{center} や {\large } などで括ります。
    1.34 +
    1.35 +
    1.36 +【プロセス起動】
    1.37 +
    1.38 +	◆jbibtex起動			[prefix] tb
    1.39 +	◆jlatex起動			[prefix] tj
    1.40 +	◆jlatex停止			[prefix] tk	※
    1.41 +	◆プリントアウト		[prefix] tl
    1.42 +	◆プリントアウト(全ページ)	C-u [prefix] tl
    1.43 +	◆プレビューア起動		[prefix] tp
    1.44 +	◆jlatex起動(領域指定)		[prefix] tr
    1.45 +
    1.46 +	  [prefix] t を押せばメニューが出るので、[prefix] t の次に押すキー
    1.47 +	は覚えなくて構いません。
    1.48 +
    1.49 +	  ※は、MS-DOS では無効です。
    1.50 +
    1.51 +	  [prefix] tr の領域指定は、文書中の、 %#BEGIN と書いてある行から、
    1.52 +	%#END と書いてある行までです。%#END を省略すると、%#BEGINから文書
    1.53 +	末まで、両方省略すると、マークした位置から、ポイントまでが指定領域
    1.54 +	となります。
    1.55 +
    1.56 +
    1.57 +【カーソルジャンプ】
    1.58 +
    1.59 +	◆タイプセットエラー箇所へ	[prefix] '
    1.60 +
    1.61 +	  タイプセットエラー発生箇所へ(末尾から)遡って順次ジャンプします。
    1.62 +	もちろん jlatex でエラーが生じた場合のみ有効です。
    1.63 +
    1.64 +	◆対応するオブジェクトジャンプ	[prefix] g
    1.65 +
    1.66 +	  カーソルジャンプは、[prefix] g を押す時のカーソルの位置により、
    1.67 +	ジャンプすべき場所を判断します。
    1.68 +
    1.69 +	・\begin{}, \end{}の上		対応する \end{},\begin{} へ
    1.70 +	・%#BEGIN, %#END の上		対応する %#BEGIN, %#END へ
    1.71 +	・\include(only), \input の上	対応するファイル
    1.72 +
    1.73 +	◆メインファイルへジャンプ	[prefix] ^
    1.74 +	◆別ウィンドウで   〃		[prefix] 4^
    1.75 +
    1.76 +	  メインファイルを野鳥に知らせるために、作成ファイルの任意の位置に、
    1.77 +			%#!jlatex メインファイル名
    1.78 +	のような行を書いておいて下さい。
    1.79 +
    1.80 +
    1.81 +【%によるコメントアウト】
    1.82 +
    1.83 +	◆領域/環境のコメントアウト	[prefix] >
    1.84 +	◆領域/環境のコメント除去	[prefix] <
    1.85 +
    1.86 +	  カーソルが、\begin{} または \end{} の行にある時は、その環境に含
    1.87 +	まれる文章全てをコメントアウト/除去し、それ以外の時は、マークとポ
    1.88 +	イント間の文章をコメントアウト/除去します。
    1.89 +
    1.90 +	◆段落/環境宣言コメントアウト	[prefix] .
    1.91 +	◆段落/環境宣言コメント除去	[prefix] ,
    1.92 +
    1.93 +	  カーソルが、\begin{} または \end{} の行にある時は、それら二つの
    1.94 +	行をコメントアウト/除去し、それ以外の時は、カーソルの属する段落を
    1.95 +	コメントアウト/除去します。
    1.96 +
    1.97 +
    1.98 +【その他】
    1.99 +	
   1.100 +	◆itemの桁揃え			[prefix] i
   1.101 +	◆LaTeXコマンド変更		[prefix] c
   1.102 +
   1.103 +	  \begin{}, \end{} の環境名を同時に変更します。
   1.104 +
   1.105 +	◆コマンド削除			[prefix] k
   1.106 +
   1.107 +	  \begin{}, \end{} のペア、または %#BEGIN, %#END のペアを一挙に削
   1.108 +	除します。
   1.109 +
   1.110 +	◆領域を{}で括る		[prefix] }
   1.111 +	◆領域を[]で括る		[prefix] ]
   1.112 +
   1.113 +
   1.114 +								   広瀬雄二
   1.115 +							yuuji@ae.keio.ac.jp
   1.116 +							pcs39334(ASCII-NET)
   1.117 +
   1.118 +
   1.119 +Local variables:
   1.120 +mode: text
   1.121 +fill-prefix: "	"
   1.122 +End:
     2.1 Binary file yatex.el has changed
     3.1 --- a/yatex.new	Mon Feb 22 11:04:53 1993 +0000
     3.2 +++ b/yatex.new	Tue May 04 12:57:27 1993 +0000
     3.3 @@ -2,6 +2,31 @@
     3.4  	Yet Another tex-mode for Emacs
     3.5  	yatex.el 各バージョンの変更点について。
     3.6  
     3.7 +1.42:	fill-paragraph と、(un)comment-paragraph の適正化。
     3.8 +	[prefix] k での削除範囲の適正化。
     3.9 +	YaTeX-end-environment などで verb(atim)中のbegin/endは数えない。
    3.10 +	LaTeX error 発生ファイルの検出の確実化。
    3.11 +	begin型補完のインデントは必ず \begin の桁に合わせるようにした。
    3.12 +	対応する \label{} または \ref{} へのジャンプ。
    3.13 +
    3.14 +1.41:	アドイン関数の自動作成モード追加。
    3.15 +	アドイン関数のmaketitle型補完への対応と、現在の補完形式を変数
    3.16 +	YaTeX-current-completion-type に記憶。
    3.17 +	タイプセットバッファで jlatex に文字列を送る処理の完全化。
    3.18 +
    3.19 +1.40:	編集ファイルをサブディレクトリ毎に分けた場合に対応。
    3.20 +	アドイン関数をsection型補完にも対応し、仕様を固めた。
    3.21 +	領域指定のタイプセット直後のプレビューファイル候補は texput に。
    3.22 +	プロセス処理関係の関数を別ファイルに分けた。
    3.23 +	section型補完で、セクションタイトル(chapter, section, ...) は
    3.24 +	read-string で読み込むようにした。また、引数0を付加することにより
    3.25 +	明示的に read-string での読み込みを指定可能。
    3.26 +	yatexadd.el が load-path 中にある場合のみ自動的にロードする。
    3.27 +
    3.28 +1.39:	編集しながらタイプセット画面をスクロール。
    3.29 +	BibTeX 起動の追加。タイプセットプロセスの中断。
    3.30 +	jlatex の ? プロンプトに対して、文字列を送れるようにした。
    3.31 +
    3.32  1.38:	YaTeX-nervous が t の時、一時的、またはカレントディレクトリでのみ
    3.33  	有効なテンポラリ辞書が利用可能。
    3.34  	section型補完に引数の数も埋め込み、これも学習する。
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/yatex.prj	Tue May 04 12:57:27 1993 +0000
     4.3 @@ -0,0 +1,14 @@
     4.4 +//今後の拡張予定//
     4.5 +
     4.6 +【section型補完の引数の候補】
     4.7 +
     4.8 +	(setq section-table
     4.9 +	      '(("part" 0) ;...段落コマンドなど...
    4.10 +		("documentstyle" 1 YaTeX:documentstyle)	;候補シンボル
    4.11 +		("setlength" 2 )))
    4.12 +
    4.13 +
    4.14 +Local Variables:
    4.15 +mode: text
    4.16 +fill-prefix: "	"
    4.17 +End:
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/yatexprc.el	Tue May 04 12:57:27 1993 +0000
     5.3 @@ -0,0 +1,594 @@
     5.4 +;;; -*- Emacs-Lisp -*-
     5.5 +;;; YaTeX process handler.
     5.6 +;;; yatexprc.el rev.1.42
     5.7 +;;; (c)1993 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     5.8 +;;; Last modified Tue May  4 21:49:59 1993 on figaro
     5.9 +;;; $Id$
    5.10 +
    5.11 +(require 'yatex)
    5.12 +
    5.13 +(defvar YaTeX-typeset-process nil
    5.14 +  "Process identifier for jlatex"
    5.15 +)
    5.16 +(defvar YaTeX-typeset-buffer "*YaTeX-typesetting*"
    5.17 +  "Process buffer for jlatex")
    5.18 +
    5.19 +(defun YaTeX-typeset (command buffer)
    5.20 +  "Execute jlatex (or other) to LaTeX typeset."
    5.21 +  (interactive)
    5.22 +  (if (and YaTeX-typeset-process
    5.23 +	   (eq (process-status YaTeX-typeset-process) 'run))
    5.24 +      ;; if tex command is halting.
    5.25 +      (YaTeX-kill-typeset-process YaTeX-typeset-process))
    5.26 +  (YaTeX-visit-main t)  ;;execution directory
    5.27 +  (with-output-to-temp-buffer buffer
    5.28 +    (if (eq system-type 'ms-dos)			;if MS-DOS
    5.29 +	(progn
    5.30 +	  (message (concat "Typesetting " (buffer-name) "..."))
    5.31 +	  (YaTeX-put-nonstopmode)
    5.32 +	  (call-process shell-file-name
    5.33 +			nil buffer nil "/c" command)
    5.34 +	  (YaTeX-remove-nonstopmode))
    5.35 +      (setq YaTeX-typeset-process			;if UNIX
    5.36 +	      (start-process "LaTeX" buffer shell-file-name "-c"
    5.37 +			     command))
    5.38 +      (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
    5.39 +  (setq current-TeX-buffer (buffer-name))
    5.40 +  (other-window 1)
    5.41 +  (use-local-map YaTeX-typesetting-mode-map)
    5.42 +  (setq mode-name "typeset")
    5.43 +  (if YaTeX-typeset-process ; if process is running (maybe on UNIX)
    5.44 +      (cond ((boundp 'MULE)
    5.45 +	     (set-current-process-coding-system
    5.46 +	      YaTeX-latex-message-code YaTeX-coding-system))
    5.47 +	    ((boundp 'NEMACS)
    5.48 +	     (set-kanji-process-code YaTeX-latex-message-code))))
    5.49 +  (message "Type SPC to continue.")
    5.50 +  (goto-char (point-max))
    5.51 +  (if (eq system-type 'ms-dos) (message "Done.")
    5.52 +    (while (bobp) (message "Invoking process. wait...") (sleep-for 1))
    5.53 +    (insert (message " ")))
    5.54 +  (if (bolp) (forward-line -1))
    5.55 +  (recenter -1)
    5.56 +  (other-window -1)
    5.57 +)
    5.58 +
    5.59 +(defun YaTeX-typeset-sentinel (proc mes)
    5.60 +  (cond ((null (buffer-name (process-buffer proc)))
    5.61 +         ;; buffer killed
    5.62 +         (set-process-buffer proc nil))
    5.63 +        ((memq (process-status proc) '(signal exit))
    5.64 +         (let* ((obuf (current-buffer)))
    5.65 +           ;; save-excursion isn't the right thing if
    5.66 +           ;;  process-buffer is current-buffer
    5.67 +           (unwind-protect
    5.68 +               (progn
    5.69 +                 ;; Write something in *typesetting* and hack its mode line
    5.70 +		 (if (equal (current-buffer) (process-buffer proc))
    5.71 +		     nil
    5.72 +		   (other-window 1)
    5.73 +		   (switch-to-buffer (process-buffer proc))
    5.74 +		   (goto-char (point-max))
    5.75 +		   (recenter -3)
    5.76 +		   (other-window -1))
    5.77 +		 (set-buffer (process-buffer proc))
    5.78 +                 (goto-char (point-max))
    5.79 +                 (insert ?\n "latex typesetting " mes)
    5.80 +                 (forward-char -1)
    5.81 +                 (insert " at " (substring (current-time-string) 0 -5) "\n")
    5.82 +                 (forward-char 1)
    5.83 +                 (setq mode-line-process
    5.84 +                       (concat ": "
    5.85 +                               (symbol-name (process-status proc))))
    5.86 +		 (message "latex typesetting done.")
    5.87 +                 ;; If buffer and mode line will show that the process
    5.88 +                 ;; is dead, we can delete it now.  Otherwise it
    5.89 +                 ;; will stay around until M-x list-processes.
    5.90 +                 (delete-process proc)
    5.91 +		 )
    5.92 +             (setq YaTeX-typesetting-process nil)
    5.93 +             ;; Force mode line redisplay soon
    5.94 +             (set-buffer-modified-p (buffer-modified-p))
    5.95 +	     )
    5.96 +	   (set-buffer obuf))))
    5.97 +)
    5.98 +
    5.99 +(defvar YaTeX-texput-file "texput.tex"
   5.100 +  "*File name for temporary file of typeset-region."
   5.101 +)
   5.102 +
   5.103 +(defun YaTeX-typeset-region ()
   5.104 +  "Paste the region to the file `texput.tex' and execute jlatex (or other)
   5.105 +to LaTeX typeset.  The region is specified by the rule:
   5.106 +	(1)If keyword `%#BEGIN' is found in the upper direction from (point).
   5.107 +	  (1-1)if the keyword `%#END' is found after `%#BEGIN',
   5.108 +		->Assume the text between `%#BEGIN' and `%#END' as region.
   5.109 +	  (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN',
   5.110 +		->Assume the text after `%#BEGIN' as region.
   5.111 +	(2)If no `%#BEGIN' usage is found before the (point),
   5.112 +		->Assume the text between current (point) and (mark) as region.
   5.113 +DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing
   5.114 +operation to the region."
   5.115 +  (interactive)
   5.116 +  (save-excursion
   5.117 +    (let*
   5.118 +	((end "") typeout ;Type out message that tells the method of cutting.
   5.119 +	 (cmd (concat (YaTeX-get-latex-command nil) " " YaTeX-texput-file))
   5.120 +	 (buffer (current-buffer)) opoint preamble
   5.121 +	 (region
   5.122 +	  (if (re-search-backward
   5.123 +	       "%#BEGIN" nil t)
   5.124 +	      (progn
   5.125 +		(setq typeout "--- Region from BEGIN to " end "END ---")
   5.126 +		(buffer-substring
   5.127 +		 (match-end 0)
   5.128 +		 (if (re-search-forward "%#END" nil t)
   5.129 +		     (match-beginning 0)
   5.130 +		   (setq end "end of buffer ---")
   5.131 +		   (point-max))))
   5.132 +	    (setq typeout "=== Region from (point) to (mark) ===")
   5.133 +	    (buffer-substring (point) (mark)))))
   5.134 +      (YaTeX-visit-main t)
   5.135 +      (setq opoint (point))
   5.136 +      (goto-char (point-min))
   5.137 +      (setq
   5.138 +       preamble
   5.139 +       (if (re-search-forward "^[ 	]*\\\\begin.*{document}" nil t)
   5.140 +	   (buffer-substring (point-min) (match-end 0))
   5.141 +	 (concat "\\documentstyle{" YaTeX-default-document-style "}\n"
   5.142 +		 "\\begin{document}")))
   5.143 +      (goto-char opoint)
   5.144 +      ;;(set-buffer buffer)		;for clarity
   5.145 +      (find-file YaTeX-texput-file)
   5.146 +      (erase-buffer)
   5.147 +      (if YaTeX-need-nonstop
   5.148 +	  (insert "\\nonstopmode{}\n"))
   5.149 +      (insert preamble "\n")
   5.150 +      (insert region)
   5.151 +      (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
   5.152 +      (insert "\n\\end{document}\n")
   5.153 +      (basic-save-buffer)
   5.154 +      (kill-buffer (current-buffer))
   5.155 +      (YaTeX-visit-main t)
   5.156 +      (YaTeX-typeset cmd YaTeX-typeset-buffer)
   5.157 +      (put 'dvi2-command 'region t)))
   5.158 +)
   5.159 +
   5.160 +(defun YaTeX-typeset-buffer ()
   5.161 +  "Typeset whole buffer.  If %#! usage says other buffer is main text,
   5.162 +visit main buffer to confirm if its includeonly list contains current
   5.163 +buffer's file.  And if it doesn't contain editing text, ask user which
   5.164 +action want to be done, A:Add list, R:Replace list, %:comment-out list."
   5.165 +  (interactive)
   5.166 +  (YaTeX-save-buffers)
   5.167 +  (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.)))
   5.168 +	(mydir (file-name-directory (buffer-file-name)))
   5.169 +	(cmd (YaTeX-get-latex-command t)))
   5.170 +    (if (YaTeX-main-file-p) nil
   5.171 +      (save-excursion
   5.172 +	(YaTeX-visit-main t)	;search into main buffer
   5.173 +	(save-excursion
   5.174 +	  (push-mark (point) t)
   5.175 +	  (goto-char (point-min))
   5.176 +	  (if (and (re-search-forward "^[ 	]*\\\\begin{document}" nil t)
   5.177 +		   (re-search-backward "^[ 	]*\\\\includeonly{" nil t))
   5.178 +	      (let*
   5.179 +		  ((b (progn (skip-chars-forward "^{") (point)))
   5.180 +		   (e (progn (skip-chars-forward "^}") (1+ (point))))
   5.181 +		   (s (buffer-substring b e)) c
   5.182 +		   (pardir (file-name-directory (buffer-file-name))))
   5.183 +		(if (string-match (concat "[{,/]" me "[,}]") s)
   5.184 +		    nil ; Nothing to do when it's already in includeonly.
   5.185 +		  (ding)
   5.186 +		  (switch-to-buffer (current-buffer));Display this buffer.
   5.187 +		  (setq
   5.188 +		   me	  ;;Rewrite my name(me) to contain sub directory name.
   5.189 +		   (concat
   5.190 +		    (if (string-match pardir mydir) ;if mydir is child of main
   5.191 +			(substring mydir (length pardir)) ;cut absolute path
   5.192 +		      mydir) ;else concat absolute path name.
   5.193 +		    me))
   5.194 +		  (message
   5.195 +		   "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? "
   5.196 +		   me)
   5.197 +		  (setq c (read-char))
   5.198 +		  (cond
   5.199 +		   ((= c ?a)
   5.200 +		    (goto-char (1+ b))
   5.201 +		    (insert me (if (string= s "{}") "" ",")))
   5.202 +		   ((= c ?r)
   5.203 +		    (delete-region (1+ b) (1- e)) (insert me))
   5.204 +		   ((= c ?%)
   5.205 +		    (beginning-of-line) (insert "%"))
   5.206 +		   (t nil))
   5.207 +		  (basic-save-buffer))))
   5.208 +	  (exchange-point-and-mark))
   5.209 +	))
   5.210 +    (YaTeX-typeset cmd YaTeX-typeset-buffer)
   5.211 +    (put 'dvi2-command 'region nil))
   5.212 +)
   5.213 +
   5.214 +(defun YaTeX-bibtex-buffer ()
   5.215 +  "Pass the bibliography data of editing file to bibtex."
   5.216 +  (interactive)
   5.217 +  (YaTeX-save-buffers)
   5.218 +  (YaTeX-typeset
   5.219 +   (read-string "BibTeX command: "
   5.220 +		(concat bibtex-command " " (YaTeX-get-preview-file-name)))
   5.221 +   "*YaTeX-bibtex*" )
   5.222 +)
   5.223 +
   5.224 +(defun YaTeX-kill-typeset-process (proc)
   5.225 +  "Kill process PROC after sending signal to PROC.
   5.226 +PROC should be process identifier."
   5.227 +  (cond
   5.228 +   ((eq system-type 'ms-dos)
   5.229 +    (error "MS-DOS can't have concurrent process."))
   5.230 +   ((or (null proc) (not (eq (process-status proc) 'run)))
   5.231 +    (error "No typesetting process."))
   5.232 +   (t (interrupt-process proc)
   5.233 +      (delete-process proc)))
   5.234 +)
   5.235 +
   5.236 +(defun YaTeX-system (command buffer)
   5.237 +  "Execute some command on buffer.  Not a official function."
   5.238 +  (save-excursion
   5.239 +    (with-output-to-temp-buffer buffer
   5.240 +      (if (eq system-type 'ms-dos)
   5.241 +	  (call-process shell-file-name nil buffer nil "/c " command)
   5.242 +	(start-process "system" buffer shell-file-name "-c " command))))
   5.243 +)
   5.244 +
   5.245 +(defun YaTeX-preview (preview-command preview-file)
   5.246 +  "Execute xdvi (or other) to tex-preview."
   5.247 +  (interactive
   5.248 +   (list (read-string "Preview command: " dvi2-command)
   5.249 +	 (read-string "Prefiew file[.dvi]: "
   5.250 +		      ;;(substring (buffer-name) 0 -4)
   5.251 +		      (if (get 'dvi2-command 'region)
   5.252 +			  (substring YaTeX-texput-file
   5.253 +				     0 (rindex YaTeX-texput-file ?.))
   5.254 +			(YaTeX-get-preview-file-name))
   5.255 +		      )))
   5.256 +  (setq dvi2-command preview-command)
   5.257 +  (save-excursion
   5.258 +    (YaTeX-visit-main t)
   5.259 +    (with-output-to-temp-buffer "*dvi-preview*"
   5.260 +      (if (eq system-type 'ms-dos)
   5.261 +	  (progn (send-string-to-terminal "\e[2J")	;if MS-DOS
   5.262 +		 (call-process shell-file-name "con" "*dvi-preview*" nil
   5.263 +			       "/c " dvi2-command preview-file)
   5.264 +		 (redraw-display))
   5.265 +	(start-process "preview" "*dvi-preview*" shell-file-name "-c"
   5.266 +		       (concat dvi2-command " " preview-file)) ;if UNIX
   5.267 +	(message
   5.268 +	 (concat "Starting " dvi2-command " to preview " preview-file)))))
   5.269 +)
   5.270 +
   5.271 +(defun YaTeX-prev-error ()
   5.272 +  "Visit previous error.  The reason why not NEXT-error is to
   5.273 +avoid make confliction of line numbers by editing."
   5.274 +  (interactive)
   5.275 +  (let ((cur-buf (buffer-name))
   5.276 +	YaTeX-error-line error-buffer)
   5.277 +    (if (null (get-buffer YaTeX-typeset-buffer))
   5.278 +	(message "There is no output buffer of typesetting.")
   5.279 +      (pop-to-buffer YaTeX-typeset-buffer)
   5.280 +      (if (eq system-type 'ms-dos)
   5.281 +	  (if (search-backward latex-dos-emergency-message nil t)
   5.282 +	      (progn (goto-char (point-max))
   5.283 +		     (setq error-regexp latex-error-regexp))
   5.284 +	    (beginning-of-line)
   5.285 +	    (forward-char -1)
   5.286 +	    (setq error-regexp latex-warning-regexp))
   5.287 +	(if YaTeX-typeset-process      ; if jlatex on UNIX
   5.288 +	    (if (eq (process-status YaTeX-typeset-process) 'run)
   5.289 +		(progn
   5.290 +		  (goto-char (point-max))
   5.291 +		  (setq error-regexp latex-error-regexp))
   5.292 +	      (beginning-of-line)
   5.293 +	      (setq error-regexp latex-warning-regexp))))
   5.294 +      (if (re-search-backward error-regexp nil t)
   5.295 +	  (save-restriction
   5.296 +	    (set-mark-command nil)
   5.297 +	    (end-of-line)
   5.298 +	    (narrow-to-region (point) (mark))
   5.299 +	    (goto-char (point-min))
   5.300 +	    (re-search-forward "[0-9]")
   5.301 +	    (forward-char -1)
   5.302 +	    (set-mark (point))
   5.303 +	    (skip-chars-forward "0-9")
   5.304 +	    (narrow-to-region (point) (mark))
   5.305 +	    (goto-char (point-min))
   5.306 +	    (setq YaTeX-error-line (read (current-buffer))))
   5.307 +	(message "No more error on %s" cur-buf)
   5.308 +	(ding)
   5.309 +	)
   5.310 +      (setq error-buffer (YaTeX-get-error-file cur-buf))
   5.311 +      (other-window -1)
   5.312 +      (switch-to-buffer cur-buf)
   5.313 +      (if (null YaTeX-error-line)
   5.314 +	  nil
   5.315 +	;; if warning or error found
   5.316 +	(YaTeX-switch-to-buffer error-buffer)
   5.317 +	(goto-line YaTeX-error-line)
   5.318 +	(message "latex error or warning in '%s' at line: %d"
   5.319 +		 error-buffer YaTeX-error-line)
   5.320 +	(other-window 1)
   5.321 +	(skip-chars-backward "[0-9]")
   5.322 +	(recenter (/ (window-height) 2))
   5.323 +	(sit-for 3)
   5.324 +	(forward-char -1)
   5.325 +	(other-window -1)
   5.326 +	)))
   5.327 +)
   5.328 +
   5.329 +(defun YaTeX-jump-error-line ()
   5.330 +  "Jump corresponding line on latex command's error message."
   5.331 +  (interactive)
   5.332 +  (let ((p (point))
   5.333 +	(end (progn (end-of-line) (point)))
   5.334 +	(begin (progn (beginning-of-line)(point))))
   5.335 +    (if (null (re-search-forward "l[ ines]*\\.*[1-9][0-9]*" end t))
   5.336 +	(if (save-excursion (end-of-line) (eobp))
   5.337 +	    (progn (goto-char p) (insert (this-command-keys)))
   5.338 +	  (message "No line number expression"))
   5.339 +      (goto-char (match-beginning 0))
   5.340 +      (re-search-forward "[1-9][0-9]*" end t)
   5.341 +      (save-restriction
   5.342 +	(let ((error-line
   5.343 +	       (string-to-int (buffer-substring (match-beginning 0)
   5.344 +						(match-end 0))))
   5.345 +	      (error-file (YaTeX-get-error-file current-TeX-buffer)))
   5.346 +	  ;;(goto-char (match-beginning 0))
   5.347 +	  (other-window -1)
   5.348 +	  (message "errors in %s" error-file)
   5.349 +	  ;(switch-to-buffer current-TeX-buffer)
   5.350 +	  (if (not (YaTeX-switch-to-buffer error-file))
   5.351 +	      (error "%s is not found in this directory."))
   5.352 +	  (goto-line error-line)))))
   5.353 +)
   5.354 +
   5.355 +(defun YaTeX-send-string ()
   5.356 +  "Send string to current typeset process."
   5.357 +  (interactive)
   5.358 +  (if (and (eq (process-status YaTeX-typeset-process) 'run)
   5.359 +	   (>= (point) (process-mark YaTeX-typeset-process)))
   5.360 +      (let ((b (process-mark YaTeX-typeset-process))
   5.361 +	    (e (point-end-of-line)))
   5.362 +	(goto-char b)
   5.363 +	(skip-chars-forward " \t" e)
   5.364 +	(setq b (point))
   5.365 +	(process-send-string
   5.366 +	 YaTeX-typeset-process (concat (buffer-substring b e) "\n"))
   5.367 +	(goto-char e)
   5.368 +	(insert "\n")
   5.369 +	(set-marker (process-mark YaTeX-typeset-process) (point))
   5.370 +	(insert " "))
   5.371 +    (ding))
   5.372 +)
   5.373 +
   5.374 +(defun YaTeX-view-error ()
   5.375 +  (interactive)
   5.376 +  (if (null (get-buffer YaTeX-typeset-buffer))
   5.377 +      (message "No typeset buffer found.")
   5.378 +    (pop-to-buffer YaTeX-typeset-buffer)
   5.379 +    (goto-char (point-max))
   5.380 +    (recenter -1)
   5.381 +    (other-window -1))
   5.382 +)
   5.383 +
   5.384 +(defun YaTeX-get-error-file (default)
   5.385 +  "Get current processing file from typesetting log."
   5.386 +  (save-excursion
   5.387 +    (let(s)
   5.388 +      (condition-case () (up-list -1)
   5.389 +	(error
   5.390 +	 (let ((list 0) found)
   5.391 +	   (while
   5.392 +	       (and (<= list 0) (not found)
   5.393 +		    (re-search-backward "\\((\\)\\|\\()\\)" nil t))
   5.394 +	     (if (equal (match-beginning 0) (match-beginning 2)) ;close paren.
   5.395 +		 (setq list (1- list)) ;open paren
   5.396 +	       (setq list (1+ list))
   5.397 +	       (if (= list 1)
   5.398 +		   (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty")
   5.399 +		       (setq found t)
   5.400 +		     (setq list (1- list)))))))))
   5.401 +      (setq s
   5.402 +	    (buffer-substring
   5.403 +	     (progn (forward-char 1) (point))
   5.404 +	     (progn (skip-chars-forward "-A-Za-z0-9_/\.\\" (point-end-of-line))
   5.405 +		    (point))))
   5.406 +      (if (string= "" s) default s)))
   5.407 +)
   5.408 +      
   5.409 +(defun YaTeX-put-nonstopmode ()
   5.410 +  (if YaTeX-need-nonstop
   5.411 +      (if (re-search-backward "\\nonstopmode{}" (point-min) t)
   5.412 +	  nil                    ;if already written in text then do nothing
   5.413 +	(save-excursion
   5.414 +	  (YaTeX-visit-main t)
   5.415 +	  (goto-char (point-min))
   5.416 +	  (insert "\\nonstopmode{}%_YaTeX_%\n")))
   5.417 +    )
   5.418 +)
   5.419 +
   5.420 +(defun YaTeX-remove-nonstopmode ()
   5.421 +  (if YaTeX-need-nonstop ;for speed
   5.422 +      (save-excursion
   5.423 +	(YaTeX-visit-main t)
   5.424 +	(goto-char (point-min))
   5.425 +	(forward-line 1)
   5.426 +	(narrow-to-region (point-min) (point))
   5.427 +	(goto-char (point-min))
   5.428 +	(delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$")
   5.429 +	(widen)))
   5.430 +)
   5.431 +
   5.432 +(defun YaTeX-get-preview-file-name ()
   5.433 +  "Get file name to preview by inquiring YaTeX-get-latex-command"
   5.434 +  (let* ((latex-cmd (YaTeX-get-latex-command t))
   5.435 +	 (rin (rindex latex-cmd ? ))
   5.436 +	 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
   5.437 +	 (period))
   5.438 +    (if (string= fname "")
   5.439 +	(setq fname (substring (buffer-name) 0 -4))
   5.440 +      (setq period (rindex fname ?.))
   5.441 +      (setq fname (substring fname 0 (if (eq -1 period) nil period)))
   5.442 +      ))
   5.443 +)
   5.444 +
   5.445 +(defun YaTeX-get-latex-command (&optional switch)
   5.446 +  "Specify the latex-command name and its argument.
   5.447 +If there is a line which begins by string: \"%#!\", the following
   5.448 +strings are assumed to be the latex-command and arguments.  The
   5.449 +default value of latex-command is:
   5.450 +	tex-command (buffer-name)
   5.451 +and if you write \"%#!jlatex\" in the beginning of certain line.
   5.452 +	\"jlatex \" (buffer-name)
   5.453 +will be the latex-command,
   5.454 +and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
   5.455 +is t, then
   5.456 +	\"jlatex main.tex\"
   5.457 +will be given to the shell."
   5.458 +  (let*
   5.459 +      ((default-command
   5.460 +	 (concat tex-command " "
   5.461 +		 (if switch (buffer-name) ""))));default value
   5.462 +    (save-excursion
   5.463 +      (goto-char (point-min))
   5.464 +      (if (null (re-search-forward "^%#!" (point-max) t))
   5.465 +	  default-command
   5.466 +	(skip-chars-forward "%#! 	")
   5.467 +	(if (eolp)
   5.468 +	    default-command
   5.469 +	  (let ((s (point)))
   5.470 +	    (skip-chars-forward "^ 	" (point-end-of-line)) ;Skip command
   5.471 +	    (skip-chars-forward " 	" (point-end-of-line))
   5.472 +	    ;(setq YaTeX-latex-command (buffer-substring s (point)))
   5.473 +	    (cond
   5.474 +	     ((null switch)
   5.475 +	      (buffer-substring s (point)))
   5.476 +	     ((eolp)			 ;Only return command name
   5.477 +	      (concat (buffer-substring s (point)) " " (buffer-name)))
   5.478 +	     (t(end-of-line)		   ;Change entire command name
   5.479 +	       (buffer-substring s (point))) ;including arguments.
   5.480 +	    ))
   5.481 +	))))
   5.482 +)
   5.483 +
   5.484 +(defun YaTeX-replace-format (string format repl)
   5.485 +  "In STRING, replace first appearance of FORMAT to REPL as if
   5.486 +function `format' does.  FORMAT does not contain `%'"
   5.487 +  (let ((beg (or (string-match (concat "^\\(%" format "\\)") string)
   5.488 +		 (string-match (concat "[^%]\\(%" format "\\)") string)))
   5.489 +	(len (length format)))
   5.490 +    (if (null beg) string ;no conversion
   5.491 +      (concat
   5.492 +       (substring string 0 (match-beginning 1)) repl
   5.493 +       (substring string (match-end 1)))))
   5.494 +)
   5.495 +
   5.496 +(defun YaTeX-lpr (arg)
   5.497 +  "Print out.  If prefix arg ARG is non nil, call print driver without
   5.498 +page range description."
   5.499 +  (interactive "P")
   5.500 +  (let*(from to (cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)))
   5.501 +    (setq
   5.502 +     cmd 
   5.503 +     (YaTeX-replace-format
   5.504 +      cmd "f"
   5.505 +      (if (or arg (not (string-match "%f" cmd)))
   5.506 +	      ""
   5.507 +	    (YaTeX-replace-format
   5.508 +	     dviprint-from-format
   5.509 +	     "b"
   5.510 +	     (if (string=
   5.511 +		  (setq from (read-string "From page(default 1): ")) "")
   5.512 +		 "1" from))))
   5.513 +       )
   5.514 +    (setq
   5.515 +     cmd
   5.516 +     (YaTeX-replace-format
   5.517 +      cmd "t"
   5.518 +      (if (or arg (not (string-match "%t" cmd))
   5.519 +	      (string= 
   5.520 +	       (setq to (read-string "To page(default none): ")) ""))
   5.521 +	  ""
   5.522 +	(YaTeX-replace-format dviprint-to-format "e" to)))
   5.523 +     )
   5.524 +    (setq cmd (read-string "Edit command line: "
   5.525 +			   (format cmd (YaTeX-get-preview-file-name))))
   5.526 +    (save-excursion
   5.527 +      (YaTeX-visit-main t) ;;change execution directory
   5.528 +      (with-output-to-temp-buffer "*dvi-printing*"
   5.529 +	(if (eq system-type 'ms-dos)
   5.530 +	    (call-process shell-file-name "con" "*dvi-printing*" nil
   5.531 +			  "/c " cmd)
   5.532 +	  (start-process "print" "*dvi-printing*" shell-file-name "-c" cmd)
   5.533 +	  (message (concat "Starting " cmd " to printing "
   5.534 +			   (YaTeX-get-preview-file-name))))
   5.535 +    )))
   5.536 +)
   5.537 +
   5.538 +(defun YaTeX-main-file-p ()
   5.539 +  "Return if current buffer is main LaTeX source."
   5.540 +  (string-match (concat "^" (YaTeX-get-preview-file-name) ".tex")(buffer-name))
   5.541 +)
   5.542 +
   5.543 +(defun YaTeX-visit-main (&optional setbuf)
   5.544 +  "Switch to buffer main LaTeX source.  Use set-buffer instead of
   5.545 +switch-to-buffer if optional second argument SETBUF is t(Use it only
   5.546 +in Emacs-Lisp program)."
   5.547 +  (interactive)
   5.548 +  (let ((main-file (YaTeX-get-preview-file-name)))
   5.549 +    (if (string-match (concat "^" main-file ".tex") (buffer-name))
   5.550 +	(if (interactive-p) (message "I think this is main LaTeX source.") nil)
   5.551 +      (cond
   5.552 +       ((YaTeX-switch-to-buffer (setq main-file (concat main-file ".tex"))
   5.553 +				setbuf))
   5.554 +       ((and (file-exists-p (setq main-file (concat "../" main-file)))
   5.555 +	     (y-or-n-p (concat (expand-file-name main-file)
   5.556 +			       " is main file?:")))
   5.557 +	(YaTeX-switch-to-buffer main-file setbuf))
   5.558 +       (t (find-file (read-file-name "Enter your main text: " nil nil 1)))
   5.559 +	)))
   5.560 +  nil
   5.561 +)
   5.562 +
   5.563 +(defun YaTeX-visit-main-other-window ()
   5.564 +  "Switch to buffer main LaTeX source in other window."
   5.565 +  (interactive)
   5.566 +  (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
   5.567 +      (YaTeX-switch-to-buffer-other-window
   5.568 +       (concat (YaTeX-get-preview-file-name) ".tex")))
   5.569 +)
   5.570 +
   5.571 +(defun YaTeX-get-builtin (key)
   5.572 +  "Read source built-in command of %# usage."
   5.573 +  (save-excursion
   5.574 +    (goto-char (point-min))
   5.575 +    (if (and (search-forward (concat "%#" key) nil t)
   5.576 +	     (not (eolp)))
   5.577 +	(buffer-substring
   5.578 +	 (progn (skip-chars-forward " 	" (point-end-of-line))(point))
   5.579 +	 (point-end-of-line))
   5.580 +      nil))
   5.581 +)
   5.582 +
   5.583 +(defun YaTeX-save-buffers ()
   5.584 +  "Save buffers which is in yatex-mode."
   5.585 +  (basic-save-buffer)
   5.586 +  (save-excursion
   5.587 +    (mapcar '(lambda (buf)
   5.588 +	       (set-buffer buf)
   5.589 +	       (if (and (buffer-file-name buf)
   5.590 +			(eq major-mode 'yatex-mode)
   5.591 +			(buffer-modified-p buf)
   5.592 +			(y-or-n-p (format "Save %s" (buffer-name buf))))
   5.593 +		   (save-buffer buf)))
   5.594 +	    (buffer-list)))
   5.595 +)
   5.596 +
   5.597 +(provide 'yatexprc)