yatex

changeset 23:b00c74813e56

Change the YaTeX-math-mode's prefix from `,' to `;'. Add YaTeX-apropos, YaTeX-what-column, YaTeX-beginning-of-environment, YaTeX-end-of-environment. Add variables YaTeX-default-pop-window-height, YaTeX-close-paren-always, YaTeX-no-begend-shortcut, YaTeX-auto-math-mode. Remove Greek letters from maketitle-type. Make YaTeX-inner-environment two times faster and more reliable. C-u for [prefix] k kills contents too. Fix the detection of the range of section-type commands when nested. Add \end{ completion. Add YaTeX-generate-simple. Refine documents(using Texinfo). %#REQUIRE for sub-preambles.
author yuuji
date Thu, 07 Jul 1994 16:37:05 +0000
parents 9d2387100375
children 21a751ddf614
files yatex.new yatexadd.el yatexenv.el yatexgen.el yatexhks.el yatexhlp.el yatexlib.el yatexmth.el yatexprc.el yatexsec.el
diffstat 10 files changed, 1382 insertions(+), 218 deletions(-) [+]
line diff
     1.1 --- a/yatex.new	Thu Jul 07 16:37:05 1994 +0000
     1.2 +++ b/yatex.new	Thu Jul 07 16:37:05 1994 +0000
     1.3 @@ -1,6 +1,36 @@
     1.4  	Yet Another tex-mode for Emacs
     1.5  	yatex.el 各バージョンの変更点について。
     1.6  
     1.7 +1.50	YaTeX-math モードの記号用 prefix を , から ; に変えた(注意!)。
     1.8 +	イメージ補完の一覧表示キーを RET から TAB に変えた(注意!)。
     1.9 +	[prefix] / の YaTeX-apropos の追加。
    1.10 +	[prefix] & の YaTeX-what-column の追加。
    1.11 +	YaTeX-math モードは自動判定するようにした。YaTeX-math モード用の
    1.12 +	prefix を強制的に活かす時は C-u ; などとする。
    1.13 +	YaTeX-beginning-of-environment(ESC C-a)
    1.14 +	YaTeX-end-of-environment(ESC C-e)
    1.15 +	YaTeX-mark-environment(ESC C-@) をそれぞれ追加。
    1.16 +	YaTeX-default-pop-window-height でデフォルトのタイプセットバッ
    1.17 +	ファの高さを指定できるようにした。数値を指定するとタイプセットバッ
    1.18 +	ファの行数、数字文字列でEmacsウィンドウの高さに対する百分率。
    1.19 +	YaTeX-close-paren-always がt、かつ新規入力モードなら常に開き括弧
    1.20 +	の入力で閉じ括弧も入力する(デフォルトはt)。
    1.21 +	ギリシャ文字補完候補を maketitle 型補完から除去。
    1.22 +	YaTeX-end-environment で呼んでいる YaTeX-inner-environment の高速化。
    1.23 +	YaTeX-end-environment で次の\end検索がうまく行かないバグを直した。
    1.24 +	C-u [prefix] k でLaTeXコマンドとその中身を同時削除するようにし、
    1.25 +	子ファイルでpreview用コマンドを変えても反映されないバグを直した。
    1.26 +	\endの次で{を押した時には自動的に閉じるべき環境名を入れる(^^;)。
    1.27 +	引数型アドイン関数も作れる M-x YaTeX-generate-simple を用意した。
    1.28 +	%#REQUIRE の行は必ず typeset-region の時にコピーする。
    1.29 +	ドキュメントの Texinfo 化。
    1.30 +    <Fixes>
    1.31 +	ネストしたsection型コマンドの削除範囲判定のバグを直した。
    1.32 +	\begin と \end の uncomment が verbatim 環境でうまく行かないバグ
    1.33 +	を直した。
    1.34 +	typeset-regionでend-of-bufferまでか%#ENDまでかの表示が逆だったの
    1.35 +	を直した。
    1.36 +
    1.37  1.49	YaTeX::newcommand において \newcommand の引数0個の時は maketitle 
    1.38  	型用の辞書を更新するようにした。
    1.39  	テンポラリ辞書を格納する変数を buffer-local に。
     2.1 --- a/yatexadd.el	Thu Jul 07 16:37:05 1994 +0000
     2.2 +++ b/yatexadd.el	Thu Jul 07 16:37:05 1994 +0000
     2.3 @@ -1,12 +1,10 @@
     2.4  ;;; -*- Emacs-Lisp -*-
     2.5  ;;; YaTeX add-in functions.
     2.6 -;;; yatexadd.el rev.8
     2.7 +;;; yatexadd.el rev.9
     2.8  ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     2.9 -;;; Last modified Sun May 15 18:00:12 1994 on 98fa
    2.10 +;;; Last modified Mon Jun 27 17:00:19 1994 on figaro
    2.11  ;;; $Id$
    2.12  
    2.13 -(provide 'yatexadd)
    2.14 -
    2.15  ;;;
    2.16  ;;Sample functions for LaTeX environment.
    2.17  ;;;
    2.18 @@ -14,22 +12,53 @@
    2.19    "@{\\vrule width 1pt\\ }c|c|c@{\\ \\vrule width 1pt}"
    2.20    "*Your favorite default rule format."
    2.21  )
    2.22 +(defvar YaTeX:tabular-thick-vrule "\\vrule width %s"
    2.23 +  "*Vertical thick line format (without @{}).  %s'll be replaced by its width."
    2.24 +)
    2.25 +(defvar YaTeX:tabular-thick-hrule "\\noalign{\\hrule height %s}"
    2.26 +  "*Horizontal thick line format.  %s will be replaced by its width."
    2.27 +)
    2.28  (defun YaTeX:tabular ()
    2.29    "YaTeX add-in function for tabular environment.
    2.30  Notice that this function refers the let-variable `env' in
    2.31  YaTeX-make-begin-end."
    2.32 -  (let ((width "") bars (rule "") (j 0) loc)
    2.33 +  (let ((width "") bars (rule "") (and "") (j 1) loc ans (hline "\\hline"))
    2.34      (if (string= env "tabular*")
    2.35  	(setq width (concat "{" (read-string "Width: ") "}")))
    2.36      (setq loc (YaTeX:read-position "tb")
    2.37 -	  bars (string-to-int (read-string "Number of `|': ")))
    2.38 -    (if (> bars 0)
    2.39 -	(while (< j bars) (setq rule (concat rule "|")) (setq j (1+ j)))
    2.40 -      (setq rule YaTeX:tabular-default-rule))
    2.41 +	  bars (string-to-int
    2.42 +		(read-string "Number of columns(0 for default format): " "3")))
    2.43 +    (if (<= bars 0)
    2.44 +	(setq				;if 0, simple format
    2.45 +	 rule YaTeX:tabular-default-rule
    2.46 +	 and "& &")
    2.47 +      (while (< j bars)			;repeat bars-1 times
    2.48 +	(setq rule (concat rule "c|")
    2.49 +	      and (concat and "& ")
    2.50 +	      j (1+ j)))
    2.51 +      (setq rule (concat rule "c"))
    2.52 +      (message "(N)ormal-frame or (T)hick frame? [nt]")
    2.53 +      (setq ans (read-char))
    2.54 +      (cond
    2.55 +       ((or (equal ans ?t) (equal ans ?T))
    2.56 +	(setq ans (read-string "Rule width: " "1pt")
    2.57 +	      rule (concat
    2.58 +		    "@{" (format YaTeX:tabular-thick-vrule ans) "}"
    2.59 +		    rule
    2.60 +		    "@{\\ " (format YaTeX:tabular-thick-vrule ans) "}")
    2.61 +	      hline (format YaTeX:tabular-thick-hrule ans)))
    2.62 +       (t (setq rule (concat "|" rule "|")
    2.63 +		hline "\\hline"))))
    2.64 +
    2.65      (setq rule (read-string "rule format: " rule))
    2.66  
    2.67 -    (message "")
    2.68 -    (format "%s%s{%s}" width loc rule))
    2.69 +    (message "Dont forget to remove null line at the end of tabular.")
    2.70 +    (format "%s%s{%s}%s"
    2.71 +	    width loc rule
    2.72 +	    (if (and (boundp 'region-mode) region-mode)
    2.73 +		""		;do nothing in region-mode
    2.74 +	      (format "\n%s\n%s \\\\ \\hline\n%s\n\\\\ %s"
    2.75 +		      hline and and hline))))
    2.76  )
    2.77  (fset 'YaTeX:tabular* 'YaTeX:tabular)
    2.78  (defun YaTeX:array ()
    2.79 @@ -37,11 +66,13 @@
    2.80  	  "{" (read-string "Column format: ") "}")
    2.81  )
    2.82  
    2.83 -(defun YaTeX:read-position (oneof)
    2.84 -  (let ((pos "") loc)
    2.85 +(defun YaTeX:read-oneof (oneof)
    2.86 +  (let ((pos "") loc (guide ""))
    2.87 +    (and (boundp 'name) name (setq guide (format "%s " name)))
    2.88      (while (not (string-match
    2.89  		 (setq loc (read-key-sequence
    2.90 -			    (format "Position (`%s') [%s]: " oneof pos)))
    2.91 +			    (format "%s position (`%s') [%s]: "
    2.92 +				    guide oneof pos)));name is in YaTeX-addin
    2.93  		 "\r\^g\n"))
    2.94        (cond
    2.95         ((string-match loc oneof)
    2.96 @@ -54,8 +85,13 @@
    2.97  	(message "Please input one of `%s'." oneof)
    2.98  	(sit-for 3))))
    2.99      (message "")
   2.100 -    (if (string= pos "") ""
   2.101 -      (concat "[" pos "]")))
   2.102 +    pos)
   2.103 +)
   2.104 +
   2.105 +(defun YaTeX:read-position (oneof)
   2.106 +  "Read a LaTeX (optional) position format such as `[htbp]'."
   2.107 +  (let ((pos (YaTeX:read-oneof oneof)))
   2.108 +    (if (string= pos "")  "" (concat "[" pos "]")))
   2.109  )
   2.110  
   2.111  (defun YaTeX:table ()
   2.112 @@ -113,8 +149,17 @@
   2.113  )
   2.114  
   2.115  (defun YaTeX:makebox ()
   2.116 -  (concat (YaTeX:read-coordinates "Dimension")
   2.117 -	  (YaTeX:read-position "lrtb"))
   2.118 +  (cond
   2.119 +   ((YaTeX-in-environment-p "picture")
   2.120 +    (concat (YaTeX:read-coordinates "Dimension")
   2.121 +	    (YaTeX:read-position "lrtb")))
   2.122 +   (t
   2.123 +    (let ((width (read-string "Width: ")))
   2.124 +      (if (string< "" width)
   2.125 +	  (progn
   2.126 +	    (or (equal (aref width 0) ?\[)
   2.127 +		(setq width (concat "[" width "]")))
   2.128 +	    (concat width (YaTeX:read-position "lr")))))))
   2.129  )
   2.130  
   2.131  (defun YaTeX:framebox ()
   2.132 @@ -127,6 +172,19 @@
   2.133  	  (YaTeX:read-coordinates "Dimension"))
   2.134  )
   2.135  
   2.136 +(defun YaTeX:left ()
   2.137 +  (let (c)
   2.138 +    (while (not (string-match
   2.139 +		 (progn (message "Which parenthesis? One of [{(|)}]: ")
   2.140 +			(setq c (regexp-quote (char-to-string (read-char)))))
   2.141 +		 "[{(|)}]")))
   2.142 +    (setq single-command "right")
   2.143 +    (cond
   2.144 +     ((string-match c "[(|)]") c)
   2.145 +     (t (concat "\\" c))))
   2.146 +)
   2.147 +(fset 'YaTeX:right 'YaTeX:left)
   2.148 +
   2.149  (defun YaTeX:read-coordinates (&optional mes varX varY)
   2.150    (concat
   2.151     "("
   2.152 @@ -177,6 +235,7 @@
   2.153  	(contents (read-string "Quoted contents: ")))
   2.154      (concat quote-char contents quote-char))
   2.155  )
   2.156 +(fset 'YaTeX:verb* 'YaTeX:verb)
   2.157  
   2.158  ;;;
   2.159  ;;Subroutine
   2.160 @@ -202,6 +261,8 @@
   2.161  ;;
   2.162  (defvar YaTeX-label-menu-other
   2.163    (if YaTeX-japan "':他のバッファのラベル\n" "':LABEL IN OTHER BUFFER.\n"))
   2.164 +(defvar YaTeX-label-menu-repeat
   2.165 +  (if YaTeX-japan ".:直前の\\refと同じ\n" "/:REPEAT LAST \ref{}\n"))
   2.166  (defvar YaTeX-label-menu-any
   2.167    (if YaTeX-japan "*:任意の文字列\n" "*:ANY STRING.\n"))
   2.168  (defvar YaTeX-label-buffer "*Label completions*")
   2.169 @@ -228,6 +289,7 @@
   2.170      (define-key YaTeX-label-select-map "/"	'isearch-forward)
   2.171      (define-key YaTeX-label-select-map "?"	'isearch-backward)
   2.172      (define-key YaTeX-label-select-map "'"	'YaTeX::label-search-tag)
   2.173 +    (define-key YaTeX-label-select-map "."	'YaTeX::label-search-tag)
   2.174      (define-key YaTeX-label-select-map "*"	'YaTeX::label-search-tag)
   2.175      (message "Setting up label selection mode map...Done")
   2.176      (let ((key ?A))
   2.177 @@ -244,15 +306,15 @@
   2.178    (interactive) (forward-line -1) (message YaTeX-label-guide-msg))
   2.179  (defun YaTeX::label-search-tag ()
   2.180    (interactive)
   2.181 -  (let ((case-fold-search t))
   2.182 +  (let ((case-fold-search t) (tag (regexp-quote (this-command-keys))))
   2.183      (cond
   2.184       ((save-excursion
   2.185  	(forward-char 1)
   2.186 -	(re-search-forward (concat "^" (this-command-keys)) nil t))
   2.187 +	(re-search-forward (concat "^" tag) nil t))
   2.188        (goto-char (match-beginning 0)))
   2.189       ((save-excursion
   2.190  	(goto-char (point-min))
   2.191 -	(re-search-forward (concat "^" (this-command-keys)) nil t))
   2.192 +	(re-search-forward (concat "^" tag) nil t))
   2.193        (goto-char (match-beginning 0))))
   2.194      (message YaTeX-label-guide-msg))
   2.195  )
   2.196 @@ -284,6 +346,7 @@
   2.197  		(message "Collecting \\label{}... %d" lnum))
   2.198  	      (goto-char e0))
   2.199  	    (princ YaTeX-label-menu-other)
   2.200 +	    (princ YaTeX-label-menu-repeat)
   2.201  	    (princ YaTeX-label-menu-any)
   2.202  	    );with
   2.203  	  (goto-char p)
   2.204 @@ -303,7 +366,15 @@
   2.205  		(setq line (count-lines (point-min)(point)))
   2.206  		(cond
   2.207  		 ((= line lnum) (setq label (YaTeX-label-other)))
   2.208 -		 ((>= line (1+ lnum ))
   2.209 +		 ((= line (1+ lnum))
   2.210 +		  (save-excursion
   2.211 +		    (switch-to-buffer buf)
   2.212 +		    (goto-char p)
   2.213 +		    (if (re-search-backward "\\\\ref{\\([^}]+\\)}" nil t)
   2.214 +			(setq label (buffer-substring
   2.215 +				     (match-beginning 1) (match-end 1)))
   2.216 +		      (setq label ""))))
   2.217 +		 ((>= line (+ lnum 2))
   2.218  		  (setq label (read-string "\\ref{???}: ")))
   2.219  		 (t (setq label (nth (- lnum line 1) label-list)))))
   2.220  	    (bury-buffer YaTeX-label-buffer)))
   2.221 @@ -408,24 +479,101 @@
   2.222     '(("arabic") ("Alpha") ("alpha") ("Roman") ("roman")))
   2.223  )
   2.224  
   2.225 -;;;
   2.226 -;; global subroutines
   2.227 -;;;
   2.228 -(defun substitute-all-key-definition (olddef newdef keymap)
   2.229 -  "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
   2.230 -defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
   2.231 -where ever it appears."
   2.232 -  (if (arrayp keymap)
   2.233 -      (let ((len (length keymap))
   2.234 -	    (i 0))
   2.235 -	(while (< i len)
   2.236 -	  (let ((map (aref keymap i)))
   2.237 -	    (cond
   2.238 -	     ((arrayp map) (substitute-key-definition olddef newdef map))
   2.239 -	     ((equal map olddef)
   2.240 -	      (aset keymap i newdef)))
   2.241 -	    (setq i (1+ i)))))
   2.242 -    (while keymap
   2.243 -      (if (equal (cdr-safe (car-safe keymap)) olddef)
   2.244 -	  (setcdr (car keymap) newdef))
   2.245 -      (setq keymap (cdr keymap)))))
   2.246 +;;
   2.247 +; Length
   2.248 +;;
   2.249 +(defvar YaTeX:style-parameters-default
   2.250 +  '(("\\arraycolsep")
   2.251 +    ("\\arrayrulewidth")
   2.252 +    ("\\baselineskip")
   2.253 +    ("\\columnsep")
   2.254 +    ("\\columnseprule")
   2.255 +    ("\\doublerulesep")
   2.256 +    ("\\evensidemargin")
   2.257 +    ("\\footheight")
   2.258 +    ("\\footskip")
   2.259 +    ("\\headheight")
   2.260 +    ("\\headsep")
   2.261 +    ("\\itemindent")
   2.262 +    ("\\itemsep")
   2.263 +    ("\\labelsep")
   2.264 +    ("\\labelwidth")
   2.265 +    ("\\leftmargin")
   2.266 +    ("\\linewidth")
   2.267 +    ("\\listparindent")
   2.268 +    ("\\marginparsep")
   2.269 +    ("\\marginparwidth")
   2.270 +    ("\\mathindent")
   2.271 +    ("\\oddsidemargin")
   2.272 +    ("\\parindent")
   2.273 +    ("\\parsep")
   2.274 +    ("\\parskip")
   2.275 +    ("\\partopsep")
   2.276 +    ("\\rightmargin")
   2.277 +    ("\\tabcolsep")
   2.278 +    ("\\textheight")
   2.279 +    ("\\textwidth")
   2.280 +    ("\\topmargin")
   2.281 +    ("\\topsep")
   2.282 +    ("\\topskip")
   2.283 +    )
   2.284 +  "Alist of LaTeX style parameters.")
   2.285 +(defvar YaTeX:style-parameters-private nil
   2.286 +  "*User definable alist of style parameters.")
   2.287 +(defvar YaTeX:style-parameters-private nil
   2.288 +  "Holds the union of LaTeX style parameters.")
   2.289 +(setq YaTeX:style-parameters
   2.290 +      (append YaTeX:style-parameters-private YaTeX:style-parameters-default))
   2.291 +
   2.292 +(defvar YaTeX:length-history nil "Holds history of length.")
   2.293 +(defun YaTeX::setlength (&optional argp)
   2.294 +  "YaTeX add-in function for arguments of \\setlength."
   2.295 +  (cond
   2.296 +   ((equal 1 argp)
   2.297 +    (completing-read "Length variable: " YaTeX:style-parameters nil nil "\\"))
   2.298 +   ((equal 2 argp)
   2.299 +    (let ((minibuffer-history-symbol 'YaTeX:length-history))
   2.300 +      (read-string "Length: "))))
   2.301 +)
   2.302 +(fset 'YaTeX::addtolength 'YaTeX::setlength)
   2.303 +
   2.304 +(defun YaTeX::settowidth (&optional argp)
   2.305 +  "YaTeX add-in function for arguments of \\settowidth."
   2.306 +  (cond
   2.307 +   ((equal 1 argp)
   2.308 +    (completing-read "Length variable: " YaTeX:style-parameters nil nil "\\"))
   2.309 +   ((equal 2 argp)
   2.310 +    (read-string "Text: ")))
   2.311 +)
   2.312 +(defun YaTeX::newlength (&optional argp)
   2.313 +  "YaTeX add-in function for arguments of \\newlength"
   2.314 +  (cond
   2.315 +   ((equal argp 1)
   2.316 +    (let ((length (read-string "Length variable: " "\\")))
   2.317 +      (or (assoc length YaTeX:style-parameters-private)
   2.318 +	  (setq YaTeX:style-parameters-private
   2.319 +		(cons (list length) YaTeX:style-parameters-private)
   2.320 +		YaTeX:style-parameters
   2.321 +		(cons (list length) YaTeX:style-parameters)))
   2.322 +      length)))
   2.323 +)
   2.324 +
   2.325 +;; \multicolumn's arguments
   2.326 +(defun YaTeX::multicolumn (&optional argp)
   2.327 +  "YaTeX add-in function for arguments of \\multicolumn."
   2.328 +  (cond
   2.329 +   ((equal 1 argp)
   2.330 +    (read-string "Number of columns: "))
   2.331 +   ((equal 2 argp)
   2.332 +    (let (c)
   2.333 +      (while (not (string-match
   2.334 +		   (progn (message "Format(one of l,r,c): ")
   2.335 +			  (setq c (char-to-string (read-char))))
   2.336 +		   "lrc")))
   2.337 +      c))
   2.338 +   ((equal 3 argp)
   2.339 +    (read-string "Item: ")))
   2.340 +)
   2.341 +
   2.342 +;;; -------------------- End of yatexadd --------------------
   2.343 +(provide 'yatexadd)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/yatexenv.el	Thu Jul 07 16:37:05 1994 +0000
     3.3 @@ -0,0 +1,154 @@
     3.4 +;;; -*- Emacs-Lisp -*-
     3.5 +;;; YaTeX environment-specific functions.
     3.6 +;;; yatexenv.el
     3.7 +;;; (c ) 1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     3.8 +;;; Last modified Fri Jul  8 00:48:40 1994 on figaro
     3.9 +;;; $Id$
    3.10 +
    3.11 +;;;
    3.12 +;; Functions for tabular environment
    3.13 +;;;
    3.14 +
    3.15 +;; Showing the matching column of tabular environment.
    3.16 +(defun YaTeX-array-what-column ()
    3.17 +  "Show matching columne title of array environment.
    3.18 +When calling from a program, make sure to be in array/tabular environment."
    3.19 +  (let ((p (point)) beg eot bor (nlptn "\\\\\\\\") (andptn "[^\\]&") (n 0)
    3.20 +	(firsterr "This line might be the first row."))
    3.21 +    (save-excursion
    3.22 +      (YaTeX-beginning-of-environment)
    3.23 +      (search-forward "{" p) (up-list 1)
    3.24 +      (search-forward "{" p) (up-list 1)
    3.25 +      ;;(re-search-forward andptn p)
    3.26 +      (while (progn (search-forward "&" p)
    3.27 +		    (equal (char-after (1- (match-beginning 0))) ?\\ )))
    3.28 +      (setq beg (1- (point)))		;beg is the point of the first &
    3.29 +      (or (re-search-forward nlptn p t)
    3.30 +	  (error firsterr))
    3.31 +      (setq eot (point))		;eot is the point of the first \\
    3.32 +      (goto-char p)
    3.33 +      (or (re-search-backward nlptn beg t)
    3.34 +	  (error firsterr))
    3.35 +      (setq bor (point))		;bor is the beginning of this row.
    3.36 +      (while (< (1- (point)) p)
    3.37 +	(if (equal (following-char) ?&)
    3.38 +	    (forward-char 1)
    3.39 +	  (re-search-forward andptn nil 1))
    3.40 +	(setq n (1+ n)))		;Check current column number
    3.41 +      (goto-char p)
    3.42 +      (cond				;Start searching \multicolumn{N}
    3.43 +       ((> n 1)
    3.44 +	(re-search-backward andptn)	;Sure to find!
    3.45 +	(while (re-search-backward "\\\\multicolumn{\\([0-9]+\\)}" bor t)
    3.46 +	  (setq n (+ n (string-to-int
    3.47 +			(buffer-substring (match-beginning 1)
    3.48 +					  (match-end 1)))
    3.49 +		     -1)))))
    3.50 +      (message "%s" n)
    3.51 +      (goto-char (1- beg))
    3.52 +      (cond
    3.53 +       ((= n 1) (message "Here is the FIRST column!"))
    3.54 +       (t (while (> n 1)
    3.55 +	    (or (re-search-forward andptn p nil)
    3.56 +		(error "This column exceeds the limit."))
    3.57 +	    (setq n (1- n)))
    3.58 +	  (skip-chars-forward "\\s ")
    3.59 +	  (message
    3.60 +	   "Here is the column of: %s"
    3.61 +	   (buffer-substring
    3.62 +	    (point)
    3.63 +	    (progn
    3.64 +	      (re-search-forward (concat andptn "\\|" nlptn) eot)
    3.65 +	      (goto-char (match-beginning 0))
    3.66 +	      (if (looking-at andptn)
    3.67 +		  (forward-char 1))
    3.68 +	      (skip-chars-backward "\\s ")
    3.69 +	      (point))))))))
    3.70 +)
    3.71 +
    3.72 +;;;###autoload
    3.73 +(defun YaTeX-what-column ()
    3.74 +  "Show which kind of column the current position is belonging to."
    3.75 +  (interactive)
    3.76 +  (cond
    3.77 +   ((YaTeX-quick-in-environment-p '("tabular" "tabular*" "array" "array*"))
    3.78 +    (YaTeX-array-what-column))
    3.79 +   (t (message "Not in array/tabuar environment.")))
    3.80 +)
    3.81 +
    3.82 +;;;
    3.83 +;; Functions for tabbing environment
    3.84 +;;;
    3.85 +(defun YaTeX-intelligent-newline-tabbing ()
    3.86 +  "Check the number of \\= in the first line and insert that many \\>."
    3.87 +  (let ((p (point)) begenv tabcount)
    3.88 +    (save-excursion
    3.89 +      (YaTeX-beginning-of-environment)
    3.90 +      (setq begenv (point-end-of-line))
    3.91 +      (if (YaTeX-search-active-forward "\\\\" YaTeX-comment-prefix p t)
    3.92 +	  (progn
    3.93 +	    (setq tabcount 0)
    3.94 +	    (while (> (point) begenv)
    3.95 +	      (if (search-backward "\\=" begenv 1)
    3.96 +		  (setq tabcount (1+ tabcount)))))))
    3.97 +    (YaTeX-indent-line)
    3.98 +    (if tabcount
    3.99 +	(progn
   3.100 +	  (save-excursion
   3.101 +	    (while (> tabcount 0)
   3.102 +	      (insert "\\>\t")
   3.103 +	      (setq tabcount (1- tabcount))))
   3.104 +	  (forward-char 2))
   3.105 +      (insert "\\=")))
   3.106 +)
   3.107 +
   3.108 +;;;
   3.109 +;; Functions for itemize/enumerate/list environments
   3.110 +;;;
   3.111 +
   3.112 +(defun YaTeX-indent-for-item ()
   3.113 +  (let (col (p (point)) begenv)
   3.114 +    (save-excursion
   3.115 +      (YaTeX-beginning-of-environment t)
   3.116 +      (setq begenv (point-end-of-line))
   3.117 +      (goto-char p)
   3.118 +      (if (YaTeX-search-active-backward "\\item" YaTeX-comment-prefix begenv t)
   3.119 +	  (setq col (current-column))))
   3.120 +    (if col (indent-to col) (YaTeX-indent-line)))
   3.121 +)
   3.122 +
   3.123 +(defvar YaTeX-item-for-insert "\\item ")
   3.124 +(defun YaTeX-intelligent-newline-itemize ()
   3.125 +  "Insert '\\item '."
   3.126 +  (YaTeX-indent-for-item)
   3.127 +  (insert YaTeX-item-for-insert)
   3.128 +)
   3.129 +(fset 'YaTeX-intelligent-newline-enumerate 'YaTeX-intelligent-newline-itemize)
   3.130 +(fset 'YaTeX-intelligent-newline-list 'YaTeX-intelligent-newline-itemize)
   3.131 +
   3.132 +(defun YaTeX-intelligent-newline-description ()
   3.133 +  (YaTeX-indent-for-item)
   3.134 +  (insert "\\item[] ")
   3.135 +  (forward-char -2)
   3.136 +)
   3.137 +
   3.138 +
   3.139 +;;;
   3.140 +;; Intelligent newline
   3.141 +;;;
   3.142 +;;;###autoload
   3.143 +(defun YaTeX-intelligent-newline (arg)
   3.144 +  "Insert newline and environment-specific entry.
   3.145 +`\\item'	for some itemizing environment,
   3.146 +`\\> \\> \\'	for tabbing environemnt,
   3.147 +`& & \\ \hline'	for tabular environment."
   3.148 +  (interactive "P")
   3.149 +  (let*((env (YaTeX-inner-environment))
   3.150 +	func)
   3.151 +    (if arg (setq env (YaTeX-read-environment "For what environment? ")))
   3.152 +    (setq func (intern-soft (concat "YaTeX-intelligent-newline-" env)))
   3.153 +    (end-of-line)
   3.154 +    (newline)
   3.155 +    (if (and env func (fboundp func))
   3.156 +	(funcall func)))
   3.157 +)
     4.1 --- a/yatexgen.el	Thu Jul 07 16:37:05 1994 +0000
     4.2 +++ b/yatexgen.el	Thu Jul 07 16:37:05 1994 +0000
     4.3 @@ -1,8 +1,8 @@
     4.4  ;;; -*- Emacs-Lisp -*-
     4.5 -;;; Generate add-in functions for YaTeX.
     4.6 -;;; yatexgen.el rev.1(beta2)
     4.7 +;;; YaTeX add-in function generator.
     4.8 +;;; yatexgen.el rev.2
     4.9  ;;; (c )1991-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
    4.10 -;;; Last modified Sat Apr 23 02:26:34 1994 on pajero
    4.11 +;;; Last modified Fri Jul  8 00:46:09 1994 on figaro
    4.12  ;;; $Id$
    4.13  
    4.14  (require 'yatex)
    4.15 @@ -403,3 +403,195 @@
    4.16        (define-key map (char-to-string i) 'undefined)
    4.17        (setq i (1+ i))))
    4.18  )
    4.19 +
    4.20 +;;;
    4.21 +;; Auto-generate Function for Lispers.
    4.22 +;;;
    4.23 +(defun YaTeX-generate-read-completion-type (nth)
    4.24 +  (message
    4.25 +"Read type(%d): (S)tring (C)omplete (F)ile ([)option (P)osition co(O)rd. (q)uit" nth)
    4.26 +  (let ((c (read-char)))
    4.27 +    (cond
    4.28 +     ((= c ?s) 'string)
    4.29 +     ((= c ?c) 'completion)
    4.30 +     ((= c ?f) 'file)
    4.31 +     ((= c ?\[) 'option)
    4.32 +     ((= c ?p) 'oneof)
    4.33 +     ((= c ?o) 'coord)
    4.34 +     ;;((= c ?m) 'macro)
    4.35 +     (t        'quit)))
    4.36 + )
    4.37 +(defun YaTeX-generate-read-completion-table ()
    4.38 +  (let ((i 1) cand (cands "(") (cb (current-buffer))
    4.39 +	(buf (get-buffer-create " *Candidates*")))
    4.40 +    (save-window-excursion
    4.41 +      (save-excursion
    4.42 +      (YaTeX-showup-buffer buf nil)
    4.43 +      (set-buffer buf)
    4.44 +      (erase-buffer)
    4.45 +      (while (string<
    4.46 +	      ""
    4.47 +	      (setq cand (read-string (format "Item[%d](RET to exit): " i))))
    4.48 +	(setq cands (concat cands (format "(""%s"")\n" cand))
    4.49 +	      i (1+ i))
    4.50 +	(insert cand "\n"))
    4.51 +      (kill-buffer buf)))
    4.52 +    ;;(set-buffer cb)
    4.53 +    (concat cands ")"))
    4.54 +)
    4.55 +(defun YaTeX-generate-corresponding-paren (left)
    4.56 +  (cond
    4.57 +   ((equal left "{") "}")
    4.58 +   ((equal left "[") "]")
    4.59 +   ((equal left "(") ")")
    4.60 +   ((equal left "<") ">")
    4.61 +   ((equal left "\\begin{" "}"))
    4.62 +   (t left))
    4.63 +)
    4.64 +(defun YaTeX-generate-create-read-string (&optional nth)
    4.65 +  (concat
    4.66 +   "(read-string """
    4.67 +   (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: "))
    4.68 +   ": ""\n"
    4.69 +   """" (read-string "Default: ") """"
    4.70 +   ")\n")
    4.71 +)
    4.72 +(defun YaTeX-generate-create-completing-read (&optional nth)
    4.73 +  (concat
    4.74 +   "(completing-read """
    4.75 +   (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: "))
    4.76 +   ": ""\n"
    4.77 +   (format "'%s\n" (YaTeX-generate-read-completion-table))
    4.78 +   "nil "
    4.79 +   (format "%s)" (y-or-n-p "Require match? ")))
    4.80 +)
    4.81 +(defun YaTeX-generate-create-read-file-name (&optional nth)
    4.82 +  (concat
    4.83 +   "(read-file-name """
    4.84 +   (read-string (if nth (format "Prompt for argument#%d: " nth) "Prompt: "))
    4.85 +   ": "" nil nil t """")\n")
    4.86 +)
    4.87 +(defun YaTeX-generate-create-read-oneof (&optional nth readpos)
    4.88 +  (concat
    4.89 +   (if readpos
    4.90 +       "(YaTeX:read-position """
    4.91 +     "(YaTeX:read-oneof """)
    4.92 +   (read-string "Acceptable characters: " "lcr") """)\n")
    4.93 +)
    4.94 +(defun YaTeX-generate-option-type (command)
    4.95 +  (let ((func (format "YaTeX:%s" command)) leftp
    4.96 +	(buf (get-buffer-create YaTeX-generate-buffer)) type (n 1))
    4.97 +    (set-buffer buf)
    4.98 +    (erase-buffer)
    4.99 +    (insert "(defun " func " ()\n  (concat\n")
   4.100 +    (catch 'done
   4.101 +      (while t
   4.102 +	(setq type (YaTeX-generate-read-completion-type n))
   4.103 +	(insert 
   4.104 +	 (cond
   4.105 +	  ;;Read string
   4.106 +	  ((eq type 'string)
   4.107 +	   (concat """" (setq leftp (read-string "Left parenthesis: " "{"))
   4.108 +		   """\n"
   4.109 +		   (YaTeX-generate-create-read-string)
   4.110 +		   """" (YaTeX-generate-corresponding-paren leftp) """"
   4.111 +		   ))
   4.112 +	  
   4.113 +	  ;;Completing-read
   4.114 +	  ((eq type 'completion)
   4.115 +	   (concat """" (setq leftp (read-string "Left parenthesis: " "{"))
   4.116 +		   """\n"
   4.117 +		   (YaTeX-generate-create-completing-read)
   4.118 +		   """" (YaTeX-generate-corresponding-paren leftp) """")
   4.119 +	   )
   4.120 +	  ((eq type 'file)
   4.121 +	   (concat """" (setq leftp (read-string "Left parenthesis: " "{"))
   4.122 +		   """\n"
   4.123 +		   (YaTeX-generate-create-read-file-name)
   4.124 +		   """" (YaTeX-generate-corresponding-paren leftp) """")
   4.125 +	   )
   4.126 +	  ((eq type 'oneof)
   4.127 +	   (YaTeX-generate-create-read-oneof nil t)
   4.128 +	   )
   4.129 +	  ((eq type 'option)
   4.130 +	   (concat "(let ((op (read-string """
   4.131 +		   (read-string "Prompt: ")
   4.132 +		   ": "")))\n"
   4.133 +		   "(if (string< """" op)\n"
   4.134 +		   "    (concat ""["" op ""]"")\n"
   4.135 +		   "  """"))\n")
   4.136 +	   )
   4.137 +	  
   4.138 +	  ((eq type 'coord)
   4.139 +	   (concat "(YaTeX:read-coordinates """
   4.140 +		   (read-string "Prompt for coordinates: ")
   4.141 +		   ": """)
   4.142 +	   )
   4.143 +	  ((eq type 'macro)
   4.144 +	   (error "not yet supported")
   4.145 +	   )
   4.146 +	  (t (throw 'done t))))
   4.147 +	(setq n (1+ n))))
   4.148 +    (insert "))\n")			;close defun
   4.149 +    (goto-char (point-min))
   4.150 +    (while (not (eobp)) (lisp-indent-line) (forward-line 1))
   4.151 +    (eval-current-buffer)
   4.152 +    buf)
   4.153 +)
   4.154 +(defun YaTeX-generate-argument-type (command argc)
   4.155 +  "Create an argument-type add-in function."
   4.156 +  (interactive)
   4.157 +  (let ((func (format "YaTeX::%s" command)) (argp 1)
   4.158 +	(cb (current-buffer))
   4.159 +	(buf (get-buffer-create YaTeX-generate-buffer)))
   4.160 +    (set-buffer buf)
   4.161 +    (erase-buffer)
   4.162 +    (insert "(defun " func " (&optional argp)\n(cond\n")
   4.163 +    (while (<= argp argc)
   4.164 +      (insert (format "((equal argp %d)\n" argp))
   4.165 +      (setq type (YaTeX-generate-read-completion-type argp))
   4.166 +      (insert
   4.167 +       (cond
   4.168 +	((eq type 'string)
   4.169 +	 (concat (YaTeX-generate-create-read-string argp)))
   4.170 +	((eq type 'completion)
   4.171 +	 (concat (YaTeX-generate-create-completing-read argp)))
   4.172 +	((eq type 'oneof)
   4.173 +	 (YaTeX-generate-create-read-oneof))
   4.174 +	((eq type 'file)
   4.175 +	 (concat (YaTeX-generate-create-read-file-name argp)))
   4.176 +	(t ""))
   4.177 +       ")\n")
   4.178 +      (setq argp (1+ argp)))
   4.179 +    (insert "))\n")
   4.180 +    (goto-char (point-min))
   4.181 +    (while (not (eobp)) (lisp-indent-line) (forward-line 1))
   4.182 +    (eval-current-buffer)
   4.183 +    (set-buffer cb)
   4.184 +    (YaTeX-update-table
   4.185 +     (if (> argc 1) (list command argc) (list command))
   4.186 +     'section-table 'user-section-table 'tmp-section-table)
   4.187 +    buf)
   4.188 +)
   4.189 +(defun YaTeX-generate-simple (&optional command)
   4.190 +  "Simple but requiring some elisp knowledge add-in generator."
   4.191 +  (interactive)
   4.192 +  (or command
   4.193 +      (setq command
   4.194 +	    (completing-read
   4.195 +	     (format "Making add-in function for (default %s): " section-name)
   4.196 +	     (append
   4.197 +	      section-table user-section-table tmp-section-table
   4.198 +	      article-table user-article-table
   4.199 +	      env-table     user-env-table     tmp-env-table
   4.200 +	      singlecmd-table user-singlecmd-table tmp-singlecmd-table)
   4.201 +	     nil nil)
   4.202 +	    command (if (string= "" command) section-name command)))
   4.203 +  (message "(o)追加型? (a)引数型? (yatexadd.docを参照のこと) :")
   4.204 +  (YaTeX-showup-buffer
   4.205 +   (if (= (read-char) ?o)
   4.206 +       (YaTeX-generate-option-type command)
   4.207 +     (YaTeX-generate-argument-type
   4.208 +      command
   4.209 +      (string-to-int (read-string "How many arguments?: ")))) nil)
   4.210 +)
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/yatexhks.el	Thu Jul 07 16:37:05 1994 +0000
     5.3 @@ -0,0 +1,16 @@
     5.4 +;;; -*- Emacs-Lisp -*-
     5.5 +;;; Hooks for YaTeX
     5.6 +
     5.7 +;;; $BLnD;$K4XO"$9$k5-=R(B($B$?$H$($P%"%I%$%s4X?t(B)$B$O(B yatexhks.el $B$H$$$&L>A0$N(B
     5.8 +;;; $B%U%!%$%k$KF~$l$F$/$@$5$$!#5/F0;~$K<+F0E*$K%m!<%I$7$^$9!#(B
     5.9 +
    5.10 +;;; All the private definitions for YaTeX can be stuffed into the file
    5.11 +;;; named `yatexhks.el'.  The file `yatexhks.el' will be automatically
    5.12 +;;; loaded at the end of loading `yatex.el'.
    5.13 +
    5.14 +;Private definitions begins from here.
    5.15 +
    5.16 +
    5.17 +;
    5.18 +;;; End of yatexhks.el
    5.19 +(provide 'yatexhks)
     6.1 --- a/yatexhlp.el	Thu Jul 07 16:37:05 1994 +0000
     6.2 +++ b/yatexhlp.el	Thu Jul 07 16:37:05 1994 +0000
     6.3 @@ -2,7 +2,7 @@
     6.4  ;;; YaTeX helper with LaTeX commands and macros.
     6.5  ;;; yatexhlp.el
     6.6  ;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     6.7 -;;; Last modified Thu May  5 16:09:42 1994 on 98fa
     6.8 +;;; Last modified Fri Jul  1 17:03:23 1994 on VFR
     6.9  ;;; $Id$
    6.10  
    6.11  (let ((help-file
    6.12 @@ -34,7 +34,73 @@
    6.13  	(t "[[ Description ]]"))
    6.14    "Section header of description.")
    6.15  
    6.16 -(defun YaTeX-refer-help (command help-file)
    6.17 +(defvar YaTeX-help-reference-regexp "<refer\\s +\\([^>]+\\)>"
    6.18 +  "Regexp of reference format of YaTeX-help file.")
    6.19 +(defvar YaTeX-help-buffer "** YaTeX HELP **" "Help buffer name for yatexhlp")
    6.20 +
    6.21 +(defun YaTeX-help-entries ()
    6.22 +  "Return the alist which contains all the entries in YaTeX-help file."
    6.23 +  (let (entries entry)
    6.24 +    (save-excursion
    6.25 +      (mapcar
    6.26 +       (function
    6.27 +	(lambda (help)
    6.28 +	  (if (file-exists-p help)
    6.29 +	      (progn
    6.30 +		(set-buffer (find-file-noselect help))
    6.31 +		(save-excursion
    6.32 +		  (goto-char (point-min))
    6.33 +		  (while (re-search-forward
    6.34 +			  (concat "^" (regexp-quote YaTeX-help-delimiter)
    6.35 +				  "\\(.+\\)$") nil t)
    6.36 +		    (setq entry (buffer-substring
    6.37 +				 (match-beginning 1) (match-end 1)))
    6.38 +		    (or (assoc entry entries)
    6.39 +			(setq entries (cons (list entry) entries)))))))))
    6.40 +       (list YaTeX-help-file YaTeX-help-file-private)))
    6.41 +    entries)
    6.42 +)
    6.43 +
    6.44 +(defvar YaTeX-help-entries (YaTeX-help-entries))
    6.45 +
    6.46 +(defun YaTeX-help-resolve-reference (buffer1 buffer2 &optional done-list)
    6.47 +  "Replace reference format in buffer1 with refered contents in buffer2."
    6.48 +  (let (ref ref-list beg end)
    6.49 +    (save-excursion
    6.50 +      (switch-to-buffer buffer1)
    6.51 +      (goto-char (point-min))
    6.52 +      (while (re-search-forward YaTeX-help-reference-regexp nil t)
    6.53 +	(setq ref (buffer-substring (match-beginning 1) (match-end 1))
    6.54 +	      ref-list (cons (list ref) ref-list))
    6.55 +	(replace-match "")
    6.56 +	(if (assoc ref done-list) nil	;already documented.
    6.57 +	  (switch-to-buffer buffer2)
    6.58 +	  (save-excursion
    6.59 +	    (goto-char (point-min))
    6.60 +	    (if (re-search-forward
    6.61 +		 (concat (regexp-quote YaTeX-help-delimiter)
    6.62 +			 (regexp-quote ref)
    6.63 +			 "$") nil t)
    6.64 +		(progn
    6.65 +		  (setq beg (progn (forward-line 2) (point))
    6.66 +			end (progn
    6.67 +			      (re-search-forward
    6.68 +			       (concat "^" (regexp-quote YaTeX-help-delimiter))
    6.69 +			       nil 1)
    6.70 +			      (goto-char (match-beginning 0))
    6.71 +			      (forward-line -1)
    6.72 +			      (while (and (bolp) (eolp) (not (bobp)))
    6.73 +				(forward-char -1))
    6.74 +			      (point)))
    6.75 +		  (switch-to-buffer buffer1)
    6.76 +		  (insert-buffer-substring buffer2 beg end))))
    6.77 +	  (switch-to-buffer buffer1)))
    6.78 +      (if beg (YaTeX-help-resolve-reference
    6.79 +	       buffer1 buffer2 (append done-list ref-list))))
    6.80 +    )
    6.81 +)
    6.82 +
    6.83 +(defun YaTeX-refer-help (command help-file &optional append)
    6.84    "Refer the COMMAND's help into HELP-FILE.
    6.85  \[Help-file format\]
    6.86  <DELIM><LaTeX/TeX command without escape character(\\)><NL>
    6.87 @@ -44,31 +110,35 @@
    6.88  	<NL> is newline.
    6.89  	<TERM> is newline or end of buffer."
    6.90    (let ((hfbuf (find-file-noselect help-file))
    6.91 -	(hbuf (get-buffer-create "** YaTeX HELP **"))
    6.92 +	(hbuf (get-buffer-create YaTeX-help-buffer))
    6.93  	(curwin (selected-window))
    6.94  	sb se db de)
    6.95      (set-buffer hfbuf)
    6.96      (goto-char (point-min))
    6.97      (if (null
    6.98 -	 (re-search-forward
    6.99 -	  (concat (regexp-quote YaTeX-help-delimiter)
   6.100 -		  (regexp-quote command)
   6.101 -		  "$") nil t))
   6.102 +	 (let ((case-fold-search nil))
   6.103 +	   (re-search-forward
   6.104 +	    (concat (regexp-quote YaTeX-help-delimiter)
   6.105 +		    (regexp-quote command)
   6.106 +		    "$") nil t)))
   6.107  	nil				;if not found, return nil
   6.108        (forward-line 1)
   6.109        (setq sb (point)
   6.110  	    se (progn (forward-line 1) (point))
   6.111  	    db (point)
   6.112  	    de (progn
   6.113 -		 (re-search-forward (regexp-quote YaTeX-help-delimiter) nil 1)
   6.114 -		 (1- (match-beginning 0))))
   6.115 -      (YaTeX-showup-buffer hbuf)
   6.116 +		 (re-search-forward
   6.117 +		  (concat "^" (regexp-quote YaTeX-help-delimiter)) nil 1)
   6.118 +		 (- (point) (length YaTeX-help-delimiter))))
   6.119 +      (YaTeX-showup-buffer
   6.120 +       hbuf (function (lambda (x) (nth 3 (window-edges x)))))
   6.121        (pop-to-buffer hbuf)
   6.122 -      (erase-buffer)
   6.123 +      (if append (goto-char (point-max)) (erase-buffer))
   6.124        (insert YaTeX-help-synopsis "\n")
   6.125        (insert-buffer-substring hfbuf sb se)
   6.126        (insert "\n" YaTeX-help-description "\n")
   6.127        (insert-buffer-substring hfbuf db de)
   6.128 +      (YaTeX-help-resolve-reference hbuf hfbuf (list (list command)))
   6.129        (goto-char (point-min))
   6.130        (select-window curwin)
   6.131        t))
   6.132 @@ -110,13 +180,15 @@
   6.133      (delete-blank-lines)
   6.134      (let ((make-backup-files t))
   6.135        (basic-save-buffer))
   6.136 -    (bury-buffer hfbuf))
   6.137 +    (bury-buffer hfbuf)
   6.138 +    (setq YaTeX-help-entries (cons (list command) YaTeX-help-entries)))
   6.139  )
   6.140  (defun YaTeX-help-prepare-entry (command help-file)
   6.141    "Read help description on COMMAND and add it to HELP-FILE."
   6.142    (let ((buf (get-buffer-create "**Description**"))
   6.143  	(conf (current-window-configuration)))
   6.144 -    (YaTeX-showup-buffer buf)
   6.145 +    (YaTeX-showup-buffer
   6.146 +     buf (function (lambda (x) (nth 3 (window-edges x)))))
   6.147      (pop-to-buffer buf)
   6.148      (make-local-variable 'YaTeX-help-file-current)
   6.149      (make-local-variable 'YaTeX-help-command-current)
   6.150 @@ -153,6 +225,44 @@
   6.151     nil "\\(\\sw+\\)\\([^]+\\|\\s'\\)" "\\1" (point-min) (point-max))
   6.152  )
   6.153  
   6.154 +(defun YaTeX-apropos-file (keyword help-file &optional append)
   6.155 +  (let ((hb (find-file-noselect help-file))
   6.156 +	(ab (get-buffer-create YaTeX-help-buffer))
   6.157 +	(sw (selected-window))
   6.158 +	(head (concat "^" (regexp-quote YaTeX-help-delimiter)))
   6.159 +	pt command)
   6.160 +    (YaTeX-showup-buffer
   6.161 +     ab (function (lambda (x) (nth 3 (window-edges x)))))
   6.162 +    (select-window (get-buffer-window ab))
   6.163 +    (set-buffer ab)			;assertion
   6.164 +    (or append (erase-buffer))
   6.165 +    (set-buffer hb)
   6.166 +    (goto-char (point-min))
   6.167 +    (while (re-search-forward keyword nil t)
   6.168 +      (setq pt (point))
   6.169 +      (re-search-backward head nil t)
   6.170 +      (setq command (buffer-substring (match-end 0) (point-end-of-line)))
   6.171 +      (switch-to-buffer ab)
   6.172 +      (goto-char (point-max))
   6.173 +      (insert-char ?- (1- (window-width)))
   6.174 +      (insert (format "\n<<%s>>\n" command))
   6.175 +      (YaTeX-refer-help command help-file t) ;append mode
   6.176 +      (set-buffer hb)
   6.177 +      (goto-char pt)
   6.178 +      (if (re-search-forward head nil 1)
   6.179 +	  (goto-char (1- (match-beginning 0)))))
   6.180 +    (select-window sw)
   6.181 +    pt)
   6.182 +)
   6.183 +
   6.184 +;;;###autoload
   6.185 +(defun YaTeX-apropos (key)
   6.186 +  (interactive "sLaTeX apropos (regexp): ")
   6.187 +  (or (YaTeX-apropos-file key YaTeX-help-file)
   6.188 +      (YaTeX-apropos-file key YaTeX-help-file-private t)
   6.189 +      (message "No matches found."))
   6.190 +)
   6.191 +
   6.192  ;;;###autoload
   6.193  (defun YaTeX-help ()
   6.194    "Show help buffer of LaTeX/TeX commands or macros."
   6.195 @@ -172,7 +282,7 @@
   6.196  		     (buffer-substring (match-beginning 2) (match-end 2))))))
   6.197         ((search-backward YaTeX-ec (point-beginning-of-line) t)
   6.198  	(goto-char (setq beg (match-end 0)))
   6.199 -	(re-search-forward "\\sw+")
   6.200 +	(re-search-forward YaTeX-TeX-token-regexp (point-end-of-line) t)
   6.201  	(setq end (point))
   6.202  	(if (and (<= beg p) (<= p end))
   6.203  	    (setq command (buffer-substring beg end)))))
   6.204 @@ -185,12 +295,7 @@
   6.205        (setq command
   6.206  	    (completing-read
   6.207  	     "Describe (La)TeX command: "
   6.208 -	     (append
   6.209 -	      section-table user-section-table tmp-section-table
   6.210 -	      article-table user-article-table
   6.211 -	      env-table     user-env-table     tmp-env-table
   6.212 -	      singlecmd-table user-singlecmd-table tmp-singlecmd-table)
   6.213 -	     nil nil command))	;no-predicate, not require match
   6.214 +	     YaTeX-help-entries nil nil command))
   6.215        );end excursion
   6.216      (or (YaTeX-refer-help command YaTeX-help-file)
   6.217  	(YaTeX-refer-help command YaTeX-help-file-private)
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/yatexlib.el	Thu Jul 07 16:37:05 1994 +0000
     7.3 @@ -0,0 +1,227 @@
     7.4 +;;; -*- Emacs-Lisp -*-
     7.5 +;;; YaTeX library of general functions.
     7.6 +;;; yatexlib.el
     7.7 +;;; (c )1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     7.8 +;;; Last modified Fri Jul  8 00:44:41 1994 on figaro
     7.9 +;;; $Id$
    7.10 +
    7.11 +;;;###autoload
    7.12 +(defun YaTeX-search-active-forward (string cmntrx &optional bound err cnt func)
    7.13 +  "Search STRING which is not commented out by CMNTRX.
    7.14 +Optional arguments after BOUND, ERR, CNT are passed literally to search-forward
    7.15 +or search-backward.
    7.16 +Optional sixth argument FUNC changes search-function."
    7.17 +  (let ((sfunc (if func func 'search-forward)) found md)
    7.18 +    (while (and (prog1
    7.19 +		    (setq found (funcall sfunc string bound err cnt))
    7.20 +		  (setq md (match-data)))
    7.21 +		(or
    7.22 +		 (YaTeX-in-verb-p (match-beginning 0))
    7.23 +		 (save-excursion
    7.24 +		   (beginning-of-line)
    7.25 +		   (re-search-forward cmntrx (match-beginning 0) t)))))
    7.26 +    (store-match-data md)
    7.27 +    found)
    7.28 +)
    7.29 +
    7.30 +(defun YaTeX-re-search-active-forward (regexp cmntrx &optional bound err cnt)
    7.31 +  "Search REGEXP backward which is not commented out by regexp CMNTRX.
    7.32 +See also YaTeX-search-active-forward."
    7.33 +  (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-forward)
    7.34 +)
    7.35 +(defun YaTeX-search-active-backward (string cmntrx &optional bound err cnt)
    7.36 +  "Search STRING backward which is not commented out by regexp CMNTRX.
    7.37 +See also YaTeX-search-active-forward."
    7.38 +  (YaTeX-search-active-forward string cmntrx bound err cnt 'search-backward)
    7.39 +)
    7.40 +(defun YaTeX-re-search-active-backward (regexp cmntrx &optional bound err cnt)
    7.41 +  "Search REGEXP backward which is not commented out by regexp CMNTRX.
    7.42 +See also YaTeX-search-active-forward."
    7.43 +  (YaTeX-search-active-forward regexp cmntrx bound err cnt 're-search-backward)
    7.44 +)
    7.45 +
    7.46 +
    7.47 +;;;###autoload
    7.48 +(defun YaTeX-switch-to-buffer (file &optional setbuf)
    7.49 +  "Switch to buffer if buffer exists, find file if not.
    7.50 +Optional second arg SETBUF t make use set-buffer instead of switch-to-buffer."
    7.51 +  (interactive "Fswitch to file: ")
    7.52 +  (let (buf)
    7.53 +    (if (setq buf (get-buffer (file-name-nondirectory file)))
    7.54 +	(progn
    7.55 +	  (funcall (if setbuf 'set-buffer 'switch-to-buffer)
    7.56 +		   (file-name-nondirectory file))
    7.57 +	  buf)
    7.58 +      (if (file-exists-p file)
    7.59 +	  (progn (find-file file) (current-buffer))
    7.60 +	(message "%s was not found in this directory." file)
    7.61 +	nil)))
    7.62 +)
    7.63 +
    7.64 +;;;###autoload
    7.65 +(defun YaTeX-switch-to-buffer-other-window (file)
    7.66 +  "Switch to buffer if buffer exists, find file if not."
    7.67 +  (interactive "Fswitch to file: ")
    7.68 +  (if (get-buffer (file-name-nondirectory file))
    7.69 +      (progn (switch-to-buffer-other-window file) t)
    7.70 +    (if (file-exists-p file)
    7.71 +	(progn (find-file-other-window file) t)
    7.72 +      (message "%s was not found in this directory." file)
    7.73 +      nil))
    7.74 +)
    7.75 +
    7.76 +(defun YaTeX-replace-format-sub (string format repl)
    7.77 +  (let ((beg (or (string-match (concat "^\\(%" format "\\)") string)
    7.78 +		 (string-match (concat "[^%]\\(%" format "\\)") string)))
    7.79 +	(len (length format)))
    7.80 +    (if (null beg) string ;no conversion
    7.81 +      (concat
    7.82 +       (substring string 0 (match-beginning 1)) repl
    7.83 +       (substring string (match-end 1)))))
    7.84 +)
    7.85 +
    7.86 +;;;###autoload
    7.87 +(defun YaTeX-replace-format (string format repl)
    7.88 +  "In STRING, replace first appearance of FORMAT to REPL as if
    7.89 +function `format' does.  FORMAT does not contain `%'"
    7.90 +  (let ((ans string))
    7.91 +    (while (not (string=
    7.92 +		 ans (setq string (YaTeX-replace-format-sub ans format repl))))
    7.93 +      (setq ans string))
    7.94 +    string)
    7.95 +)
    7.96 +
    7.97 +;;;###autoload
    7.98 +(defun YaTeX-replace-format-args (string &rest args)
    7.99 +  "Translate the argument mark #1, #2, ... #n in the STRING into the
   7.100 +corresponding real arguments ARGS."
   7.101 +  (let ((argp 1))
   7.102 +    (while args
   7.103 +      (setq string
   7.104 +	    (YaTeX-replace-format string (int-to-string argp) (car args)))
   7.105 +      (setq args (cdr args) argp (1+ argp))))
   7.106 +  string
   7.107 +)
   7.108 +
   7.109 +;;;###autoload
   7.110 +(defun rindex (string char)
   7.111 +  (let ((pos (1- (length string)))(index -1))
   7.112 +    (while (>= pos 0)
   7.113 +      (cond
   7.114 +       ((= (aref string pos) char)
   7.115 +	(setq index pos) (setq pos -1))
   7.116 +       (t (setq pos (1- pos))))
   7.117 +      )
   7.118 +    index)
   7.119 +)
   7.120 +
   7.121 +;;;###autoload
   7.122 +(defun YaTeX-showup-buffer (buffer &optional func select)
   7.123 +  "Make BUFFER show up in certain window (but current window)
   7.124 +that gives the maximum value by the FUNC.  FUNC should take an argument
   7.125 +of its window object.  Non-nil for optional third argument SELECT selects
   7.126 +that window."
   7.127 +  (or (and (get-buffer-window buffer)
   7.128 +	   (progn (if select (select-window (get-buffer-window buffer)))
   7.129 +		  t))
   7.130 +      (let ((window (selected-window))
   7.131 +	    (wlist (YaTeX-window-list)) win w (x 0))
   7.132 +	(cond
   7.133 +	 ((> (length wlist) 2)
   7.134 +	  (if func
   7.135 +	      (while wlist
   7.136 +		(setq w (car wlist))
   7.137 +		(if (and (not (eq window w))
   7.138 +			 (> (funcall func w) x))
   7.139 +		    (setq win w x (funcall func w)))
   7.140 +		(setq wlist (cdr wlist)))
   7.141 +	    (setq win (get-lru-window)))
   7.142 +	  (select-window win)
   7.143 +	  (switch-to-buffer buffer)
   7.144 +	  (or select (select-window window)))
   7.145 +	 ((= (length wlist) 2)
   7.146 +	  (other-window 1)
   7.147 +	  (switch-to-buffer buffer)
   7.148 +	  (or select (select-window window)))
   7.149 +	 (t				;if one-window
   7.150 +	  (cond
   7.151 +	   (YaTeX-default-pop-window-height
   7.152 +	    (split-window
   7.153 +	     (selected-window)
   7.154 +	     (max
   7.155 +	      (min
   7.156 +	       (- (screen-height)
   7.157 +		  (if (numberp YaTeX-default-pop-window-height)
   7.158 +		      (+ YaTeX-default-pop-window-height 2)
   7.159 +		    (/ (* (screen-height)
   7.160 +			  (string-to-int YaTeX-default-pop-window-height))
   7.161 +		       100)))
   7.162 +	       (- (screen-height) window-min-height 1))
   7.163 +	      window-min-height))
   7.164 +	    (pop-to-buffer buffer)
   7.165 +	    (or select (select-window window)))
   7.166 +	   (t nil)))
   7.167 +	 )))
   7.168 +)
   7.169 +
   7.170 +;;;###autoload
   7.171 +(defun YaTeX-window-list ()
   7.172 +  (let*((curw (selected-window)) (win curw) (wlist (list curw)))
   7.173 +    (while (not (eq curw (setq win (next-window win))))
   7.174 +      (or (eq win (minibuffer-window))
   7.175 +	  (setq wlist (cons win wlist))))
   7.176 +    wlist)
   7.177 +)
   7.178 +
   7.179 +;;;###autoload
   7.180 +(defun substitute-all-key-definition (olddef newdef keymap)
   7.181 +  "Replace recursively OLDDEF with NEWDEF for any keys in KEYMAP now
   7.182 +defined as OLDDEF. In other words, OLDDEF is replaced with NEWDEF
   7.183 +where ever it appears."
   7.184 +  (mapcar
   7.185 +   (function (lambda (key) (define-key keymap key newdef)))
   7.186 +   (where-is-internal olddef))
   7.187 +)
   7.188 +
   7.189 +;;;###autoload
   7.190 +(defun YaTeX-match-string (n &optional m)
   7.191 +  "Return (buffer-substring (match-beginning n) (match-beginning m))."
   7.192 +  (if (match-beginning n)
   7.193 +      (buffer-substring (match-beginning n)
   7.194 +			(match-end (if m m n))))
   7.195 +)
   7.196 +
   7.197 +;;;###autoload
   7.198 +(defun YaTeX-minibuffer-complete ()
   7.199 +  "Complete in minibuffer"
   7.200 +  (interactive)
   7.201 +  (let (beg word compl)
   7.202 +    (setq beg (if (and (boundp 'delim) delim)
   7.203 +		  (save-excursion
   7.204 +		    (skip-chars-backward (concat "^" delim))
   7.205 +		    (1- (point)))
   7.206 +		(point-min))
   7.207 +	  word (buffer-substring beg (point-max))
   7.208 +	  compl (try-completion word minibuffer-completion-table))
   7.209 +    (cond
   7.210 +     ((eq compl t) nil)
   7.211 +     ((eq compl nil)
   7.212 +      (ding)
   7.213 +      (save-excursion
   7.214 +	(let (p)
   7.215 +	  (goto-char (setq p (point-max)))
   7.216 +	  (insert " [No match]")
   7.217 +	  (goto-char p)
   7.218 +	  (sit-for 2)
   7.219 +	  (delete-region p (point-max)))))
   7.220 +     ((string= compl word)
   7.221 +      (with-output-to-temp-buffer "*Completions*"
   7.222 +	(display-completion-list
   7.223 +	 (all-completions word minibuffer-completion-table))))
   7.224 +     (t (delete-region beg (point-max))
   7.225 +	(insert compl))
   7.226 +     ))
   7.227 +)
   7.228 +
   7.229 +
   7.230 +(provide 'yatexlib)
     8.1 --- a/yatexmth.el	Thu Jul 07 16:37:05 1994 +0000
     8.2 +++ b/yatexmth.el	Thu Jul 07 16:37:05 1994 +0000
     8.3 @@ -1,18 +1,18 @@
     8.4  ;;; -*- Emacs-Lisp -*-
     8.5 -;;; YaTeX interface for math-mode.
     8.6 +;;; YaTeX math-mode-specific functions.
     8.7  ;;; yatexmth.el rev.2
     8.8  ;;; (c )1993-1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
     8.9 -;;; Last modified Sat Apr 23 02:26:57 1994 on pajero
    8.10 +;;; Last modified Fri Jul  8 00:48:24 1994 on figaro
    8.11  ;;; $Id$
    8.12  
    8.13  ;;; [Customization guide]
    8.14  ;;;
    8.15  ;;;	  By default,  you can use two  completion  groups in YaTeX math
    8.16 -;;;	mode, `,' for mathematical signs and `/' for greek letters.  But
    8.17 +;;;	mode, `;' for mathematical signs and `/' for greek letters.  But
    8.18  ;;;	you  can add other completion groups   by defining the  alist of
    8.19  ;;;	`prefix  key'    vs   `completion   list'    into  the  variable
    8.20  ;;;	YaTeX-math-key-list-private.  If  you wish  to    accomplish the
    8.21 -;;;	completion as follows(prefix key is `;'):
    8.22 +;;;	completion as follows(prefix key is `,'):
    8.23  ;;;
    8.24  ;;;		KEY		COMPLETION
    8.25  ;;;		s		\sin
    8.26 @@ -24,7 +24,7 @@
    8.27  ;;;		l		\log
    8.28  ;;;		hs		\sinh
    8.29  ;;;
    8.30 -;;;	Typing `s' after `;' makes `\sin', `hs' after `;' makes `\sinh'
    8.31 +;;;	Typing `s' after `,' makes `\sin', `hs' after `,' makes `\sinh'
    8.32  ;;;	and so on.  First, you have to define list of key-completion
    8.33  ;;;	pairs.  Variable name(YaTeX-math-funcs-list) is arbitrary.
    8.34  ;;;
    8.35 @@ -38,21 +38,21 @@
    8.36  ;;;	above) into the variable YaTeX-math-key-list-private.
    8.37  ;;;
    8.38  ;;;		(setq YaTeX-math-key-list-private
    8.39 -;;;		      '((";" . YaTeX-math-funcs-list)
    8.40 +;;;		      '(("," . YaTeX-math-funcs-list)
    8.41  ;;;			("'" . Other-List-if-any)))
    8.42  ;;;
    8.43  ;;;	  Put these expressions into your ~/.emacs, and you can use this
    8.44  ;;;	completion in the YaTeX-math-mode.
    8.45  ;;;
    8.46  ;;;	  And you can add your favorite completion sequences to the
    8.47 -;;;	default completion list invoked with `,', by defining those lists
    8.48 +;;;	default completion list invoked with `;', by defining those lists
    8.49  ;;;	into variable YaTeX-math-sign-alist-private.
    8.50  
    8.51  ;;; 【イメージ補完の追加方法】
    8.52  ;;;
    8.53 -;;;	  標準のイメージ補完では、「,」で始まる数式記号補完と、「/」で始
    8.54 +;;;	  標準のイメージ補完では、「;」で始まる数式記号補完と、「/」で始
    8.55  ;;;	まるギリシャ文字補完が使用可能ですが、これ以外の文字で始まる補完
    8.56 -;;;	シリーズも定義することができます。例えば、「;」で始まる次のよう
    8.57 +;;;	シリーズも定義することができます。例えば、「,」で始まる次のよう
    8.58  ;;;	な補完シリーズを定義する場合を考えてみます。
    8.59  ;;;
    8.60  ;;;		補完キー	補完結果
    8.61 @@ -65,7 +65,7 @@
    8.62  ;;;		l		\log
    8.63  ;;;		hs		\sinh
    8.64  ;;;
    8.65 -;;;	「;」のあとに s を押すと \sin が、hs を押すと \sinh が入力されま
    8.66 +;;;	「,」のあとに s を押すと \sin が、hs を押すと \sinh が入力されま
    8.67  ;;;	す。このような補完リストの登録は以下のようにします(変数名は任意)。
    8.68  ;;;
    8.69  ;;;		(setq YaTeX-math-funcs-list
    8.70 @@ -74,11 +74,11 @@
    8.71  ;;;				:
    8.72  ;;;			("hs"	"sinh")))
    8.73  ;;;
    8.74 -;;;	さらに、「;」を押した時にイメージ補完が始まるよう次の変数に、起動キー
    8.75 +;;;	さらに、「,」を押した時にイメージ補完が始まるよう次の変数に、起動キー
    8.76  ;;;	と上で定義した補完用変数の登録を行ないます。
    8.77  ;;;
    8.78  ;;;		(setq YaTeX-math-key-list-private
    8.79 -;;;		      '((";" . YaTeX-math-funcs-list)
    8.80 +;;;		      '(("," . YaTeX-math-funcs-list)
    8.81  ;;;			("'" . ほかに定義したいシリーズがあれば…)))
    8.82  ;;;
    8.83  ;;;	これらを ~/.emacs に書いておけば、野鳥の math-mode で自分専用の
    8.84 @@ -106,6 +106,7 @@
    8.85  (YaTeX-setq-math-sym YaTeX-image-bot		"|\n ̄"	"⊥")
    8.86  (YaTeX-setq-math-sym YaTeX-image-neg		"イ"		"¬")
    8.87  (YaTeX-setq-math-sym YaTeX-image-flat		"b"		"♭")
    8.88 +(YaTeX-setq-math-sym YaTeX-image-sqrt		""		"√")
    8.89  
    8.90  (setq
    8.91   YaTeX-math-sign-alist-default
    8.92 @@ -116,6 +117,8 @@
    8.93     ("sigma"	"sum"		("\\-+\n >\n/-+" "Σ"))
    8.94     ("integral"	"int"		(" /\\\n \\\n\\/" YaTeX-image-int))
    8.95     ("ointegral"	"oint"		" /\\\n(\\)\n\\/")
    8.96 +   ("sqrt"	"sqrt"		("  __\n,/" YaTeX-image-sqrt))
    8.97 +   ("root"	"sqrt"		("  __\n,/" YaTeX-image-sqrt))
    8.98     ("A"		"forall"	"|_|\nV")
    8.99     ("E"		"exists"	"-+\n-+\n-+")
   8.100     ("!"		"neg"		("--+\n  |" YaTeX-image-neg))
   8.101 @@ -127,6 +130,7 @@
   8.102     ("-+"	"mp"		"-\n+")
   8.103     ("x"		"times"		("x" "×"))
   8.104     ("/"		"div"		(",\n-\n'" "÷"))
   8.105 +   ("f"		"frac"		"xxx\n---\nyyy" "÷")
   8.106     ("*"		"ast"		"*")
   8.107     ("#"		"star"		("_/\\_\n\\  /\n//\\\\" "★"))
   8.108     ("o"		"circ"		"o")
   8.109 @@ -366,18 +370,6 @@
   8.110    (define-key YaTeX-math-menu-map "\^m"	'exit-recursive-edit)
   8.111    (define-key YaTeX-math-menu-map "q"	'abort-recursive-edit))
   8.112  
   8.113 -(defvar YaTeX-math-key-list-default
   8.114 -  '(("," . YaTeX-math-sign-alist)
   8.115 -    ("/" . YaTeX-greek-key-alist))
   8.116 -  "Default key sequence to invoke math-mode's image completion."
   8.117 -)
   8.118 -(defvar YaTeX-math-key-list-private nil
   8.119 -  "*User defined alist, math-mode-prefix vs completion alist"
   8.120 -)
   8.121 -(defvar YaTeX-math-key-list
   8.122 -  (append YaTeX-math-key-list-private YaTeX-math-key-list-default)
   8.123 -  "Key sequence to invoke math-mode's image completion."
   8.124 -)
   8.125  (defvar YaTeX-math-exit-key "\e"
   8.126    "*Key sequence after prefix key of YaTeX-math-mode to exit from math-mode."
   8.127  )
   8.128 @@ -390,43 +382,30 @@
   8.129  ;;;
   8.130  ;;YaTeX math-mode functions
   8.131  ;;;
   8.132 -;##autoload from yatex.el
   8.133 +;;;###autoload from yatex.el
   8.134  (defun YaTeX-toggle-math-mode (&optional arg)
   8.135    (interactive "P")
   8.136 -  (require 'yatexmth)
   8.137    (or (memq 'YaTeX-math-mode mode-line-format) nil
   8.138        (setq mode-line-format
   8.139  	    (append (list "" 'YaTeX-math-mode) mode-line-format)))
   8.140 -  (if (or arg (null YaTeX-math-mode))
   8.141 -      (let ((keys ""))
   8.142 -	(setq YaTeX-math-mode "math:")
   8.143 -	(mapcar
   8.144 -	 (function (lambda (x)
   8.145 -		     (let ((key (car x)) (list (cdr x)))
   8.146 -		       (setq keys (concat keys " " key))
   8.147 -		       (put 'YaTeX-math-key-list list (key-binding key))
   8.148 -		       (define-key YaTeX-mode-map key
   8.149 -			 'YaTeX-math-insert-sequence))))
   8.150 -	 YaTeX-math-key-list)
   8.151 -	(message "Turn on math mode. Prefix keys are %s" keys)
   8.152 -	(sit-for 3)
   8.153 -	(message
   8.154 -	 (concat "To exit from math-mode, type `ESC' after prefix, "
   8.155 -		 "or type `"
   8.156 -		 (key-description
   8.157 -		  (car
   8.158 -		   (where-is-internal 'YaTeX-switch-mode-menu YaTeX-mode-map)))
   8.159 -		 " $'")))
   8.160 -    (setq YaTeX-math-mode nil)
   8.161 -    (mapcar
   8.162 -     (function (lambda (x)
   8.163 -		 (let ((key (car x)) (list (cdr x)))
   8.164 -		   (define-key YaTeX-mode-map key
   8.165 -		     (get 'YaTeX-math-key-list list)))))
   8.166 -     YaTeX-math-key-list)
   8.167 -    (setq YaTeX-math-mode nil)
   8.168 -    (message "Exit from math mode."))
   8.169 -  (set-buffer-modified-p (buffer-modified-p))
   8.170 +  (if YaTeX-auto-math-mode nil		;Only effective on manual mode.
   8.171 +    (if (or arg (null YaTeX-math-mode))
   8.172 +	(let (keys)
   8.173 +	  (setq YaTeX-math-mode "math:")
   8.174 +	  (message "Turn on math mode. Prefix keys are %s"
   8.175 +		   (mapconcat 'car YaTeX-math-key-list " "))
   8.176 +	  (sit-for 3)
   8.177 +	  (message
   8.178 +	   (concat "To exit from math-mode, type `ESC' after prefix, "
   8.179 +		   "or type `"
   8.180 +		   (key-description
   8.181 +		    (car
   8.182 +		     (where-is-internal
   8.183 +		      'YaTeX-switch-mode-menu YaTeX-mode-map)))
   8.184 +		   " $'")))
   8.185 +      (setq YaTeX-math-mode nil)
   8.186 +      (message "Exit from math mode."))
   8.187 +    (set-buffer-modified-p (buffer-modified-p)))
   8.188  )
   8.189  
   8.190  (defun YaTeX-math-forward (arg)
   8.191 @@ -455,6 +434,47 @@
   8.192    (YaTeX-math-gets (car (cdr-safe (cdr-safe list))))
   8.193  )
   8.194  
   8.195 +(defun YaTeX-in-math-mode-p ()
   8.196 +  "If current position is supposed to be in LaTeX-math-mode, return t."
   8.197 +  (or (YaTeX-quick-in-environment-p
   8.198 +       '("math" "eqnarray" "equation" "eqnarray*" "displaymath"))
   8.199 +      (let ((p (point)) (nest 0) me0
   8.200 +	    (boundary
   8.201 +	     (save-excursion
   8.202 +	       (if (looking-at YaTeX-paragraph-delimiter)
   8.203 +		   (goto-char (max (point-min) (1- (point)))))
   8.204 +	       (re-search-backward YaTeX-paragraph-delimiter nil 1)
   8.205 +	       (point))))
   8.206 +	(save-excursion
   8.207 +	  (cond
   8.208 +	   ((catch 'open
   8.209 +	      (save-excursion
   8.210 +		(while (and (>= nest 0)
   8.211 +			    (re-search-backward
   8.212 +			     (concat YaTeX-ec-regexp	;\
   8.213 +				     "\\([()]\\|[][]\\)") boundary t))
   8.214 +		  (setq me0 (match-end 0))
   8.215 +		  (if (or (YaTeX-on-comment-p)
   8.216 +			  (YaTeX-quick-in-environment-p "verbatim")) nil
   8.217 +		    (if (or (= (char-after (1- me0)) ?\))
   8.218 +			    (= (char-after (1- me0)) ?\]))
   8.219 +			(setq nest (1+ nest))
   8.220 +		      (setq nest (1- nest)))))
   8.221 +		(if (< nest 0) (throw 'open t))))
   8.222 +	    t)
   8.223 +	   (t (catch 'dollar
   8.224 +		(while (search-backward "$" boundary t)
   8.225 +		  (cond
   8.226 +		   ((equal (char-after (1- (point))) ?$) ; $$ equation $$
   8.227 +		    (backward-char 1)
   8.228 +		    (setq nest (1+ nest)))
   8.229 +		   ((and (equal (char-after (1- (point))) ?\\ )
   8.230 +			 (not (equal (char-after (- (point) 3)) ?\\ )))
   8.231 +		    nil)		;\$
   8.232 +		   (t (setq nest (1+ nest)))))
   8.233 +		(if (= (% nest 2) 1) (throw 'dollar t))))))))
   8.234 +)
   8.235 +
   8.236  (defun YaTeX-math-display-list (list cols)
   8.237    (goto-char (point-max))
   8.238    (if (= cols 0) (if (not (eolp)) (newline 1))
   8.239 @@ -551,8 +571,9 @@
   8.240  	  (setq buffer-file-name name)
   8.241  	  (set-buffer-modified-p modified)))))
   8.242  
   8.243 -(defun YaTeX-math-insert-sequence ()
   8.244 -  (interactive)
   8.245 +(defun YaTeX-math-insert-sequence (&optional force)
   8.246 +  "Insert math-mode sequence with image completion."
   8.247 +  (interactive "P")
   8.248    (let*((key "") regkey str  last-char list i
   8.249  	(case-fold-search nil) match sign
   8.250  	(this-key (char-to-string last-command-char))
   8.251 @@ -560,8 +581,12 @@
   8.252  	(n (length alist)) (beg (point)) result)
   8.253      (setq result
   8.254  	  (catch 'complete
   8.255 +	    (if (and (not force)
   8.256 +		     (or (and (not YaTeX-auto-math-mode) (not YaTeX-math-mode))
   8.257 +			 (not (YaTeX-in-math-mode-p))))
   8.258 +		(throw 'complete 'escape));this tag should be exit, but...
   8.259  	    (while t
   8.260 -	      (message "Sequence: %s" key)
   8.261 +	      (message "Sequence(TAB for menu): %s" key)
   8.262  	      (setq last-char (read-char)
   8.263  		    key (concat key (char-to-string last-char))
   8.264  		    i 0)
   8.265 @@ -570,20 +595,24 @@
   8.266  		(throw 'complete 'escape))
   8.267  	       ((string= key YaTeX-math-exit-key)	;;exit from math-mode
   8.268  		(throw 'complete 'exit))
   8.269 -	       ((string-match "[\C-g\C-c]" key) (throw 'complete 'abort))
   8.270 -	       ((string-match "[\n\r]" key) (throw 'complete 'menu))
   8.271 -	       ((string-match "[\C-h\C-?]" key)
   8.272 -		(if (string= key "") (throw 'complete 'abort))
   8.273 +	       ((string-match "\r" key)			;;RET = kakutei
   8.274 +		(throw 'complete 'select))
   8.275 +	       ((string-match "[\C-g\C-c]" key)		;;C-g = abort
   8.276 +		(throw 'complete 'abort))
   8.277 +	       ((string-match "[\t\n]" key)		;;TAB, LFD = menu
   8.278 +		(throw 'complete 'menu))
   8.279 +	       ((string-match "[\C-h\C-?]" key)		;;BS, DEL = BS
   8.280 +		(if (< (length key) 2) (throw 'complete 'abort))
   8.281  		(setq key (substring key 0 -2))))
   8.282  	      
   8.283  	      (setq regkey (concat "^" (regexp-quote key)))
   8.284 -	      (message "Sequence: %s" key)
   8.285 +	      (message "Sequence(TAB for menu): %s" key)
   8.286  	      (if
   8.287  		  (catch 'found
   8.288  		    ;;(1)input string strictly matches with alist
   8.289 -		    (setq single-command (car (cdr match))
   8.290 -			  ;;remember previous match
   8.291 -			  match (assoc key alist))
   8.292 +		    (setq match (assoc key alist))
   8.293 +		    ;;remember previous match
   8.294 +
   8.295  		    ;;(2)search partial match into alist
   8.296  		    (setq list alist)
   8.297  		    (while (< i n)
   8.298 @@ -591,8 +620,7 @@
   8.299  			   regkey
   8.300  			   ;;(aref array i)
   8.301  			   ;;(car (nth i alist))
   8.302 -			   (car (car list))
   8.303 -			   )
   8.304 +			   (car (car list)))
   8.305  			  (progn
   8.306  			    (or match
   8.307  				;;(setq match (nth i alist))
   8.308 @@ -602,11 +630,12 @@
   8.309  		  nil ;;if any match, continue reading
   8.310  		;;else reading of sequence has been done.
   8.311  		(message "complete.")
   8.312 -		(throw 'complete t)
   8.313 -		)
   8.314 +		(throw 'complete t))
   8.315 +
   8.316  	      (if match
   8.317  		  (progn (delete-region beg (point))
   8.318 -			 (insert YaTeX-ec (car (cdr match)))
   8.319 +			 (setq single-command (car (cdr match)))
   8.320 +			 (insert YaTeX-ec single-command)
   8.321  			 (if (and YaTeX-math-need-image
   8.322  				  (setq sign (YaTeX-math-get-sign match)))
   8.323  			     (YaTeX-math-show-image (concat sign "\n")))
   8.324 @@ -616,12 +645,7 @@
   8.325      (cond
   8.326       ((eq result t)
   8.327        (setq YaTeX-current-completion-type 'maketitle)
   8.328 -      (if t nil
   8.329 -	(delete-region beg (point))
   8.330 -	(setq single-command (car (cdr match)))
   8.331 -	;;(recursive-edit)
   8.332 -	(insert YaTeX-ec single-command)
   8.333 -	)
   8.334 +
   8.335        ;;;(sit-for 1)
   8.336        (setq unread-command-char last-char)
   8.337        (insert (YaTeX-addin single-command)))
   8.338 @@ -631,6 +655,8 @@
   8.339       ((eq result 'escape)
   8.340        (delete-region beg (point))
   8.341        (insert this-key))
   8.342 +     ((eq result 'select)
   8.343 +      (message "Done."))
   8.344       ((eq result 'exit)
   8.345        (delete-region beg (point))
   8.346        (YaTeX-toggle-math-mode))
     9.1 --- a/yatexprc.el	Thu Jul 07 16:37:05 1994 +0000
     9.2 +++ b/yatexprc.el	Thu Jul 07 16:37:05 1994 +0000
     9.3 @@ -2,7 +2,7 @@
     9.4  ;;; YaTeX process handler.
     9.5  ;;; yatexprc.el
     9.6  ;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
     9.7 -;;; Last modified Fri May 13 01:22:54 1994 on 98fa
     9.8 +;;; Last modified Fri Jul  1 02:44:32 1994 on figaro
     9.9  ;;; $Id$
    9.10  
    9.11  (require 'yatex)
    9.12 @@ -44,7 +44,7 @@
    9.13      (with-output-to-temp-buffer buffer
    9.14        (if YaTeX-dos			;if MS-DOS
    9.15  	  (progn
    9.16 -	    (message (concat "Typesetting " (buffer-name) "..."))
    9.17 +	    (message (format "Calling `%s'..." command))
    9.18  	    (YaTeX-put-nonstopmode)
    9.19  	    (call-process shell-file-name
    9.20  			  nil buffer nil "/c" command)
    9.21 @@ -64,10 +64,9 @@
    9.22  		YaTeX-latex-message-code YaTeX-coding-system))
    9.23  	      ((boundp 'NEMACS)
    9.24  	       (set-kanji-process-code YaTeX-latex-message-code))))
    9.25 -    (message "Type SPC to continue.")
    9.26      (goto-char (point-max))
    9.27      (if YaTeX-dos (message "Done.")
    9.28 -      (insert (message " "))
    9.29 +      (insert " ")
    9.30        (set-marker (process-mark YaTeX-typeset-process) (1- (point))))
    9.31      (if (bolp) (forward-line -1))
    9.32      (recenter -1)
    9.33 @@ -80,16 +79,19 @@
    9.34           (set-process-buffer proc nil))
    9.35          ((memq (process-status proc) '(signal exit))
    9.36           (let* ((obuf (current-buffer)) (pbuf (process-buffer proc))
    9.37 +		(pwin (get-buffer-window pbuf))
    9.38  		(owin (selected-window)) win)
    9.39             ;; save-excursion isn't the right thing if
    9.40             ;;  process-buffer is current-buffer
    9.41             (unwind-protect
    9.42                 (progn
    9.43                   ;; Write something in *typesetting* and hack its mode line
    9.44 -		 (YaTeX-pop-to-buffer pbuf)
    9.45 -		 (set-buffer (process-buffer proc))
    9.46 +		 (if pwin
    9.47 +		     (select-window pwin)
    9.48 +		   (set-buffer pbuf))
    9.49 +		 ;;(YaTeX-showup-buffer pbuf nil t)
    9.50                   (goto-char (point-max))
    9.51 -		 (recenter -3)
    9.52 +		 (if pwin (recenter -3))
    9.53                   (insert ?\n "latex typesetting " mes)
    9.54                   (forward-char -1)
    9.55                   (insert " at " (substring (current-time-string) 0 -5) "\n")
    9.56 @@ -132,19 +134,34 @@
    9.57      (let*
    9.58  	((end "") typeout ;Type out message that tells the method of cutting.
    9.59  	 (cmd (concat (YaTeX-get-latex-command nil) " " YaTeX-texput-file))
    9.60 -	 (buffer (current-buffer)) opoint preamble main
    9.61 +	 (buffer (current-buffer)) opoint preamble (subpreamble "") main
    9.62  	 reg-begin reg-end)
    9.63 -      
    9.64 -      (if (re-search-backward "%#BEGIN" nil t)
    9.65 +
    9.66 +      (if (search-backward "%#BEGIN" nil t)
    9.67  	  (progn
    9.68 -	    (setq typeout "--- Region from BEGIN to " end "END ---"
    9.69 +	    (setq typeout "--- Region from BEGIN to "
    9.70 +		  end "the end of the buffer ---"
    9.71  		  reg-begin (match-end 0))
    9.72 -	    (if (re-search-forward "%#END" nil t)
    9.73 +	    (if (search-forward "%#END" nil t)
    9.74  		(setq reg-end (match-beginning 0)
    9.75 -		      end "end of buffer ---")
    9.76 +		      end "END ---")
    9.77  	      (setq reg-end (point-max))))
    9.78  	(setq typeout "=== Region from (point) to (mark) ===")
    9.79  	(setq reg-begin (point) reg-end (mark)))
    9.80 +      (goto-char (point-min))
    9.81 +      (while (search-forward "%#REQUIRE" nil t)
    9.82 +	(setq subpreamble
    9.83 +	      (concat subpreamble
    9.84 +		      (cond
    9.85 +		       ((eolp)
    9.86 +			(buffer-substring
    9.87 +			 (match-beginning 0)
    9.88 +			 (point-beginning-of-line)))
    9.89 +		       (t (buffer-substring
    9.90 +			   (match-end 0)
    9.91 +			   (point-end-of-line))))
    9.92 +		      "\n"))
    9.93 +	(goto-char (match-end 0)))
    9.94        (YaTeX-visit-main t)
    9.95        (setq main (current-buffer))
    9.96        (setq opoint (point))
    9.97 @@ -162,7 +179,7 @@
    9.98        (erase-buffer)
    9.99        (if YaTeX-need-nonstop
   9.100  	  (insert "\\nonstopmode{}\n"))
   9.101 -      (insert preamble "\n")
   9.102 +      (insert preamble "\n" subpreamble "\n")
   9.103        (insert-buffer-substring buffer reg-begin reg-end)
   9.104        (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
   9.105        (insert "\n\\end{document}\n")
   9.106 @@ -261,6 +278,8 @@
   9.107  (defun YaTeX-system (command buffer)
   9.108    "Execute some command on buffer.  Not a official function."
   9.109    (save-excursion
   9.110 +    (YaTeX-showup-buffer
   9.111 +     buffer (function (lambda (x) (nth 3 (window-edges x)))))
   9.112      (with-output-to-temp-buffer buffer
   9.113        (if YaTeX-dos
   9.114  	  (call-process shell-file-name nil buffer nil "/c " command)
   9.115 @@ -286,20 +305,24 @@
   9.116  				  0 (rindex YaTeX-texput-file ?.))
   9.117  		     (YaTeX-get-preview-file-name))
   9.118  		   ))))
   9.119 -  (setq dvi2-command preview-command)
   9.120 +  (setq dvi2-command preview-command)	;`dvi2command' is buffer local
   9.121    (save-excursion
   9.122      (YaTeX-visit-main t)
   9.123 -    (with-output-to-temp-buffer "*dvi-preview*"
   9.124 -      (if YaTeX-dos			;if MS-DOS
   9.125 -	  (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
   9.126 -		 (call-process shell-file-name "con" "*dvi-preview*" nil
   9.127 -			       "/c " dvi2-command preview-file)
   9.128 -		 (send-string-to-terminal "\e[>5l") ;show cursor
   9.129 -		 (redraw-display))
   9.130 -	(start-process "preview" "*dvi-preview*" shell-file-name "-c"
   9.131 -		       (concat dvi2-command " " preview-file)) ;if UNIX
   9.132 -	(message
   9.133 -	 (concat "Starting " dvi2-command " to preview " preview-file)))))
   9.134 +    (let ((pbuffer "*dvi-preview*"))
   9.135 +      (YaTeX-showup-buffer
   9.136 +       pbuffer (function (x) (nth 3 (window-edges x))))
   9.137 +      (with-output-to-temp-buffer pbuffer
   9.138 +	(if YaTeX-dos			;if MS-DOS
   9.139 +	    (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
   9.140 +		   (call-process shell-file-name "con" "*dvi-preview*" nil
   9.141 +				 "/c " preview-command preview-file)
   9.142 +		   (send-string-to-terminal "\e[>5l") ;show cursor
   9.143 +		   (redraw-display))
   9.144 +	  (start-process "preview" "*dvi-preview*" shell-file-name "-c"
   9.145 +			 (concat preview-command " " preview-file)) ;if UNIX
   9.146 +	  (message
   9.147 +	   (concat "Starting " preview-command
   9.148 +		   " to preview " preview-file))))))
   9.149  )
   9.150  
   9.151  (defun YaTeX-prev-error ()
   9.152 @@ -311,7 +334,7 @@
   9.153  	error-line typeset-win error-buffer error-win)
   9.154      (if (null (get-buffer YaTeX-typeset-buffer))
   9.155  	(error "There is no typesetting buffer."))
   9.156 -    (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
   9.157 +    (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
   9.158      (setq typeset-win (selected-window))
   9.159      (if (re-search-backward
   9.160  	 (concat "\\(" latex-error-regexp "\\)\\|\\("
   9.161 @@ -397,8 +420,9 @@
   9.162    (if (null (get-buffer YaTeX-typeset-buffer))
   9.163        (message "No typeset buffer found.")
   9.164      (let ((win (selected-window)))
   9.165 -      (YaTeX-pop-to-buffer YaTeX-typeset-buffer)
   9.166 +      (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
   9.167        (goto-char (point-max))
   9.168 +      (forward-line -1)
   9.169        (recenter -1)
   9.170        (select-window win)))
   9.171  )
   9.172 @@ -504,7 +528,8 @@
   9.173    "Print out.  If prefix arg ARG is non nil, call print driver without
   9.174  page range description."
   9.175    (interactive "P")
   9.176 -  (let*(from to (cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)))
   9.177 +  (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format))
   9.178 +	from to (lbuffer "*dvi-printing*"))
   9.179      (setq
   9.180       cmd 
   9.181       (YaTeX-replace-format
   9.182 @@ -534,7 +559,9 @@
   9.183  			 (format cmd (YaTeX-get-preview-file-name)))))
   9.184      (save-excursion
   9.185        (YaTeX-visit-main t) ;;change execution directory
   9.186 -      (with-output-to-temp-buffer "*dvi-printing*"
   9.187 +      (YaTeX-showup-buffer
   9.188 +       lbuffer (function (lambda (x) (nth 3 (window-edges x)))))
   9.189 +      (with-output-to-temp-buffer lbuffer
   9.190  	(if YaTeX-dos
   9.191  	    (call-process shell-file-name "con" "*dvi-printing*" nil
   9.192  			  "/c " cmd)
   9.193 @@ -565,7 +592,8 @@
   9.194      (if (setq b-in (YaTeX-get-builtin "!"))
   9.195  	(setq main-file (YaTeX-guess-parent b-in)))
   9.196      (if YaTeX-parent-file
   9.197 -	(setq main-file (get-file-buffer YaTeX-parent-file)))
   9.198 +	(setq main-file ;;(get-file-buffer YaTeX-parent-file)
   9.199 +	      YaTeX-parent-file))
   9.200      (if (YaTeX-main-file-p)
   9.201  	(if (interactive-p) (message "I think this is main LaTeX source.") nil)
   9.202        (cond
   9.203 @@ -632,47 +660,4 @@
   9.204  	    (buffer-list)))
   9.205  )
   9.206  
   9.207 -(defun YaTeX-pop-to-buffer (buffer &optional win)
   9.208 -  (if (setq win (get-buffer-window buffer))
   9.209 -      (select-window win)
   9.210 -    (pop-to-buffer buffer))
   9.211 -)
   9.212 -
   9.213 -(defun YaTeX-showup-buffer (buffer &optional func select)
   9.214 -  "Make BUFFER show up in certain window (but current window)
   9.215 -that gives the maximum value by the FUNC.  FUNC should take an argument
   9.216 -of its window object.  Non-nil for optional third argument SELECT selects
   9.217 -that window."
   9.218 -  (or (and (get-buffer-window buffer)
   9.219 -	   (progn (if select (select-window (get-buffer-window buffer)))
   9.220 -		  t))
   9.221 -      (cond
   9.222 -       ((> (length (YaTeX-window-list)) 2)
   9.223 -	(let ((window (selected-window))
   9.224 -	      (list (YaTeX-window-list)) win w (x 0))
   9.225 -	  (if func
   9.226 -	      (while list
   9.227 -		(setq w (car list))
   9.228 -		(if (and (not (eq window w))
   9.229 -			 (> (funcall func w) x))
   9.230 -		    (setq win w x (funcall func w)))
   9.231 -		(setq list (cdr list)))
   9.232 -	    (setq win (get-lru-window)))
   9.233 -	  (select-window win)
   9.234 -	  (switch-to-buffer buffer)
   9.235 -	  (or select (select-window window))))
   9.236 -       ((= (length (YaTeX-window-list)) 2)
   9.237 -	(let ((window (selected-window)))
   9.238 -	  (other-window 1)
   9.239 -	  (switch-to-buffer buffer)
   9.240 -	  (or select (select-window window))))
   9.241 -       (t nil)))
   9.242 -)
   9.243 -
   9.244 -(defun YaTeX-window-list ()
   9.245 -  (let*((curw (selected-window)) (win curw) (wlist (list curw)))
   9.246 -    (while (not (eq curw (setq win (next-window win))))
   9.247 -      (setq wlist (cons win wlist)))
   9.248 -    wlist)
   9.249 -)
   9.250  (provide 'yatexprc)
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/yatexsec.el	Thu Jul 07 16:37:05 1994 +0000
    10.3 @@ -0,0 +1,281 @@
    10.4 +;;; -*- Emacs-Lisp -*-
    10.5 +;;; YaTeX sectioning browser.
    10.6 +;;; yatexsec.el
    10.7 +;;; (c ) 1994 by HIROSE Yuuji [yuuji@ae.keio.ac.jp]
    10.8 +;;; Last modified Thu Jul  7 01:26:26 1994 on 98fa
    10.9 +;;; $Id$
   10.10 +
   10.11 +(defvar YaTeX-sectioning-level
   10.12 +  '(("part" . 0) ("chapter" . 1) ("section" . 2) ("subsection" . 3)
   10.13 +    ("subsubsection" . 4) ("paragraph" . 5) ("subparagraph" . 6))
   10.14 +  "Sectioning level.")
   10.15 +
   10.16 +(defun YaTeX-sectioning-map-hide (map)
   10.17 +  (let ((ch ?0))
   10.18 +    (while (<= ch ?9)
   10.19 +      (define-key map (char-to-string ch) 'YaTeX-sectioning-hide)
   10.20 +      (setq ch (1+ ch))))
   10.21 +)
   10.22 +
   10.23 +(defvar YaTeX-minibuffer-sectioning-map nil
   10.24 +  "Key map used in minibuffer for sectioning.")
   10.25 +(if YaTeX-minibuffer-sectioning-map nil
   10.26 +  (setq YaTeX-minibuffer-sectioning-map
   10.27 +	(copy-keymap minibuffer-local-completion-map))
   10.28 +  (define-key YaTeX-minibuffer-sectioning-map "\C-p"
   10.29 +    'YaTeX-sectioning-up)
   10.30 +  (define-key YaTeX-minibuffer-sectioning-map "\C-e"
   10.31 +    'YaTeX-sectioning-up)
   10.32 +  (define-key YaTeX-minibuffer-sectioning-map "\C-i"
   10.33 +    'YaTeX-minibuffer-complete)
   10.34 +  (define-key YaTeX-minibuffer-sectioning-map " "
   10.35 +    'YaTeX-minibuffer-complete)
   10.36 +  (define-key YaTeX-minibuffer-sectioning-map "\C-n"
   10.37 +    'YaTeX-sectioning-down)
   10.38 +  (define-key YaTeX-minibuffer-sectioning-map "\C-x"
   10.39 +    'YaTeX-sectioning-down)
   10.40 +  (define-key YaTeX-minibuffer-sectioning-map "\C-v"
   10.41 +    'YaTeX-sectioning-scroll-up)
   10.42 +  (define-key YaTeX-minibuffer-sectioning-map "\C-c"
   10.43 +    'YaTeX-sectioning-scroll-up)
   10.44 +  (define-key YaTeX-minibuffer-sectioning-map "\M-v"
   10.45 +    'YaTeX-sectioning-scroll-down)
   10.46 +  (define-key YaTeX-minibuffer-sectioning-map "\C-r"
   10.47 +    'YaTeX-sectioning-scroll-down)
   10.48 +  (define-key YaTeX-minibuffer-sectioning-map "\C-w"
   10.49 +    '(lambda () (interactive) (YaTeX-sectioning-scroll-down 1)))
   10.50 +  (define-key YaTeX-minibuffer-sectioning-map "\C-z"
   10.51 +    '(lambda () (interactive) (YaTeX-sectioning-scroll-up 1)))
   10.52 +  (define-key YaTeX-minibuffer-sectioning-map "\C-l"
   10.53 +    'YaTeX-sectioning-recenter)
   10.54 +  (define-key YaTeX-minibuffer-sectioning-map "?"
   10.55 +    'YaTeX-sectioning-help)
   10.56 +  (YaTeX-sectioning-map-hide YaTeX-minibuffer-sectioning-map)
   10.57 +)
   10.58 +
   10.59 +(defvar YaTeX-sectioning-buffer-map nil
   10.60 +  "Key map used in YaTeX-sectioning-buffer.")
   10.61 +(if YaTeX-sectioning-buffer-map nil
   10.62 +  (setq YaTeX-sectioning-buffer-map (make-sparse-keymap))
   10.63 +  (define-key YaTeX-sectioning-buffer-map " "
   10.64 +    'YaTeX-sectioning-buffer-jump)
   10.65 +  (define-key YaTeX-sectioning-buffer-map (concat YaTeX-prefix "\C-c")
   10.66 +    'YaTeX-sectioning-buffer-jump)
   10.67 +  (YaTeX-sectioning-map-hide YaTeX-sectioning-buffer-map)
   10.68 +)
   10.69 +
   10.70 +(defvar YaTeX-sectioning-buffer-parent nil)
   10.71 +(defun YaTeX-sectioning-buffer-jump ()
   10.72 +  (interactive)
   10.73 +  (if (and YaTeX-sectioning-buffer-parent
   10.74 +	   (get-buffer YaTeX-sectioning-buffer-parent))
   10.75 +      (let (ptn)
   10.76 +	(beginning-of-line)
   10.77 +	(if (re-search-forward YaTeX-sectioning-regexp)
   10.78 +	    (progn (setq ptn (buffer-substring
   10.79 +			      (1- (match-beginning 0))
   10.80 +			      (progn (skip-chars-forward "^}") (1+ (point)))))
   10.81 +		   (YaTeX-showup-buffer YaTeX-sectioning-buffer-parent nil t)
   10.82 +		   (goto-char (point-max))
   10.83 +		   (search-backward ptn))
   10.84 +	  (message "No line number expression."))))
   10.85 +)
   10.86 +
   10.87 +(defun YaTeX-sectioning-hide-under (n)
   10.88 +  "Hide sectioning commands under level N."
   10.89 +  (let ((cw (selected-window)))
   10.90 +    (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t)
   10.91 +    (if (>= n (1- (length YaTeX-sectioning-level)))
   10.92 +	(progn
   10.93 +	  (set-selective-display nil)
   10.94 +	  (message "Show all."))
   10.95 +      (set-selective-display (1+ n))
   10.96 +      (if (nth n YaTeX-sectioning-level)
   10.97 +	  (message "Hide lower than %s" (car (nth n YaTeX-sectioning-level)))
   10.98 +	(message "")))
   10.99 +    (if (numberp selective-display)
  10.100 +	(setq mode-name (format "level %d" (1- selective-display)))
  10.101 +      (setq mode-name (format "all")))
  10.102 +    (select-window cw))
  10.103 +)
  10.104 +(defun YaTeX-sectioning-hide ()
  10.105 +  "Call YaTeX-sectioning-hide-under with argument according to pressed key."
  10.106 +  (interactive)
  10.107 +  (YaTeX-sectioning-hide-under (- last-command-char ?0)))
  10.108 +
  10.109 +(defun YaTeX-sectioning-help ()
  10.110 +  "Show help of sectioning."
  10.111 +  (interactive)
  10.112 +  (let ((cw (selected-window)) sb (hb (get-buffer-create "*Help*")))
  10.113 +    (unwind-protect
  10.114 +	(progn
  10.115 +	  (other-window 1)
  10.116 +	  (setq sb (current-buffer))
  10.117 +	  (switch-to-buffer hb)
  10.118 +	  (erase-buffer)
  10.119 +	  (insert "===== View sectioning =====
  10.120 +C-p	Up sectioning level.			0	Show only \\part, 
  10.121 +C-n	Down sectioning level.			1	 and \\chapter,
  10.122 +C-v	Scroll up *Sectioning line* buffer.	2	 and \\section,
  10.123 +M-v	Scroll down *Sectioning line* buffer.	3	 and \\subsection,
  10.124 +SPC	Complete word.				4	 and \\subsubsection,
  10.125 +TAB	Complete word.				5	 and \\paragraph.
  10.126 +C-l	Recenter recent line.			6	Show all.
  10.127 +RET	Select.
  10.128 +==== End of HELP =====
  10.129 +")
  10.130 +	  (set-buffer-modified-p nil)
  10.131 +	  (goto-char (point-min))
  10.132 +	  (momentary-string-display "" (point-min)))
  10.133 +      (bury-buffer hb)
  10.134 +      (switch-to-buffer sb)
  10.135 +      (select-window cw)))
  10.136 +)
  10.137 +
  10.138 +(defun YaTeX-sectioning-up (n)
  10.139 +  "Up section level.
  10.140 +Refers the YaTeX-read-section-in-minibuffer's local variable minibuffer-start."
  10.141 +  (interactive "p")
  10.142 +  (if (eq (selected-window) (minibuffer-window))
  10.143 +      (let*((command (buffer-string))
  10.144 +	    (alist YaTeX-sectioning-level)
  10.145 +	    (level (cdr-safe (assoc command alist))))
  10.146 +	(or level (error "No such sectioning command."))
  10.147 +	(setq level (- level n))
  10.148 +	(if (or (< level 0) (>= level (length alist)))
  10.149 +	    (ding)
  10.150 +	  (erase-buffer)
  10.151 +	  (insert (car (nth level alist))))
  10.152 +    ))
  10.153 +)
  10.154 +
  10.155 +(defun YaTeX-sectioning-down (n)
  10.156 +  "Down section level."
  10.157 +  (interactive "p")
  10.158 +  (YaTeX-sectioning-up (- n))
  10.159 +)
  10.160 +
  10.161 +(defun YaTeX-sectioning-scroll-up (n)
  10.162 +  (interactive "P")
  10.163 +  (let ((section-buffer YaTeX-sectioning-buffer)
  10.164 +	(cw (selected-window)))
  10.165 +    (YaTeX-showup-buffer section-buffer nil t)
  10.166 +    (unwind-protect
  10.167 +	(scroll-up (or n (- (window-height) 2)))
  10.168 +      (select-window cw)))
  10.169 +)
  10.170 +
  10.171 +(defun YaTeX-sectioning-scroll-down (n)
  10.172 +  (interactive "P")
  10.173 +  (let ((section-buffer YaTeX-sectioning-buffer)
  10.174 +	(cw (selected-window)))
  10.175 +    (YaTeX-showup-buffer section-buffer nil t)
  10.176 +    (unwind-protect
  10.177 +	(scroll-down (or n (- (window-height) 2)))
  10.178 +      (select-window cw)))
  10.179 +)
  10.180 +
  10.181 +(defun YaTeX-sectioning-recenter (arg)
  10.182 +  "Recenter `<<--' line"
  10.183 +  (interactive "P")
  10.184 +  (let ((cw (selected-window)))
  10.185 +    (unwind-protect
  10.186 +	(progn
  10.187 +	  (YaTeX-showup-buffer YaTeX-sectioning-buffer nil t)
  10.188 +	  (or (search-forward "<<--" nil t)
  10.189 +	      (search-backward "<<--" nil t))
  10.190 +	  (recenter (or arg (/ (window-height) 2))))
  10.191 +      (select-window cw)))
  10.192 +)
  10.193 +
  10.194 +(defvar YaTeX-sectioning-minibuffer " *sectioning*"
  10.195 +  "Miniuffer used for sectioning")
  10.196 +(defun YaTeX-read-section-in-minibuffer (prompt table &optional default delim)
  10.197 +  (interactive)
  10.198 +  (let ((minibuffer-completion-table table))
  10.199 +    (read-from-minibuffer
  10.200 +     prompt default YaTeX-minibuffer-sectioning-map))
  10.201 +)
  10.202 +
  10.203 +(defun YaTeX-get-sectioning-level ()
  10.204 +  "Get section-level on the cursor."
  10.205 +   (cdr-safe (assoc (buffer-substring
  10.206 +		     (point)
  10.207 +		     (progn (skip-chars-forward "a-z") (point)))
  10.208 +		     YaTeX-sectioning-level))
  10.209 +)
  10.210 +
  10.211 +(defvar YaTeX-sectioning-buffer "*Sectioning lines*")
  10.212 +(defun YaTeX-colloect-sections ()
  10.213 +  "Collect all the lines which contains sectioning command."
  10.214 +  (let ((cw (selected-window)) level indent begp (prevp 1) (prevl 1)
  10.215 +	(pattern (concat YaTeX-ec-regexp
  10.216 +			 "\\(" YaTeX-sectioning-regexp "\\)\\*?{"))
  10.217 +	(cb (current-buffer)))
  10.218 +    (save-excursion
  10.219 +      (YaTeX-showup-buffer YaTeX-sectioning-buffer) ;show buffer
  10.220 +      (goto-char (point-min))
  10.221 +      (with-output-to-temp-buffer YaTeX-sectioning-buffer
  10.222 +	(while (re-search-forward pattern nil t)
  10.223 +	  (goto-char (1+ (match-beginning 0)))
  10.224 +	  (setq level (YaTeX-get-sectioning-level)
  10.225 +		begp (match-beginning 0))
  10.226 +	  ;;(beginning-of-line)
  10.227 +	  ;;(skip-chars-forward " \t")
  10.228 +	  (setq indent (format "%%%ds" level))
  10.229 +	  (princ (format indent ""))
  10.230 +	  (if (YaTeX-on-comment-p) (princ "%"))
  10.231 +	  (princ (buffer-substring begp (progn (forward-list 1) (point))))
  10.232 +	  (setq prevl (+ prevl (count-lines prevp (point)) -1)
  10.233 +		prevp (point))
  10.234 +	  (princ (format " (line:%d)" prevl))
  10.235 +	  (princ "\n")))
  10.236 +      (set-buffer YaTeX-sectioning-buffer)
  10.237 +      (make-local-variable 'YaTeX-sectioning-buffer-parent)
  10.238 +      (use-local-map YaTeX-sectioning-buffer-map)
  10.239 +      (setq YaTeX-sectioning-buffer-parent cb)
  10.240 +      (if (numberp selective-display)
  10.241 +	  (setq mode-name (format "level %d" (1- selective-display))))
  10.242 +      YaTeX-sectioning-buffer))
  10.243 +)
  10.244 +
  10.245 +(defun YaTeX-section-overview ()
  10.246 +  "Show section overview.  Return the nearest sectioning command."
  10.247 +  (interactive)
  10.248 +  (let ((cw (selected-window)) (ln (count-lines (point-min) (point)))
  10.249 +	(pattern "(line:\\([0-9]+\\))")
  10.250 +	(secbuf YaTeX-sectioning-buffer) (command ""))
  10.251 +    (save-excursion
  10.252 +      (setq secbuf (YaTeX-colloect-sections))
  10.253 +      (YaTeX-showup-buffer secbuf nil t)
  10.254 +      (goto-char (point-max))
  10.255 +      (while (re-search-backward pattern nil t)
  10.256 +	(if (< ln (string-to-int (YaTeX-match-string 1))) nil
  10.257 +	  (beginning-of-line)
  10.258 +	  (search-forward YaTeX-ec)
  10.259 +	  (looking-at YaTeX-TeX-token-regexp)
  10.260 +	  (setq command (YaTeX-match-string 0))
  10.261 +	  (end-of-line)
  10.262 +	  (insert "  <<--")
  10.263 +	  (setq pattern (concat "HackyRegexp" "ForFailure"))))
  10.264 +      (set-buffer-modified-p nil)
  10.265 +      (forward-line 1)
  10.266 +      (if (eobp) (recenter -1) (recenter -3))
  10.267 +      (select-window cw)
  10.268 +      command))
  10.269 +)
  10.270 +
  10.271 +(defun YaTeX-make-section-with-overview ()
  10.272 +  "Input sectining command with previous overview."
  10.273 +  (interactive)
  10.274 +  (insert
  10.275 +   YaTeX-ec
  10.276 +   (YaTeX-read-section-in-minibuffer
  10.277 +    "Sectioning(Up=C-p, Down=C-n, Help=?): "
  10.278 +    YaTeX-sectioning-level (YaTeX-section-overview))
  10.279 +   "{}")
  10.280 +  (forward-char -1)
  10.281 +)
  10.282 +
  10.283 +(provide 'yatexsec)
  10.284 +;;(YaTeX-define-key "o" 'YaTeX-make-section-with-overview)