yatex

changeset 12:a7f397790cdc

Revise YaTeX-typeset faster. Optimize window selection of error-jump.
author yuuji
date Mon, 25 Oct 1993 14:35:00 +0000
parents 390df0e505da
children eafae54794a0
files docs/yatexadd.doc docs/yatexgen.doc yatex.el yatex.new yatexadd.el yatexprc.el
diffstat 6 files changed, 147 insertions(+), 70 deletions(-) [+]
line diff
     1.1 --- a/docs/yatexadd.doc	Mon Sep 20 08:56:09 1993 +0000
     1.2 +++ b/docs/yatexadd.doc	Mon Oct 25 14:35:00 1993 +0000
     1.3 @@ -34,15 +34,84 @@
     1.4  	を定義するファイル名を yatexadd.el(またはバイトコンパイルした形式
     1.5  	のyatexadd.elc)にし、そのファイルを load-path 中に置いておけば、 
     1.6  	野鳥が自動的にロードします。それ以外のファイル名にする場合は、
     1.7 -	yatex-mode-hook に、付加関数を定義する Emacs-Lisp ファイルをロード
     1.8 -	するような仕掛けを書いておくのがよいでしょう。
     1.9 +	yatex-mode-hook に付加関数を定義する Emacs-Lisp ファイルをロードす
    1.10 +	るような仕掛けを書いておくのがよいでしょう。
    1.11  
    1.12  
    1.13 -【関数名】
    1.14 +【関数定義】
    1.15  
    1.16 -	  作成する付加関数名は、補完入力した名前の先頭に YaTeX: を付け足し
    1.17 -	たものにします。例えば(begin型補完の) tabular 環境に対して付加関数
    1.18 -	を作成したい場合は YaTeX:tabular という関数名で定義します。
    1.19 +	  付加関数には、各LaTeXコマンドのオプション引数を返す形式のもの、
    1.20 +	section型補完の引数を返すもの、の二種類があります。
    1.21 +
    1.22 +	  前者は、以下の例のように、begin型補完では\begin{環境名}の直後に
    1.23 +	付加する文字列、section型補完では LaTeX コマンド名と第一引数の間に
    1.24 +	位置する文字列、maketitle型補完では LaTeX コマンド名の直後に位置す
    1.25 +	る文字列を返すような関数です。便宜上この形の付加関数を、追加型付加
    1.26 +	関数と呼ぶことにします。
    1.27 +
    1.28 +	(例)	\begin{table}[ht]	(付加関数名 YaTeX:table)
    1.29 +		             ~~~~
    1.30 +		\put(100,200){}		(付加関数名 YaTeX:put)
    1.31 +		    ~~~~~~~~~
    1.32 +		\sum_{i=0}^{n}		(付加関数名 YaTeX:sum)
    1.33 +		    ~~~~~~~~~~
    1.34 +
    1.35 +	追加型付加関数は『LaTeXコマンド名の前に YaTeX: をつけた名前』で定
    1.36 +	義します。
    1.37 +
    1.38 +	  後者は、以下のようにsection型コマンドの引数となる文字列を返す
    1.39 +	関数です。この形の付加関数を引数型付加関数と呼ぶことにします。
    1.40 +
    1.41 +	(例)	\newcommand{\foo}{bar}	(付加関数名 YaTeX::newcommand)
    1.42 +			    ~~~~  ~~~
    1.43 +
    1.44 +	引数型付加関数は『LaTeXコマンド名の前に YaTeX:: をつけた名前』で定
    1.45 +	義します。また引数型付加関数が呼ばれる時には何番目の引数を入力して
    1.46 +	いるのかが引数として渡されます。したがって、引数型付加関数は整数の
    1.47 +	引数を一つ取るものとして定義し、その引数の値により処理を決定するこ
    1.48 +	とになります。
    1.49 +
    1.50 +
    1.51 +【定義例】
    1.52 +
    1.53 +	  例えば、tabular環境のフォーマットとして、いつでも {|c|c|c|} を入
    1.54 +	れるだけで良いのなら、
    1.55 +
    1.56 +		(defun YaTeX:tabular ()
    1.57 +		  "{|c|c|c|}")
    1.58 +
    1.59 +	とだけ書けばよく、前述の、複雑な定型 tabular フォーマットを挿入す
    1.60 +	るための関数を定義する場合は次のようにします。
    1.61 +
    1.62 +		(defun YaTeX:tabular ()
    1.63 +		  "{@{\\vrule width 1pt\\ }|||@{\\ \\vrule width 1pt}}")
    1.64 +
    1.65 +	この時、Emacs-Lisp 中の文字列では、\ 自身は \\ と表記することなど
    1.66 +	に注意して下さい。
    1.67 +
    1.68 +	  また、{} の中を、補完時に直接キーボードから読み込ませたい時は、
    1.69 +
    1.70 +		(defun YaTeX:tabular ()
    1.71 +		  (concat "{" (read-string "Rule: ") "}"))
    1.72 +
    1.73 +	などとすれば良いでしょう。
    1.74 +
    1.75 +	  次に、引数型付加関数として \newcommand の引数を読み込む関数を定
    1.76 +	義する場合を例示します。\newcommand の第一引数は新たに定義するコマ
    1.77 +	ンド名なので、必ず先頭に \ が来ます。第二引数はたいていの場合ミニ
    1.78 +	バッファでは編集しづらいような複雑な定義を書くので、何も補完しない
    1.79 +	方が良いでしょう。これを考慮して付加関数を定義すると以下のようなも
    1.80 +	のになるでしょう。
    1.81 +
    1.82 +		(defun YaTeX::newcommand (n)	;nは引数の位置
    1.83 +		  (cond
    1.84 +		   ((= n 1)			;第一引数ならコマンド名
    1.85 +		    (concat "\\" (read-string "Command: ")))
    1.86 +		   ((= n 2) "")			;第二引数なら何も入れない
    1.87 +		   (t nil)))
    1.88 +
    1.89 +	なお、引数型付加関数が nil を返した場合は、通常の引数入力関数が呼
    1.90 +	ばれます。
    1.91  
    1.92  
    1.93  【呼ばれ方】
    1.94 @@ -51,42 +120,8 @@
    1.95  	入力時に付加関数の存在を調べてから呼び出します。begin型補完の場合 
    1.96  	\begin{環境名} が自動入力された直後に呼び出されます。section型補完
    1.97  	では第一引数の補完の直前、maketitle型補完の場合は、コマンド名の直
    1.98 -	後(一つのスペースを挿入する直前)に呼び出されます。
    1.99 -
   1.100 -
   1.101 -【関数定義】
   1.102 -
   1.103 -	  begin型補完では、\begin{環境名}の直後に付加する文字列、section型
   1.104 -	補完では、LaTeXコマンド名と第一引数の間に位置する文字列、maketitle
   1.105 -	型補完では、LaTeXコマンド名の直後に位置する文字列を返すような関数
   1.106 -	を定義して下さい。
   1.107 -	(例)
   1.108 -		\begin{table}[ht]
   1.109 -		             ~~~~
   1.110 -		\put(100,200){}
   1.111 -		    ~~~~~~~~~
   1.112 -		\sum_{i=0}^{n} 
   1.113 -		    ~~~~~~~~~~
   1.114 -	たんに、いつでも {|c|c|c|} を入れるだけで良いのなら、
   1.115 -
   1.116 -		(defun YaTeX:tabular ()
   1.117 -		  "{|c|c|c|}")
   1.118 -
   1.119 -	とだけ、書けばよく、前述の、複雑な定型 tabular フォーマットを挿入
   1.120 -	するための関数を定義する場合は、次のようにします。
   1.121 -
   1.122 -		(defun YaTeX:tabular ()
   1.123 -		  "{@{\\vrule width 1pt\\ }|||@{\\ \\vrule width 1pt}}")
   1.124 -
   1.125 -	この時、Emacs-Lisp 中の文字列では、\ 自身は、\\ と表記することなどに
   1.126 -	注意して下さい。
   1.127 -
   1.128 -	  また、{} の中を、補完時に直接キーボードから読み込ませたい時は、
   1.129 -
   1.130 -		(defun YaTeX:tabular ()
   1.131 -		  (concat "{" (read-string "Rule: ") "}"))
   1.132 -
   1.133 -	などとすれば良いでしょう。
   1.134 +	後(一つのスペースを挿入する直前)に呼び出されます。引数型付加関数は、
   1.135 +	section型コマンドの引数の入力時にその都度呼ばれます。
   1.136  
   1.137  
   1.138  【参考】
     2.1 --- a/docs/yatexgen.doc	Mon Sep 20 08:56:09 1993 +0000
     2.2 +++ b/docs/yatexgen.doc	Mon Oct 25 14:35:00 1993 +0000
     2.3 @@ -9,7 +9,7 @@
     2.4  
     2.5  【はじめに】
     2.6  
     2.7 -	  まず、yatexadd.doc には目を通して下さい。これを読んで、なにか独
     2.8 +	  まず、yatexadd.doc には目を通して下さい。それを読んで、なにか独
     2.9  	自の関数をすぐに作りたくなったあなたには、このドキュメントも、
    2.10  	yatexgen.el も必要有りません。しかし、Emacs-Lisp をよく知らないた
    2.11  	め、どのように作ってよいのかピンと来ない方のために、野鳥自身に付加
     3.1 Binary file yatex.el has changed
     4.1 --- a/yatex.new	Mon Sep 20 08:56:09 1993 +0000
     4.2 +++ b/yatex.new	Mon Oct 25 14:35:00 1993 +0000
     4.3 @@ -2,6 +2,11 @@
     4.4  	Yet Another tex-mode for Emacs
     4.5  	yatex.el 各バージョンの変更点について。
     4.6  
     4.7 +1.44:	タイプセットプログラムの起動処理を高速化。
     4.8 +	エラージャンプのウィンドウ利用の最適化。
     4.9 +	数式モード/修正モードのモードライン表示修正。
    4.10 +	数式環境補完時には自動的に数式モードに入る。
    4.11 +
    4.12  1.43:	環境のネストに応じたインデント(変数YaTeX-environment-indentで指定)。
    4.13  	数式環境記号補完モード(yatexmth)添付。
    4.14  	modify-mode の値で開き括弧の動作を決定する。
     5.1 --- a/yatexadd.el	Mon Sep 20 08:56:09 1993 +0000
     5.2 +++ b/yatexadd.el	Mon Oct 25 14:35:00 1993 +0000
     5.3 @@ -2,7 +2,7 @@
     5.4  ;;; YaTeX add-in functions.
     5.5  ;;; yatexadd.el rev.5
     5.6  ;;; (c)1991-1993 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     5.7 -;;; Last modified Sat Sep 18 04:13:41 1993 on 98fa
     5.8 +;;; Last modified Wed Oct  6 03:40:30 1993 on 98fa
     5.9  ;;; $Id$
    5.10  
    5.11  (provide 'yatexadd)
    5.12 @@ -73,6 +73,13 @@
    5.13  	  (YaTeX:read-coordinates "Initial position"))
    5.14  )
    5.15  
    5.16 +(defun YaTeX:equation ()
    5.17 +  (if (fboundp 'YaTeX-toggle-math-mode)
    5.18 +      (YaTeX-toggle-math-mode t))		;force math-mode ON.
    5.19 +)
    5.20 +(fset 'YaTeX:eqnarray 'YaTeX:equation)
    5.21 +(fset 'YaTeX:displaymath 'YaTeX:equation)
    5.22 +
    5.23  ;;;
    5.24  ;;Sample functions for section-type command.
    5.25  ;;;
    5.26 @@ -224,6 +231,8 @@
    5.27  	(goto-char (point-min))
    5.28  	(message "Collecting labels...")
    5.29  	(save-window-excursion
    5.30 +	  (YaTeX-showup-buffer
    5.31 +	   YaTeX-label-buffer (function (lambda (x) (window-width x))))
    5.32  	  (with-output-to-temp-buffer YaTeX-label-buffer
    5.33  	    (while (re-search-forward "\\label{\\([^}]+\\)}" nil t)
    5.34  	      (setq e0 (match-end 0) m1 (match-beginning 1) e1 (match-end 1))
    5.35 @@ -272,6 +281,8 @@
    5.36  (defun YaTeX-label-other ()
    5.37    (let ((lbuf "*YaTeX mode buffers*") (blist (buffer-list)) (lnum -1) buf rv
    5.38  	(ff "**find-file**"))
    5.39 +    (YaTeX-showup-buffer
    5.40 +     lbuf (function (lambda (x) 1)))	;;Select next window surely.
    5.41      (with-output-to-temp-buffer lbuf
    5.42        (while blist
    5.43  	(if (and (buffer-file-name (setq buf (car blist)))
     6.1 --- a/yatexprc.el	Mon Sep 20 08:56:09 1993 +0000
     6.2 +++ b/yatexprc.el	Mon Oct 25 14:35:00 1993 +0000
     6.3 @@ -1,8 +1,8 @@
     6.4  ;;; -*- Emacs-Lisp -*-
     6.5  ;;; YaTeX process handler.
     6.6 -;;; yatexprc.el rev.1.43
     6.7 +;;; yatexprc.el rev.1.44
     6.8  ;;; (c)1993 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     6.9 -;;; Last modified Sat Sep 18 04:12:18 1993 on 98fa
    6.10 +;;; Last modified Mon Oct 25 17:48:39 1993 on figaro
    6.11  ;;; $Id$
    6.12  
    6.13  (require 'yatex)
    6.14 @@ -28,31 +28,34 @@
    6.15  (defun YaTeX-typeset (command buffer)
    6.16    "Execute jlatex (or other) to LaTeX typeset."
    6.17    (interactive)
    6.18 -  (if (and YaTeX-typeset-process
    6.19 -	   (eq (process-status YaTeX-typeset-process) 'run))
    6.20 -      ;; if tex command is halting.
    6.21 -      (YaTeX-kill-typeset-process YaTeX-typeset-process))
    6.22 -  (YaTeX-visit-main t)  ;;execution directory
    6.23 -  (with-output-to-temp-buffer buffer
    6.24 -    (if (eq system-type 'ms-dos)			;if MS-DOS
    6.25 -	(progn
    6.26 -	  (message (concat "Typesetting " (buffer-name) "..."))
    6.27 -	  (YaTeX-put-nonstopmode)
    6.28 -	  (call-process shell-file-name
    6.29 -			nil buffer nil "/c" command)
    6.30 -	  (YaTeX-remove-nonstopmode))
    6.31 -      (setq YaTeX-typeset-process			;if UNIX
    6.32 +  (let ((window (selected-window)))
    6.33 +    (if (and YaTeX-typeset-process
    6.34 +	     (eq (process-status YaTeX-typeset-process) 'run))
    6.35 +	;; if tex command is halting.
    6.36 +	(YaTeX-kill-typeset-process YaTeX-typeset-process))
    6.37 +    (YaTeX-visit-main t);;execution directory
    6.38 +    ;;Select under-most window if there are more than 2 windows and
    6.39 +    ;;typeset buffer isn't seen.
    6.40 +    (YaTeX-showup-buffer
    6.41 +     buffer (function (lambda (x) (nth 3 (window-edges x)))))
    6.42 +    (with-output-to-temp-buffer buffer
    6.43 +      (if (eq system-type 'ms-dos)	;if MS-DOS
    6.44 +	  (progn
    6.45 +	    (message (concat "Typesetting " (buffer-name) "..."))
    6.46 +	    (YaTeX-put-nonstopmode)
    6.47 +	    (call-process shell-file-name
    6.48 +			  nil buffer nil "/c" command)
    6.49 +	    (YaTeX-remove-nonstopmode))
    6.50 +	(setq YaTeX-typeset-process	;if UNIX
    6.51  	      (start-process "LaTeX" buffer shell-file-name "-c"
    6.52  			     command))
    6.53 -      (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
    6.54 -  (setq current-TeX-buffer (buffer-name))
    6.55 -  (let ((window (selected-window)))
    6.56 +	(set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
    6.57 +    (setq current-TeX-buffer (buffer-name))
    6.58      (select-window (get-buffer-window buffer))
    6.59 -    ;;(other-window 1)
    6.60      (use-local-map YaTeX-typesetting-mode-map)
    6.61      (set-syntax-table YaTeX-typeset-buffer-syntax)
    6.62      (setq mode-name "typeset")
    6.63 -    (if YaTeX-typeset-process ; if process is running (maybe on UNIX)
    6.64 +    (if YaTeX-typeset-process		; if process is running (maybe on UNIX)
    6.65  	(cond ((boundp 'MULE)
    6.66  	       (set-current-process-coding-system
    6.67  		YaTeX-latex-message-code YaTeX-coding-system))
    6.68 @@ -61,13 +64,11 @@
    6.69      (message "Type SPC to continue.")
    6.70      (goto-char (point-max))
    6.71      (if (eq system-type 'ms-dos) (message "Done.")
    6.72 -      (while (bobp) (message "Invoking process. wait...") (sleep-for 1))
    6.73 -      (insert (message " ")))
    6.74 +      (insert (message " "))
    6.75 +      (set-marker (process-mark YaTeX-typeset-process) (1- (point))))
    6.76      (if (bolp) (forward-line -1))
    6.77      (recenter -1)
    6.78 -    (select-window window)
    6.79 -  ;;(other-window -1)
    6.80 -    )
    6.81 +    (select-window window))
    6.82  )
    6.83  
    6.84  (defun YaTeX-typeset-sentinel (proc mes)
    6.85 @@ -325,6 +326,7 @@
    6.86  	  nil
    6.87  	;; if warning or error found
    6.88  	(if error-win (select-window error-win)
    6.89 +	  (select-window (get-lru-window))
    6.90  	  (YaTeX-switch-to-buffer error-buffer)
    6.91  	  (setq error-win (selected-window)))
    6.92  	(goto-line YaTeX-error-line)
    6.93 @@ -614,4 +616,28 @@
    6.94      (pop-to-buffer buffer))
    6.95  )
    6.96  
    6.97 +(defun YaTeX-showup-buffer (buffer &optional func)
    6.98 +  "Make BUFFER show up in certain window (but current window)
    6.99 +that gives the maximum value by the FUNC.  FUNC should take an argument
   6.100 +of its window object"
   6.101 +  (or (get-buffer-window buffer)
   6.102 +      (< (length (YaTeX-window-list)) 3)
   6.103 +      (let ((window (selected-window)) (list (YaTeX-window-list)) win w (x 0))
   6.104 +	(while list
   6.105 +	  (setq w (car list))
   6.106 +	    (if (and (not (eq window w))
   6.107 +		     (> (funcall func w) x))
   6.108 +		(setq win w x (funcall func w)))
   6.109 +	    (setq list (cdr list)))
   6.110 +	(select-window win)
   6.111 +	(switch-to-buffer buffer)
   6.112 +	(select-window window)))
   6.113 +)
   6.114 +
   6.115 +(defun YaTeX-window-list ()
   6.116 +  (let*((curw (selected-window)) (win curw) (wlist (list curw)))
   6.117 +    (while (not (eq curw (setq win (next-window win))))
   6.118 +      (setq wlist (cons win wlist)))
   6.119 +    wlist)
   6.120 +)
   6.121  (provide 'yatexprc)