yatex

changeset 5:370a391533fd

Post fj.sources.
author yuuji
date Tue, 16 Feb 1993 08:51:15 +0000
parents 78dfe28b6a35
children 49be9ccb0b65
files yatex.el yatex.new
diffstat 2 files changed, 887 insertions(+), 223 deletions(-) [+]
line diff
     1.1 --- a/yatex.el	Mon Nov 30 07:29:11 1992 +0000
     1.2 +++ b/yatex.el	Tue Feb 16 08:51:15 1993 +0000
     1.3 @@ -1,12 +1,27 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5  ;;; Yet Another tex-mode for emacs.
     1.6 -;;; yatex.el rev.1.33
     1.7 -;;; (c)1991 by Hirose Yuuji.[yuuji@ae.keio.ac.jp]
     1.8 -;;; Last modified Sun Nov 29 16:04:57 1992 on 98fa
     1.9 +;;; yatex.el rev.1.37
    1.10 +;;; (c)1991-1993 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
    1.11 +;;; Last modified Fri Feb 12 16:05:54 1993 on VFR
    1.12  
    1.13 -(provide 'yatex-mode)
    1.14 +;; This software is distributed in the hope that it will be useful,
    1.15 +;; but WITHOUT ANY WARRANTY.  No author or distributor
    1.16 +;; accepts responsibility to anyone for the consequences of using it
    1.17 +;; or for whether it serves any particular purpose or works at all,
    1.18 +;; unless he says so in writing.  Refer to the GNU Emacs General Public
    1.19 +;; License for full details.
    1.20 +
    1.21 +;; Everyone is granted permission to copy, modify and redistribute
    1.22 +;; this software, but only under the conditions described in the
    1.23 +;; GNU Emacs General Public License.   A copy of this license is
    1.24 +;; supposed to have been given to you along with this software so you
    1.25 +;; can know your rights and responsibilities.  It should be in a
    1.26 +;; file named COPYING.  Among other things, the copyright notice
    1.27 +;; and this notice must be preserved on all copies.
    1.28 +
    1.29 +(provide 'yatex)
    1.30  (require 'comment)
    1.31 -(defconst YaTeX-revision-number "1.33"
    1.32 +(defconst YaTeX-revision-number "1.37"
    1.33    "Revision number of running yatex.el"
    1.34  )
    1.35  
    1.36 @@ -16,51 +31,84 @@
    1.37  ;; Preserving user preferred definitions.
    1.38  ;; ** Check all of these defvar-ed values **
    1.39  ;; ** and setq other values more suitable **
    1.40 -;; ** for your site, if nedded.           **
    1.41 +;; ** for your site, if needed.           **
    1.42  ;;;
    1.43  (defvar YaTeX-prefix "\^C"
    1.44 -  "Prefix key to trigger YaTeX functions.
    1.45 +  "*Prefix key to trigger YaTeX functions.
    1.46  You can select favorite prefix key by setq in your ~/.emacs."
    1.47  )
    1.48  (defvar YaTeX-open-lines 1
    1.49 -  "Blank lines between text and \??{??}"
    1.50 +  "*Blank lines between text and \??{??}"
    1.51  )
    1.52  (defvar YaTeX-fill-prefix ""
    1.53 -  "fill-prefix used for auto-fill-mode.
    1.54 -The defalut value is single TAB."
    1.55 +  "*fill-prefix used for auto-fill-mode.
    1.56 +The defalut value is null string."
    1.57 +)
    1.58 +(defvar YaTeX-fill-column 72
    1.59 +  "*fill-column used for auto-fill-mode."
    1.60  )
    1.61  (defvar YaTeX-comment-prefix "%"
    1.62    "TeX comment prefix."
    1.63  )
    1.64 +(defvar YaTeX-current-position-register ?3
    1.65 +  "*All of YaTeX completing input store the current position into
    1.66 +the register YaTeX-current-position-register.  So every time you
    1.67 +make a trip to any other part of text than you writing, you can
    1.68 +return to editing paragraph by calling register-to-point with argument
    1.69 +YaTeX-current-position-register."
    1.70 +)
    1.71  (defvar YaTeX-user-completion-table
    1.72 -  (if (eq system-type 'ms-dos) "~/_yatexrc"
    1.73 -    "~/.yatexrc")
    1.74 -  "Default filename in which user completion table is saved."
    1.75 +  (if (eq system-type 'ms-dos) "~/_yatexrc" "~/.yatexrc")
    1.76 +  "*Default filename in which user completion table is saved."
    1.77  )
    1.78  (defvar tex-command "jlatex"
    1.79 -  "Default command for compiling LaTeX text."
    1.80 +  "*Default command for compiling LaTeX text."
    1.81  )
    1.82  (defvar dvi2-command		;previewer command for your site
    1.83 -  (if (eq system-type 'ms-dos)
    1.84 -      "dviout"
    1.85 -    (concat
    1.86 -     "xdvi -geo +0+0 -s 4 -display "
    1.87 -     (getenv "DISPLAY")))
    1.88 -    "Default previewer command including its option.
    1.89 +  (if (eq system-type 'ms-dos) "dviout"
    1.90 +    (concat "xdvi -geo +0+0 -s 4 -display " (getenv "DISPLAY")))
    1.91 +  "*Default previewer command including its option.
    1.92  This default value is for X window system.  If you want to use this
    1.93  default, you have to make sure the environment variable DISPLAY is
    1.94  correctly set."
    1.95  )
    1.96 +(defvar dviprint-command-format
    1.97 +  (if (eq system-type 'ms-dos) "dviprt %s %f%t"
    1.98 +      "dvi2ps %f %t %s | lpr")
    1.99 +  "*Command line string to print out current file.  Format string %s
   1.100 +will be replaced by the filename.  Do not forget to specify the
   1.101 +`from usage' and `to usage' with their option by format string %f and %t.
   1.102 +See also documentation of dviprint-from-format and dviprint-to-format."
   1.103 +)
   1.104 +(defvar dviprint-from-format
   1.105 +  (if (eq system-type 'ms-dos) "%b-" "-f %b")
   1.106 +  "*From page format of dvi filter.  %b will turn to beginning page number."
   1.107 +)
   1.108 +(defvar dviprint-to-format
   1.109 +  (if (eq system-type 'ms-dos) "%e" "-t %e")
   1.110 +  "*To page format of dvi filter.  %e will turn to end page number."
   1.111 +)
   1.112 +(defvar YaTeX-japan (or (boundp 'NEMACS) (boundp 'MULE))
   1.113 +  "Whether yatex mode is running on Japanese environment or not."
   1.114 +)
   1.115 +(defvar YaTeX-default-document-style
   1.116 +  (concat (if YaTeX-japan "j") "article")
   1.117 +  "*Default LaTeX Documentstyle for YaTeX-typeset-region."
   1.118 +)
   1.119 +(defvar YaTeX-need-nonstop nil
   1.120 +  "*If t yatex automatically put `\nonstopmode{}' in current buffer
   1.121 +before invoke latex command."
   1.122 +)
   1.123  (defvar latex-warning-regexp "line.* [0-9]*"
   1.124 -  "Regular expression of line number of warning message by latex command."
   1.125 +  "*Regular expression of line number of warning message by latex command."
   1.126  )
   1.127  (defvar latex-error-regexp "l\\.[1-9][0-9]*"
   1.128 -  "Regular expression of line number of latex error.  Perhaps your latex
   1.129 +  "*Regular expression of line number of latex error.  Perhaps your latex
   1.130  command stops at this error message with line number of LaTeX source text."
   1.131  )
   1.132  (defvar latex-dos-emergency-message
   1.133    "Emergency stop"      ;<- for Micro tex, ASCII-pTeX 1.6
   1.134 -  "Because Demacs (GNU Emacs on DOS) cannot have pararell process, the
   1.135 +  "Because Demacs (GNU Emacs on DOS) cannot have concurrent process, the
   1.136  latex command which is stopping on a LaTeX error, is terminated by Demacs.
   1.137  Many latex command on DOS display some message when it is terminated by
   1.138  other process, user or OS.  Define this variable a message string of your
   1.139 @@ -68,6 +116,13 @@
   1.140    Remember Demacs's call-process function is not oriented for interactive
   1.141  process."
   1.142  )
   1.143 +(defvar latex-message-kanji-code 2
   1.144 +  "*Kanji coding system latex command types out.
   1.145 +1 = Shift JIS, 2 = JIS, 3 = EUC."
   1.146 +)
   1.147 +(defvar NTT-jTeX nil
   1.148 +  "*Use NTT-jTeX for latex command."
   1.149 +)
   1.150  
   1.151  ;------------ Completion table ------------
   1.152  ; Set tex-section-like command possible completion
   1.153 @@ -82,6 +137,7 @@
   1.154  	("nocite") ("input") ("include") ("includeonly") ("mbox") ("hbox")
   1.155  	("caption") ("newcommand") ("setlength") ("addtolength")
   1.156  	("newenvironment") ("newtheorem")
   1.157 +	("cline") ("framebox")
   1.158  ))
   1.159  (defvar user-section-table nil)
   1.160  
   1.161 @@ -93,6 +149,7 @@
   1.162  	("\\oddsidemargin") ("\\evensidemargin")
   1.163  	("\\textheight") ("\\topmargin")
   1.164  	("\\bottommargin") ("\\footskip") ("\\footheight")
   1.165 +	("\\baselineskip") ("\\baselinestretch") ("normalbaselineskip")
   1.166  ))
   1.167  (defvar user-article-table nil)
   1.168  
   1.169 @@ -100,10 +157,10 @@
   1.170  (setq env-table
   1.171        '(("quote") ("quotation") ("center") ("verse") ("document")
   1.172  	("verbatim") ("itemize") ("enumerate") ("description")
   1.173 -	("list{}") ("tabular") ("table") ("titlepage")
   1.174 +	("list{}") ("tabular") ("table") ("tabbing") ("titlepage")
   1.175  	("sloppypar") ("ref") ("quotation") ("quote") ("picture")
   1.176  	("eqnarray") ("figure") ("equation") ("abstract") ("array")
   1.177 -	("thebibliography") ("theindex")
   1.178 +	("thebibliography") ("theindex") ("flushleft") ("flushright")
   1.179  ))
   1.180  (defvar user-env-table nil)
   1.181  
   1.182 @@ -117,14 +174,16 @@
   1.183  (defvar user-fontsize-table nil)
   1.184  
   1.185  (setq singlecmd-table
   1.186 -      '(("maketitle") ("sloppy")
   1.187 +      '(("maketitle") ("sloppy") ("protect")
   1.188  	("alpha") ("beta") ("gamma") ("delta") ("epsilon") ("varepsilon")
   1.189  	("zeta") ("eta") ("theta")("vartheta") ("iota") ("kappa")
   1.190  	("lambda") ("mu") ("nu") ("xi") ("pi") ("varpi") ("rho") ("varrho")
   1.191  	("sigma") ("varsigma") ("tau") ("upsilon") ("phi") ("varphi")
   1.192  	("chi") ("psi") ("omega") ("Gamma") ("Delta") ("Theta") ("Lambda")
   1.193  	("Xi") ("Pi") ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")
   1.194 -	("LaTeX") ("TeX") ("item[]")
   1.195 +	("LaTeX") ("TeX") ("item[]") ("appendix") ("hline")
   1.196 +	("rightarrow") ("Rightarrow") ("leftarrow") ("Leftarrow")
   1.197 +	("pagebreak")
   1.198  ))
   1.199  (defvar user-singlecmd-table nil)
   1.200  
   1.201 @@ -134,7 +193,7 @@
   1.202  ;; Do not change this section.
   1.203  ;;;
   1.204  (defvar YaTeX-inhibit-prefix-letter nil
   1.205 -  "Switch which determin whether inhibit yatex.el from defining
   1.206 +  "*Switch which determins whether inhibit yatex.el from defining
   1.207  key sequence \"C-c letter\" or not."
   1.208  )
   1.209  (defvar YaTeX-mode-map nil
   1.210 @@ -178,15 +237,22 @@
   1.211    (setq YaTeX-mode-map (make-sparse-keymap))
   1.212    (setq YaTeX-prefix-map (make-sparse-keymap))
   1.213    (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
   1.214 +  (define-key YaTeX-mode-map "{" 'YaTeX-insert-braces)
   1.215 +  (define-key YaTeX-mode-map "(" '(lambda () (interactive)
   1.216 +				    (insert "()") (backward-char 1)))
   1.217 +  ;(define-key YaTeX-mode-map "[" 'YaTeX-insert-brackets)
   1.218    (define-key YaTeX-mode-map YaTeX-prefix YaTeX-prefix-map)
   1.219    (YaTeX-define-key "t" 'YaTeX-typeset-menu)
   1.220 -  (define-key YaTeX-prefix-map "'" 'YaTeX-prev-error)
   1.221 -  (define-key YaTeX-prefix-map " " 'YaTeX-do-completion)
   1.222 +  (YaTeX-define-key "'" 'YaTeX-prev-error)
   1.223 +  (YaTeX-define-key "^" 'YaTeX-visit-main)
   1.224 +  (YaTeX-define-key "4^" 'YaTeX-visit-main-other-window)
   1.225 +  (YaTeX-define-key " " 'YaTeX-do-completion)
   1.226    (YaTeX-define-key "v" 'YaTeX-version)
   1.227  
   1.228 -  (define-key YaTeX-prefix-map "{" 'YaTeX-insert-braces)
   1.229 -  (define-key YaTeX-prefix-map "}" 'YaTeX-insert-braces-region)
   1.230 +  (YaTeX-define-key "}" 'YaTeX-insert-braces-region)
   1.231 +  (YaTeX-define-key "]" 'YaTeX-insert-brackets-region)
   1.232    (YaTeX-define-key "d" 'YaTeX-insert-dollar)
   1.233 +  (YaTeX-define-key "i" 'YaTeX-fill-item)
   1.234    (YaTeX-define-key
   1.235     "\\" '(lambda () (interactive) (YaTeX-insert-string "$\\backslash$")))
   1.236    (YaTeX-define-begend-region-key "Bd" "document")
   1.237 @@ -216,11 +282,14 @@
   1.238    (YaTeX-define-key "L" 'YaTeX-make-fontsize-region)
   1.239    (YaTeX-define-key "l" 'YaTeX-make-fontsize)
   1.240    (YaTeX-define-key "m" 'YaTeX-make-singlecmd)
   1.241 -  (YaTeX-define-key "g" 'YaTeX-goto-corresponding-environment)
   1.242 -  (YaTeX-define-key "\C-m"
   1.243 +  (YaTeX-define-key "g" 'YaTeX-goto-corresponding-*)
   1.244 +  (YaTeX-define-key "k" 'YaTeX-kill-*)
   1.245 +  (YaTeX-define-key "c" 'YaTeX-change-*)
   1.246 +  (YaTeX-define-key "a" 'YaTeX-make-accent)
   1.247 +  (YaTeX-define-key "n"
   1.248      '(lambda () (interactive) (YaTeX-insert-string "\\\\")))
   1.249    (if (eq system-type 'ms-dos)
   1.250 -      (define-key YaTeX-prefix-map "\^L"
   1.251 +      (define-key YaTeX-prefix-map "L"
   1.252  	'(lambda () (interactive)
   1.253  	   (set-screen-height YaTeX-saved-screen-height) (recenter))))
   1.254  )
   1.255 @@ -240,15 +309,31 @@
   1.256  (defvar fontsize-name "large")		;Initial fontsize completion
   1.257  (defvar single-command "maketitle")	;Initial LaTeX single command
   1.258  (defvar YaTeX-user-table-has-read nil
   1.259 -  "Flag that means whether user completion table has read or not."
   1.260 +  "Flag that means whether user completion table has been read or not."
   1.261  )
   1.262  (defvar YaTeX-user-table-modified nil
   1.263    "Flag that means whether user completion table has modified or not."
   1.264  )
   1.265  (defvar yatex-mode-hook nil
   1.266 -  "List of functions to be called after .tex file is read
   1.267 -and yatex-mode starts.")
   1.268 -
   1.269 +  "*List of functions to be called after .tex file is read
   1.270 +and yatex-mode starts."
   1.271 +)
   1.272 +(defvar YaTeX-kanji-code-alist
   1.273 +  '((1 . *sjis*) (2 . *junet*) (3 . *euc-japan*))
   1.274 +)
   1.275 +(defvar YaTeX-kanji-code (if (eq system-type 'ms-dos) 1 2)
   1.276 +  "*File kanji code used by Japanese TeX."
   1.277 +)
   1.278 +(cond
   1.279 + ((boundp 'MULE)
   1.280 +  (defvar YaTeX-coding-system
   1.281 +    (symbol-value (cdr (assoc YaTeX-kanji-code YaTeX-kanji-code-alist)))
   1.282 +    "File coding system used by Japanese TeX")
   1.283 +  (if (not (eq system-type 'ms-dos))
   1.284 +      (defvar YaTeX-latex-message-code *autoconv*)))
   1.285 + ((boundp 'NEMACS)
   1.286 +  (defvar YaTeX-latex-message-code latex-message-kanji-code))
   1.287 +)
   1.288  ;---------- Produce YaTeX-mode ----------
   1.289  ;;;
   1.290  ;; Major mode definition
   1.291 @@ -257,19 +342,17 @@
   1.292    (interactive)
   1.293    (kill-all-local-variables)
   1.294    (setq major-mode 'YaTeX-mode)
   1.295 -  (setq mode-name "やてふもーど")
   1.296 -  (turn-on-auto-fill)
   1.297 +  (setq mode-name (if YaTeX-japan "やてふ" "YaTeX"))
   1.298    (make-local-variable 'dvi2-command)
   1.299 -  (make-local-variable 'kanji-display-code)
   1.300 -  (make-local-variable 'kanji-fileio-code)
   1.301 -  (if (eq system-type 'ms-dos)
   1.302 -      (setq YaTeX-kanji-code 1)
   1.303 -    (defvar YaTeX-kanji-code 2))
   1.304 -  (setq kanji-display-code YaTeX-kanji-code
   1.305 -	kanji-fileio-code  YaTeX-kanji-code)
   1.306 +  (cond ((boundp 'MULE) ;;1992/12/21 by NIIMI Satoshi.
   1.307 +	 ;; file-coding-system is buffer local variable
   1.308 +	 (set-file-coding-system  YaTeX-coding-system))
   1.309 +  	((boundp 'NEMACS)
   1.310 +	 (make-local-variable 'kanji-fileio-code)
   1.311 +	 (setq kanji-fileio-code YaTeX-kanji-code)))
   1.312    (make-local-variable 'fill-column)
   1.313    (make-local-variable 'fill-prefix)
   1.314 -  (setq fill-column 72
   1.315 +  (setq fill-column YaTeX-fill-column
   1.316  	fill-prefix YaTeX-fill-prefix)
   1.317    (use-local-map YaTeX-mode-map)
   1.318    (if (eq system-type 'ms-dos)
   1.319 @@ -277,7 +360,16 @@
   1.320    (if YaTeX-user-table-has-read nil
   1.321      (YaTeX-read-user-completion-table)
   1.322      (setq YaTeX-user-table-has-read t))
   1.323 -  (run-hooks 'yatex-mode-hook)
   1.324 +  (run-hooks 'text-mode-hook 'yatex-mode-hook)
   1.325 +)
   1.326 +
   1.327 +;---------- Define macro ---------
   1.328 +(defmacro point-beginning-of-line ()
   1.329 +  (save-excursion (beginning-of-line)(point))
   1.330 +)
   1.331 +
   1.332 +(defmacro point-end-of-line ()
   1.333 +  (save-excursion (end-of-line)(point))
   1.334  )
   1.335  
   1.336  ;---------- Define YaTeX-mode functions ----------
   1.337 @@ -289,29 +381,42 @@
   1.338    (if arg
   1.339        (save-excursion
   1.340  	(if (> (point) (mark)) (exchange-point-and-mark))
   1.341 -	(insert "\\begin{" env "}\n")
   1.342 +	(insert "\\begin{" env "}")
   1.343 +	(YaTeX-addin env)
   1.344 +	(insert "\n")
   1.345 +	(indent-relative-maybe)
   1.346  	(exchange-point-and-mark)
   1.347 -	(insert "\\end{" env "}\n"))
   1.348 -    (delete-blank-lines)
   1.349 -    (insert "\\begin{" env "}\n")
   1.350 -    (newline (1+ (* 2 YaTeX-open-lines)))
   1.351 -    (insert "\\end{" env "}\n")
   1.352 -    (previous-line (+ 2 YaTeX-open-lines)))
   1.353 +	(insert "\\end{" env "}\n")
   1.354 +	(indent-relative-maybe))
   1.355 +    ;(delete-blank-lines)
   1.356 +    (let ((i 1))
   1.357 +      (insert "\\begin{" env "}")
   1.358 +      (YaTeX-addin env)
   1.359 +      (insert "\n")
   1.360 +      (indent-relative-maybe)
   1.361 +      ;;(newline (1+ (* 2 YaTeX-open-lines)))
   1.362 +      (while (<= i (1+ (* 2 YaTeX-open-lines)))
   1.363 +	(insert "\n")
   1.364 +	(indent-relative-maybe)
   1.365 +	(setq i (1+ i)))
   1.366 +      (insert "\\end{" env "}")
   1.367 +      (previous-line (+ 1 YaTeX-open-lines)));let i
   1.368 +    (if YaTeX-current-position-register
   1.369 +	(point-to-register YaTeX-current-position-register)))
   1.370  )
   1.371  
   1.372  (defun YaTeX-make-begin-end (arg)
   1.373    "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
   1.374  by completing read.
   1.375   If you invoke this command with universal argument,
   1.376 -\(C-u or ESC-1 is typical prefix to invoke commands with ARG.\)
   1.377 +\(key binding for universal-argument is \\[universal-argument]\)
   1.378  you can put REGION into that environment between \\begin and \\end."
   1.379    (interactive "P")
   1.380    (let*
   1.381        ((mode (if arg " region" ""))
   1.382         (env
   1.383 -	(completing-read
   1.384 -	 (format "Begin environment%s(default %s): " mode env-name)
   1.385 -	 (append user-env-table env-table) nil nil)))
   1.386 +	(YaTeX-read-environment
   1.387 +	 (format "Begin environment%s(default %s): " mode env-name))))
   1.388      (if (string= env "")
   1.389  	(setq env env-name))
   1.390      (setq env-name env)
   1.391 @@ -327,12 +432,10 @@
   1.392    (YaTeX-make-begin-end t)
   1.393  )
   1.394  
   1.395 -(defun YaTeX-end-environment ()
   1.396 -  "Close opening environment"
   1.397 -  (interactive)
   1.398 -  (let ((curp (point))
   1.399 -	s env (nest 0))
   1.400 -    (save-excursion
   1.401 +(defun YaTeX-inner-environment ()
   1.402 +  "Return current inner environment."
   1.403 +  (save-excursion
   1.404 +    (let ((nest 0) s)
   1.405        (while
   1.406  	  (and
   1.407  	   (>= nest 0)
   1.408 @@ -343,14 +446,21 @@
   1.409  	  (setq nest (if (eq (match-beginning 0) (match-beginning 1))
   1.410  			 (1- nest) (1+ nest)))))
   1.411        (if (>= nest 0)
   1.412 -	  (message "No premature environment")
   1.413 +	  nil
   1.414  	(goto-char (match-end 1))
   1.415  	(setq s (point))
   1.416  	(skip-chars-forward "^}")
   1.417 -	(setq env (buffer-substring s (point)))
   1.418 -	;;(recursive-edit)
   1.419 -	))
   1.420 -    (if (not env) nil
   1.421 +	(buffer-substring s (point))
   1.422 +      )))
   1.423 +)
   1.424 +
   1.425 +(defun YaTeX-end-environment ()
   1.426 +  "Close opening environment"
   1.427 +  (interactive)
   1.428 +  (let ((curp (point))
   1.429 +	(env (YaTeX-inner-environment)))
   1.430 +
   1.431 +    (if (not env) (error "No premature environment")
   1.432        (save-excursion
   1.433  	(if (and (re-search-forward "^[^\\%]*\\\\end{.*}" (point-max) t)
   1.434  		 (progn (goto-char (match-beginning 0))
   1.435 @@ -363,12 +473,12 @@
   1.436        (message "")			;Erase (y or n) message.
   1.437        (insert "\\end{" env "}")
   1.438        (setq curp (point))
   1.439 -      (goto-char s)
   1.440 +      (goto-char (match-end 0))
   1.441        (if (pos-visible-in-window-p)
   1.442  	  (sit-for 1)
   1.443  	(message (concat "Matches \\begin{" env
   1.444  			 (format "} at line %d"
   1.445 -				   (count-lines (point-min) s)))))
   1.446 +				   (count-lines (point-min) (match-end 0))))))
   1.447        (goto-char curp))
   1.448      )
   1.449  )
   1.450 @@ -381,7 +491,7 @@
   1.451  
   1.452  	\\addtolength{\\topmargin}{8mm}
   1.453  
   1.454 -which has two argument.  You can produce that sequence by typing...
   1.455 +which has two arguments.  You can produce that sequence by typing...
   1.456  	ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
   1.457  \(by default\)
   1.458  You can complete symbol at LaTeX command and 1st argument."
   1.459 @@ -403,6 +513,8 @@
   1.460  	      (cons (list section-name) user-section-table)
   1.461  	      YaTeX-user-table-modified t))
   1.462      (insert "\\" section-name "{" title "}")
   1.463 +    (if YaTeX-current-position-register
   1.464 +	(point-to-register YaTeX-current-position-register))
   1.465      (let ((j 2))
   1.466        (while (<= j arg)
   1.467  	(insert (concat "{" (read-string (format "Argument %d: " j))))
   1.468 @@ -423,7 +535,7 @@
   1.469    "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
   1.470  If you invoke this command with universal argument, you can put region
   1.471  into {\\xxx } braces.
   1.472 -\(C-u or ESC-1 are default key bindings of universal-argument.\)"
   1.473 +\(key binding for universal-argument is \\[universal-argument]\)"
   1.474    (interactive "P")
   1.475    (let* ((mode (if arg "region" ""))
   1.476  	 (fontsize
   1.477 @@ -445,11 +557,13 @@
   1.478  	  (exchange-point-and-mark)
   1.479  	  (insert "}"))
   1.480        (insert "{\\" fontsize-name " }")
   1.481 +      (if YaTeX-current-position-register
   1.482 +	  (point-to-register YaTeX-current-position-register))
   1.483        (forward-char -1)))
   1.484  )
   1.485  
   1.486  (defun YaTeX-make-fontsize-region ()
   1.487 -  "Call functino:YaTeX-make-fontsize with ARG to specify region mode."
   1.488 +  "Call function:YaTeX-make-fontsize with ARG to specify region mode."
   1.489    (interactive)
   1.490    (YaTeX-make-fontsize t)
   1.491  )
   1.492 @@ -469,6 +583,8 @@
   1.493  	    (cons (list single-command) user-singlecmd-table)
   1.494  	    YaTeX-user-table-modified t))
   1.495    (insert "\\" single-command " ")
   1.496 +  (if YaTeX-current-position-register
   1.497 +      (point-to-register YaTeX-current-position-register))
   1.498  )
   1.499  
   1.500  (defvar YaTeX-completion-begin-regexp "[{\\]"
   1.501 @@ -537,6 +653,7 @@
   1.502    (interactive)
   1.503    (insert
   1.504     (cond
   1.505 +    ((YaTeX-quick-in-environment-p "verbatim") ?\")
   1.506      ((= (preceding-char) ?\\ ) ?\")
   1.507      ((= (preceding-char) ?\( ) ?\")
   1.508      ((= (preceding-char) 32)  "``")
   1.509 @@ -546,14 +663,13 @@
   1.510      (t  "''")
   1.511  )))
   1.512  
   1.513 -
   1.514 -(defun YaTeX-insert-braces-region (beg end)
   1.515 +(defun YaTeX-insert-braces-region (beg end &optional open close)
   1.516    (interactive "r")
   1.517    (save-excursion
   1.518      (goto-char end)
   1.519 -    (insert "}")
   1.520 +    (insert (or close "}"))
   1.521      (goto-char beg)
   1.522 -    (insert "{"))
   1.523 +    (insert (or open "{")))
   1.524  )
   1.525  
   1.526  (defun YaTeX-insert-braces ()
   1.527 @@ -562,6 +678,12 @@
   1.528    (forward-char -1)
   1.529  )
   1.530  
   1.531 +(defun YaTeX-insert-brackets-region (beg end)
   1.532 +  (interactive "r")
   1.533 +  (save-excursion
   1.534 +    (YaTeX-insert-braces-region beg end "[" "]"))
   1.535 +)
   1.536 +
   1.537  (defun YaTeX-insert-dollar ()
   1.538    (interactive)
   1.539    (insert "$$")
   1.540 @@ -576,7 +698,9 @@
   1.541    "Return string of the version of running YaTeX."
   1.542    (interactive)
   1.543    (message
   1.544 -   (concat "Yet Another TeX mode 「野鳥」 Revision "
   1.545 +   (concat "Yet Another tex-mode "
   1.546 +	   (if YaTeX-japan "「野鳥」" "Wild Bird")
   1.547 +	   "Revision "
   1.548  	   YaTeX-revision-number))
   1.549  )
   1.550  
   1.551 @@ -591,9 +715,16 @@
   1.552             (unwind-protect
   1.553                 (progn
   1.554                   ;; Write something in *typesetting* and hack its mode line
   1.555 -                 (set-buffer (process-buffer proc))
   1.556 +		 (if (equal (current-buffer) (process-buffer proc))
   1.557 +		     nil
   1.558 +		   (other-window 1)
   1.559 +		   (switch-to-buffer (process-buffer proc))
   1.560 +		   (goto-char (point-max))
   1.561 +		   (recenter -3)
   1.562 +		   (other-window -1))
   1.563 +		 (set-buffer (process-buffer proc))
   1.564                   (goto-char (point-max))
   1.565 -                 (insert ?\n "jlatex typesetting " mes)
   1.566 +                 (insert ?\n "latex typesetting " mes)
   1.567                   (forward-char -1)
   1.568                   (insert " at "
   1.569                           (substring (current-time-string) 0 -5))
   1.570 @@ -602,6 +733,7 @@
   1.571                   (setq mode-line-process
   1.572                         (concat ": "
   1.573                                 (symbol-name (process-status proc))))
   1.574 +		 (message "latex typesetting done.")
   1.575                   ;; If buffer and mode line will show that the process
   1.576                   ;; is dead, we can delete it now.  Otherwise it
   1.577                   ;; will stay around until M-x list-processes.
   1.578 @@ -618,50 +750,143 @@
   1.579  (defvar YaTeX-typesetting-process nil
   1.580    "Process identifier for jlatex"
   1.581  )
   1.582 +(defvar YaTeX-typeset-buffer "*YaTeX-typesetting*"
   1.583 +  "Process buffer for jlatex")
   1.584  
   1.585 -(defun YaTeX-typeset ()
   1.586 +(defun YaTeX-typeset (command)
   1.587    "Execute jlatex (or other) to LaTeX typeset."
   1.588    (interactive)
   1.589    (if YaTeX-typesetting-process
   1.590     (if (eq (process-status YaTeX-typesetting-process) 'run)
   1.591  	(progn (interrupt-process YaTeX-typesetting-process)
   1.592 -	       (sit-for 1)
   1.593 +	       ;(sit-for 1)
   1.594  	       (delete-process YaTeX-typesetting-process))
   1.595        nil) nil)
   1.596 -;  (compile1 (concat tex-command " " (buffer-name))
   1.597 -;	    "TeX error" "*TeX typesetting*")
   1.598    (setq YaTeX-typesetting-process nil)
   1.599    (if (eq system-type 'ms-dos)				;if MS-DOS
   1.600 -      (with-output-to-temp-buffer "*YaTeX-typesetting*"
   1.601 -	(message (concat "Compiling " (buffer-name) "..."))
   1.602 +      (with-output-to-temp-buffer YaTeX-typeset-buffer
   1.603 +	(message (concat "Typesetting " (buffer-name) "..."))
   1.604  	(YaTeX-put-nonstopmode)
   1.605 -	(basic-save-buffer)
   1.606  	(call-process shell-file-name
   1.607 -		      nil
   1.608 -		      "*YaTeX-typesetting*" nil
   1.609 -		      "/c" (YaTeX-get-latex-command))
   1.610 +		      nil YaTeX-typeset-buffer nil "/c" command)
   1.611  	(YaTeX-remove-nonstopmode))
   1.612      (setq YaTeX-typesetting-process			;if UNIX
   1.613 -	  (with-output-to-temp-buffer "*YaTeX-typesetting*"
   1.614 -	    (basic-save-buffer)
   1.615 -	    (start-process "LaTeX" "*YaTeX-typesetting*" shell-file-name "-c"
   1.616 -			   (YaTeX-get-latex-command))
   1.617 +	  (with-output-to-temp-buffer YaTeX-typeset-buffer
   1.618 +	    (start-process "LaTeX" YaTeX-typeset-buffer shell-file-name "-c"
   1.619 +			   command)
   1.620  	    ))
   1.621      (set-process-sentinel YaTeX-typesetting-process 'YaTeX-typeset-sentinel))
   1.622    (setq current-TeX-buffer (buffer-name))
   1.623    (other-window 1)
   1.624    (use-local-map YaTeX-typesetting-mode-map)
   1.625 -  (set-kanji-process-code YaTeX-kanji-code)
   1.626 +  (setq mode-name "typeset")
   1.627 +  (if YaTeX-typesetting-process ; if process is running (maybe on UNIX)
   1.628 +      (cond ((boundp 'MULE)
   1.629 +	     (set-current-process-coding-system
   1.630 +	      YaTeX-latex-message-code YaTeX-coding-system))
   1.631 +	    ((boundp 'NEMACS)
   1.632 +	     (set-kanji-process-code YaTeX-latex-message-code))))
   1.633    (message "Type SPC to continue.")
   1.634    (goto-char (point-max))
   1.635 -  (sit-for 30)
   1.636 -  (read-char)	;hit any key
   1.637 -  (if (not (= (window-start) (point-min)))
   1.638 -      (while (eq (point) (point-max))
   1.639 -	(scroll-down 1)))
   1.640 +  (sit-for 1)
   1.641 +  (if (eq system-type 'ms-dos) (message "") (read-char));hit any key
   1.642 +  (forward-line -1)
   1.643 +  (recenter -1)
   1.644    (other-window -1)
   1.645  )
   1.646  
   1.647 +(defun YaTeX-typeset-region ()
   1.648 +  "Paste the region to the file `texput.tex' and execute jlatex (or other)
   1.649 +to LaTeX typeset.  The region is specified by the rule:
   1.650 +	(1)If keyword `%#BEGIN' is found in the upper direction from (point).
   1.651 +	  (1-1)if the keyword `%#END' is found after `%#BEGIN',
   1.652 +		->Assume the text between `%#BEGIN' and `%#END' as region.
   1.653 +	  (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN',
   1.654 +		->Assume the text after `%#BEGIN' as region.
   1.655 +	(2)If no `%#BEGIN' usage is found before the (point),
   1.656 +		->Assume the text between current (point) and (mark) as region.
   1.657 +DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing
   1.658 +operation to the region."
   1.659 +  (interactive)
   1.660 +  (save-excursion
   1.661 +    (let*
   1.662 +	((end "") typeout ;Type out message that tells the method of cutting.
   1.663 +	 (buffer (current-buffer)) opoint preamble
   1.664 +	 (region
   1.665 +	  (if (re-search-backward
   1.666 +	       "%#BEGIN" nil t)
   1.667 +	      (progn
   1.668 +		(setq typeout "--- Region from BEGIN to " end "END ---")
   1.669 +		(buffer-substring
   1.670 +		 (match-end 0)
   1.671 +		 (if (re-search-forward "%#END" nil t)
   1.672 +		     (match-beginning 0)
   1.673 +		   (setq end "end of buffer ---")
   1.674 +		   (point-max))))
   1.675 +	    (setq typeout "=== Region from (point) to (mark) ===")
   1.676 +	    (buffer-substring (point) (mark)))))
   1.677 +      (YaTeX-visit-main)
   1.678 +      (setq opoint (point))
   1.679 +      (goto-char (point-min))
   1.680 +      (setq
   1.681 +       preamble
   1.682 +       (if (re-search-forward "^[ 	]*\\\\begin.*{document}" nil t)
   1.683 +	   (buffer-substring (point-min) (match-end 0))
   1.684 +	 (concat "\\documentstyle{" YaTeX-default-document-style "}\n"
   1.685 +		 "\\begin{document}")))
   1.686 +      (goto-char opoint)
   1.687 +      (switch-to-buffer buffer)		;for clarity
   1.688 +      (find-file "texput.tex")
   1.689 +      (erase-buffer)
   1.690 +      (if YaTeX-need-nonstop
   1.691 +	  (insert "\\nonstopmode{}\n"))
   1.692 +      (insert preamble "\n")
   1.693 +      (insert region)
   1.694 +      (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
   1.695 +      (insert "\n\\end{document}\n")
   1.696 +      (basic-save-buffer)
   1.697 +      (kill-buffer (current-buffer))
   1.698 +      (YaTeX-typeset (concat (YaTeX-get-latex-command nil) " texput.tex"))))
   1.699 +)
   1.700 +
   1.701 +(defun YaTeX-typeset-buffer ()
   1.702 +  "Typeset whole buffer."
   1.703 +  (interactive)
   1.704 +  (if (YaTeX-main-file-p) nil
   1.705 +    (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.))))
   1.706 +      (save-excursion		;save excursion of current buffer.
   1.707 +	(YaTeX-visit-main)
   1.708 +	(save-excursion		;save excursion of main .tex buffer
   1.709 +	  (push-mark (point) t)
   1.710 +	  (goto-char (point-min))
   1.711 +	  (if (and (re-search-forward "^[ 	]*\\\\begin{document}" nil t)
   1.712 +		   (re-search-backward "^[ 	]*\\\\includeonly{" nil t))
   1.713 +	      (let*
   1.714 +		  ((b (progn (skip-chars-forward "^{") (point)))
   1.715 +		   (e (progn (skip-chars-forward "^}") (1+ (point))))
   1.716 +		   (s (buffer-substring b e)) c)
   1.717 +		(if (string-match (concat "[{,]" me "[,}]") s)
   1.718 +		    nil
   1.719 +		  (ding)
   1.720 +		  (message
   1.721 +  "File:`%s' is not in includeonly list. A)ppend R)eplace %%)comment? " me)
   1.722 +		  (setq c (read-char))
   1.723 +		  (cond
   1.724 +		   ((= c ?a)
   1.725 +		    (goto-char (1+ b))
   1.726 +		    (insert me (if (string= s "{}") "" ",")))
   1.727 +		   ((= c ?r)
   1.728 +		    (delete-region (1+ b) (1- e)) (insert me))
   1.729 +		   ((= c ?%)
   1.730 +		    (beginning-of-line) (insert "%"))
   1.731 +		   (t nil))
   1.732 +		  (basic-save-buffer))))
   1.733 +	  (exchange-point-and-mark))
   1.734 +	)))
   1.735 +  (YaTeX-save-buffers)
   1.736 +  (YaTeX-typeset (YaTeX-get-latex-command t))
   1.737 +)
   1.738 +
   1.739  (defun YaTeX-preview (preview-command preview-file)
   1.740    "Execute xdvi (or other) to tex-preview."
   1.741    (interactive
   1.742 @@ -687,54 +912,58 @@
   1.743    "Visit previous error.  The reason why not NEXT-error is to
   1.744  avoid make confliction of line numbers by editing."
   1.745    (interactive)
   1.746 -  (setq cur-buf (buffer-name)
   1.747 -	YaTeX-error-line nil)
   1.748 -  (if (null (get-buffer "*YaTeX-typesetting*"))
   1.749 -      (message "There is no output buffer of typesetting.")
   1.750 -    (pop-to-buffer "*YaTeX-typesetting*")
   1.751 -    (if (eq system-type 'ms-dos)
   1.752 -	(if (search-backward latex-dos-emergency-message nil t)
   1.753 -	    (progn (goto-char (point-max))
   1.754 -		   (setq error-regexp latex-error-regexp))
   1.755 +  (let ((cur-buf (buffer-name))
   1.756 +	YaTeX-error-line error-buffer)
   1.757 +    (if (null (get-buffer YaTeX-typeset-buffer))
   1.758 +	(message "There is no output buffer of typesetting.")
   1.759 +      (pop-to-buffer YaTeX-typeset-buffer)
   1.760 +      (if (eq system-type 'ms-dos)
   1.761 +	  (if (search-backward latex-dos-emergency-message nil t)
   1.762 +	      (progn (goto-char (point-max))
   1.763 +		     (setq error-regexp latex-error-regexp))
   1.764 +	    (beginning-of-line)
   1.765 +	    (forward-char -1)
   1.766 +	    (setq error-regexp latex-warning-regexp))
   1.767 +	(if YaTeX-typesetting-process      ; if jlatex on UNIX
   1.768 +	    (if (eq (process-status YaTeX-typesetting-process) 'run)
   1.769 +		(progn
   1.770 +		  (goto-char (point-max))
   1.771 +		  (setq error-regexp latex-error-regexp)))
   1.772  	  (beginning-of-line)
   1.773 -	  (forward-char -1)
   1.774 -	  (setq error-regexp latex-warning-regexp))
   1.775 -      (if YaTeX-typesetting-process      ; if jlatex on UNIX
   1.776 -	  (if (eq (process-status YaTeX-typesetting-process) 'run)
   1.777 -	      (progn
   1.778 -		(goto-char (point-max))
   1.779 -		(setq error-regexp latex-error-regexp)))
   1.780 -	(beginning-of-line)
   1.781 -	(setq error-regexp latex-warning-regexp)))
   1.782 -    (if (re-search-backward error-regexp nil t)
   1.783 -	(save-restriction
   1.784 -	  (set-mark-command nil)
   1.785 -	  (end-of-line)
   1.786 -	  (narrow-to-region (point) (mark))
   1.787 -	  (goto-char (point-min))
   1.788 -	  (re-search-forward "[0-9]")
   1.789 -	  (forward-char -1)
   1.790 -	  (set-mark (point))
   1.791 -	  (skip-chars-forward "0-9")
   1.792 -	  (narrow-to-region (point) (mark))
   1.793 -	  (goto-char (point-min))
   1.794 -	  (setq YaTeX-error-line (read (current-buffer))))
   1.795 -      (message "No more error on %s" cur-buf)
   1.796 -      (ding)
   1.797 -      )
   1.798 -    (other-window -1)
   1.799 -    (switch-to-buffer cur-buf)
   1.800 -    (if (null YaTeX-error-line)
   1.801 -	nil
   1.802 -      (goto-line YaTeX-error-line)
   1.803 -      (message "latex error or warning at line: %d" YaTeX-error-line)
   1.804 -      (other-window 1)
   1.805 -      (skip-chars-backward "[0-9]")
   1.806 -      (recenter (/ (window-height) 2))
   1.807 -      (sit-for 3)
   1.808 -      (forward-line -1)
   1.809 +	  (setq error-regexp latex-warning-regexp)))
   1.810 +      (if (re-search-backward error-regexp nil t)
   1.811 +	  (save-restriction
   1.812 +	    (set-mark-command nil)
   1.813 +	    (end-of-line)
   1.814 +	    (narrow-to-region (point) (mark))
   1.815 +	    (goto-char (point-min))
   1.816 +	    (re-search-forward "[0-9]")
   1.817 +	    (forward-char -1)
   1.818 +	    (set-mark (point))
   1.819 +	    (skip-chars-forward "0-9")
   1.820 +	    (narrow-to-region (point) (mark))
   1.821 +	    (goto-char (point-min))
   1.822 +	    (setq YaTeX-error-line (read (current-buffer))))
   1.823 +	(message "No more error on %s" cur-buf)
   1.824 +	(ding)
   1.825 +	)
   1.826 +      (setq error-buffer (YaTeX-get-error-file cur-buf))
   1.827        (other-window -1)
   1.828 -      ))
   1.829 +      (switch-to-buffer cur-buf)
   1.830 +      (if (null YaTeX-error-line)
   1.831 +	  nil
   1.832 +	;; if warning or error found
   1.833 +	(YaTeX-switch-to-buffer error-buffer)
   1.834 +	(goto-line YaTeX-error-line)
   1.835 +	(message "latex error or warning in '%s' at line: %d"
   1.836 +		 error-buffer YaTeX-error-line)
   1.837 +	(other-window 1)
   1.838 +	(skip-chars-backward "[0-9]")
   1.839 +	(recenter (/ (window-height) 2))
   1.840 +	(sit-for 3)
   1.841 +	(forward-line -1)
   1.842 +	(other-window -1)
   1.843 +	)))
   1.844  )
   1.845  
   1.846  (defun YaTeX-jump-error-line ()
   1.847 @@ -747,23 +976,40 @@
   1.848        (goto-char (match-beginning 0))
   1.849        (re-search-forward "[1-9][0-9]*" end t)
   1.850        (save-restriction
   1.851 -	(narrow-to-region (match-beginning 0) (match-end 0))
   1.852 -	(goto-char (point-min))
   1.853 -	(let ((error-line (read (current-buffer))))
   1.854 +	(let ((error-line
   1.855 +	       (string-to-int (buffer-substring (match-beginning 0)
   1.856 +						(match-end 0))))
   1.857 +	      (error-file (YaTeX-get-error-file current-TeX-buffer)))
   1.858 +	  (goto-char (match-beginning 0))
   1.859  	  (other-window -1)
   1.860 -	  (switch-to-buffer current-TeX-buffer)
   1.861 +	  (message "errors in %s" error-file)
   1.862 +	  ;(switch-to-buffer current-TeX-buffer)
   1.863 +	  (if (not (YaTeX-switch-to-buffer error-file))
   1.864 +	      (error "%s is not found in this directory."))
   1.865  	  (goto-line error-line)))))
   1.866  )
   1.867  
   1.868  (defun YaTeX-view-error ()
   1.869    (interactive)
   1.870 -  (other-window 1)
   1.871 -  (goto-char (point-max))
   1.872 -  (other-window -1)
   1.873 +  (if (null (get-buffer YaTeX-typeset-buffer))
   1.874 +      (message "No typeset buffer found.")
   1.875 +    (pop-to-buffer YaTeX-typeset-buffer)
   1.876 +    (goto-char (point-max))
   1.877 +    (recenter -1)
   1.878 +    (other-window -1))
   1.879  )
   1.880  
   1.881 +(defun YaTeX-get-error-file (default)
   1.882 +  "Get current processing file by tex message."
   1.883 +  (let (file-name)
   1.884 +    (save-excursion
   1.885 +      (if (re-search-backward "([-A-Z_a-z0-9]+.tex" (point-min) t)
   1.886 +	  (buffer-substring (1+ (match-beginning 0)) (match-end 0))
   1.887 +	default)))
   1.888 +)
   1.889 +      
   1.890  (defun YaTeX-put-nonstopmode ()
   1.891 -  (if (boundp 'YaTeX-need-nonstop)
   1.892 +  (if YaTeX-need-nonstop
   1.893        (if (re-search-backward "\\nonstopmode{}" (point-min) t)
   1.894  	  nil                    ;if already written in text then do nothing
   1.895  	(save-excursion
   1.896 @@ -773,7 +1019,7 @@
   1.897  )
   1.898  
   1.899  (defun YaTeX-remove-nonstopmode ()
   1.900 -  (if (boundp 'YaTeX-need-nonstop) ;for speed
   1.901 +  (if YaTeX-need-nonstop ;for speed
   1.902        (save-excursion
   1.903  	(goto-char (point-min))
   1.904  	(forward-line 1)
   1.905 @@ -783,21 +1029,23 @@
   1.906  	(widen)))
   1.907  )
   1.908  
   1.909 -(defun YaTeX-typeset-menu ()
   1.910 +(defun YaTeX-typeset-menu (arg)
   1.911    "Typeset, preview, visit error and miscellaneous convinient menu."
   1.912 -  (interactive)
   1.913 -  (message "J)latex P)review V)iewerror")
   1.914 +  (interactive "P")
   1.915 +  (message "J)latex R)egion P)review V)iewerror L)pr")
   1.916    (let ((c (read-char)))
   1.917      (cond
   1.918 -     ((= c ?j) (YaTeX-typeset))
   1.919 +     ((= c ?j) (YaTeX-typeset-buffer))
   1.920 +     ((= c ?r) (YaTeX-typeset-region))
   1.921       ((= c ?p) (call-interactively 'YaTeX-preview))
   1.922       ((= c ?v) (YaTeX-view-error))
   1.923 +     ((= c ?l) (YaTeX-lpr arg))
   1.924       ((= c ?b) (YaTeX-insert-string "\\"))))
   1.925  )
   1.926  
   1.927  (defun YaTeX-get-preview-file-name ()
   1.928    "Get file name to preview by inquiring YaTeX-get-latex-command"
   1.929 -  (let* ((latex-cmd (YaTeX-get-latex-command))
   1.930 +  (let* ((latex-cmd (YaTeX-get-latex-command t))
   1.931  	 (fname (substring latex-cmd (1+ (rindex latex-cmd ? ))))
   1.932  	 (period))
   1.933      (if (eq fname "")
   1.934 @@ -807,7 +1055,7 @@
   1.935        ))
   1.936  )
   1.937  
   1.938 -(defun YaTeX-get-latex-command ()
   1.939 +(defun YaTeX-get-latex-command (switch)
   1.940    "Specify the latex-command name and its argument.
   1.941  If there is a line which begins by string: \"%#!\", the following
   1.942  strings are assumed to be the latex-command and arguments.  The
   1.943 @@ -816,69 +1064,199 @@
   1.944  and if you write \"%#!jlatex\" in the beginning of certain line.
   1.945  	\"jlatex \" (buffer-name)
   1.946  will be the latex-command,
   1.947 -and you write \"%#!jlatex main.tex\"
   1.948 +and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
   1.949 +is t, then
   1.950  	\"jlatex main.tex\"
   1.951  will be given to the shell."
   1.952    (let*
   1.953        ((default-command
   1.954 -	 (concat tex-command " " (buffer-name)))) ;default value
   1.955 +	 (concat tex-command " "
   1.956 +		 (if switch (buffer-name) ""))));default value
   1.957      (save-excursion
   1.958        (goto-char (point-min))
   1.959        (if (null (re-search-forward "^%#!" (point-max) t))
   1.960  	  default-command
   1.961  	(skip-chars-forward "%#! 	")
   1.962 -	(if (eolp)1z
   1.963 +	(if (eolp)
   1.964  	    default-command
   1.965  	  (let ((s (point)))
   1.966  	    (skip-chars-forward "A-z")	;Skip command name
   1.967  	    ;(setq YaTeX-latex-command (buffer-substring s (point)))
   1.968 -	    (if (eolp)			;Only change command name
   1.969 -		(concat (buffer-substring s (point)) " " (buffer-name))
   1.970 -	      (end-of-line)		   ;Change entire command name
   1.971 -	      (buffer-substring s (point)) ;including arguments.
   1.972 +	    (cond
   1.973 +	     ((null switch)
   1.974 +	      (buffer-substring s (point)))
   1.975 +	     ((eolp)			 ;Only return command name
   1.976 +	      (concat (buffer-substring s (point)) " " (buffer-name)))
   1.977 +	     (t(end-of-line)		   ;Change entire command name
   1.978 +	       (buffer-substring s (point))) ;including arguments.
   1.979  	    ))
   1.980  	))))
   1.981  )
   1.982  
   1.983 +(defun YaTeX-get-builtin (key)
   1.984 +  "Read source built-in command of %# usage."
   1.985 +  (save-excursion
   1.986 +    (goto-char (point-min))
   1.987 +    (if (and (search-forward (concat "%#" key) nil t)
   1.988 +	     (not (eolp)))
   1.989 +	(buffer-substring
   1.990 +	 (progn (skip-chars-forward " 	" (point-end-of-line))(point))
   1.991 +	 (point-end-of-line))
   1.992 +      nil))
   1.993 +)
   1.994 +
   1.995  (defun YaTeX-goto-corresponding-environment ()
   1.996    "Go to corresponding begin/end enclosure."
   1.997    (interactive)
   1.998 -  (if (not (YaTeX-on-begin-end-p))
   1.999 -      (error "No environment declaration"))
  1.1000 -  (let ((p  (match-end 0) env)
  1.1001 -	(m0 (match-beginning 0))
  1.1002 -	(m1 (match-beginning 1))
  1.1003 -	(m2 (match-beginning 2)))
  1.1004 -    (if (not
  1.1005 -	 (save-excursion
  1.1006 -	   (goto-char p)
  1.1007 -	   (search-forward "}" (point-end-of-line) t)))
  1.1008 -	(error "Unterminated brackets for begin/end"))
  1.1009 -    (setq env (buffer-substring p (match-beginning 0))) ;get current env
  1.1010 -    (cond
  1.1011 -     ((equal m0 m1)		;if begin{xxx}
  1.1012 -      (search-forward (concat "end{" env "}")))
  1.1013 -     ((equal m0 m2)		;if end{xxx}
  1.1014 -      (search-backward (concat "begin{" env "}")))
  1.1015 -     )
  1.1016 -    (beginning-of-line)
  1.1017 -    );let
  1.1018 +  (if (not (YaTeX-on-begin-end-p)) nil
  1.1019 +    (let ((p  (match-end 0)) env (nest 0) regexp re-s
  1.1020 +	  (m0 (match-beginning 0))
  1.1021 +	  (m1 (match-beginning 1))
  1.1022 +	  (m2 (match-beginning 2)))
  1.1023 +      (if (not
  1.1024 +	   (save-excursion
  1.1025 +	     (goto-char p)
  1.1026 +	     (search-forward "}" (point-end-of-line) t)))
  1.1027 +	  (error "Unterminated brackets for begin/end"))
  1.1028 +      (setq env (buffer-substring p (match-beginning 0))) ;get current env
  1.1029 +      (if (cond
  1.1030 +	   ((equal m0 m1)		;if begin{xxx}
  1.1031 +	    (setq regexp (concat "\\(\\\\end{" env "}\\)\\|"
  1.1032 +				 "\\(\\\\begin{" env "}\\)"))
  1.1033 +	    (fset re-s 're-search-forward))
  1.1034 +	   ((equal m0 m2)		;if end{xxx}
  1.1035 +	    (setq regexp (concat "\\(\\\\begin{" env "}\\)\\|"
  1.1036 +				 "\\(\\\\end{" env "}\\)"))
  1.1037 +	    (fset re-s 're-search-backward))
  1.1038 +	   (error "Corresponding environment not found."))
  1.1039 +	(while (and (>= nest 0) (funcall re-s regexp nil t))
  1.1040 +	  (if (eq (match-beginning 0) m0) nil
  1.1041 +	    (setq nest (if (eq (match-beginning 0) (match-beginning 1))
  1.1042 +			   (1- nest) (1+ nest))))))
  1.1043 +      (beginning-of-line));let
  1.1044 +    t); if on begin/end line
  1.1045  )
  1.1046  
  1.1047 -(defun YaTeX-comment-region ()
  1.1048 +(defun YaTeX-goto-corresponding-file ()
  1.1049 +  "Visit or switch buffer of corresponding file, looking at \\input or
  1.1050 +\\include or \includeonly on current line."
  1.1051 +  (if (not (YaTeX-on-includes-p)) nil
  1.1052 +    (beginning-of-line)
  1.1053 +    (skip-chars-forward "^{")
  1.1054 +    (let ((input-file
  1.1055 +	   (concat
  1.1056 +	    (buffer-substring (1+ (point))
  1.1057 +			      (progn (skip-chars-forward "^ ,}") (point)))
  1.1058 +	    ".tex")))
  1.1059 +      (YaTeX-switch-to-buffer input-file)
  1.1060 +      )
  1.1061 +    t);if on \input or \include line.
  1.1062 +)
  1.1063 +
  1.1064 +(defun YaTeX-goto-corresponding-BEGIN-END ()
  1.1065 +  (if (not (YaTeX-on-BEGIN-END-p)) nil
  1.1066 +    (if (cond
  1.1067 +	 ((equal (match-beginning 0) (match-beginning 1)) ;if on %#BEGIN
  1.1068 +	  (not (search-forward "%#END" nil t)))
  1.1069 +	 (t ; if on %#END
  1.1070 +	  (not (search-backward "%#BEGIN" nil t))))
  1.1071 +	(error "Corresponding %#BEGIN/END not found."))
  1.1072 +    (beginning-of-line)
  1.1073 +    t)
  1.1074 +)
  1.1075 +
  1.1076 +(defun YaTeX-switch-to-buffer (file)
  1.1077 +  "Switch to buffer if buffer exists, find file if not."
  1.1078 +  (interactive "Fswitch to file: ")
  1.1079 +  (if (get-buffer file)
  1.1080 +      (progn (switch-to-buffer file) t)
  1.1081 +    (if (file-exists-p file)
  1.1082 +	(progn (find-file file) t)
  1.1083 +      (message "%s was not found in this directory." file)
  1.1084 +      nil))
  1.1085 +)
  1.1086 +
  1.1087 +(defun YaTeX-switch-to-buffer-other-window (file)
  1.1088 +  "Switch to buffer if buffer exists, find file if not."
  1.1089 +  (interactive "Fswitch to file: ")
  1.1090 +  (if (get-buffer file)
  1.1091 +      (progn (switch-to-buffer-other-window file) t)
  1.1092 +    (if (file-exists-p file)
  1.1093 +	(progn (find-file-other-window file) t)
  1.1094 +      (message "%s was not found in this directory." file)
  1.1095 +      nil))
  1.1096 +)
  1.1097 +
  1.1098 +(defmacro YaTeX-main-file-p ()
  1.1099 +  "Return if current buffer is main LaTeX source."
  1.1100 +  (string-match (concat "^" (YaTeX-get-preview-file-name) ".tex")(buffer-name))
  1.1101 +)
  1.1102 +
  1.1103 +(defun YaTeX-visit-main ()
  1.1104 +  "Switch to buffer main LaTeX source."
  1.1105 +  (interactive)
  1.1106 +  (let ((main-file (YaTeX-get-preview-file-name)))
  1.1107 +    (if (string-match (concat "^" main-file ".tex") (buffer-name))
  1.1108 +	(message "I think this is main LaTeX source.")
  1.1109 +      (YaTeX-switch-to-buffer (concat main-file ".tex"))))
  1.1110 +  nil
  1.1111 +)
  1.1112 +
  1.1113 +(defun YaTeX-visit-main-other-window ()
  1.1114 +  "Switch to buffer main LaTeX source in other window."
  1.1115 +  (interactive)
  1.1116 +  (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
  1.1117 +      (YaTeX-switch-to-buffer-other-window
  1.1118 +       (concat (YaTeX-get-preview-file-name) ".tex")))
  1.1119 +)
  1.1120 +
  1.1121 +(defun YaTeX-on-begin-end-p ()
  1.1122 +  (save-excursion
  1.1123 +    (beginning-of-line)
  1.1124 +    (re-search-forward
  1.1125 +     "\\(\\\\begin{\\)\\|\\(\\\\end{\\)" (point-end-of-line) t))
  1.1126 +)
  1.1127 +(defun YaTeX-on-includes-p ()
  1.1128 +  (save-excursion
  1.1129 +    (beginning-of-line)
  1.1130 +    (re-search-forward "\\(\\(include.*\\)\\|\\(input\\)\\){.*}"
  1.1131 +		       (point-end-of-line) t))
  1.1132 +)
  1.1133 +(defun YaTeX-on-BEGIN-END-p ()
  1.1134 +  (save-excursion
  1.1135 +    (let ((case-fold-sea nil))
  1.1136 +      (beginning-of-line)
  1.1137 +      (re-search-forward "\\(%#BEGIN\\)\\|\\(%#END\\)" (point-end-of-line) t)))
  1.1138 +)
  1.1139 +(defun YaTeX-goto-corresponding-* ()
  1.1140 +  "Parse current line and call suitable function."
  1.1141 +  (interactive)
  1.1142 +  (cond
  1.1143 +   ((YaTeX-goto-corresponding-environment))
  1.1144 +   ((YaTeX-goto-corresponding-file))
  1.1145 +   ((YaTeX-goto-corresponding-BEGIN-END))
  1.1146 +   (t (message "I don't know where to go.")))
  1.1147 +)
  1.1148 +
  1.1149 +(defun YaTeX-comment-region (alt-prefix)
  1.1150    "Comment out region by '%'. If you call this function on the 'begin{}' or
  1.1151  'end{}' line, it comments out whole environment"
  1.1152 -  (interactive)
  1.1153 +  (interactive "P")
  1.1154    (if (not (YaTeX-on-begin-end-p))
  1.1155 -      (comment-region YaTeX-comment-prefix)
  1.1156 +      (comment-region
  1.1157 +       (if alt-prefix
  1.1158 +	   (read-string "Insert prefix: ")
  1.1159 +	 YaTeX-comment-prefix))
  1.1160      (YaTeX-comment-uncomment-env 'comment-region))
  1.1161  )
  1.1162  
  1.1163 -(defun YaTeX-uncomment-region ()
  1.1164 +(defun YaTeX-uncomment-region (alt-prefix)
  1.1165    "Uncomment out region by '%'."
  1.1166 -  (interactive)
  1.1167 +  (interactive "P")
  1.1168    (if (not (YaTeX-on-begin-end-p))
  1.1169 -      (uncomment-region YaTeX-comment-prefix)
  1.1170 +      (uncomment-region
  1.1171 +       (if alt-prefix (read-string "Remove prefix: ")
  1.1172 +	 YaTeX-comment-prefix))
  1.1173      (YaTeX-comment-uncomment-env 'uncomment-region))
  1.1174  )
  1.1175  
  1.1176 @@ -888,11 +1266,10 @@
  1.1177      (if (eq (match-beginning 0) (match-beginning 2)) ; if on the '\end{}' line
  1.1178  	(YaTeX-goto-corresponding-environment)) ; goto '\begin{}' line
  1.1179      (beginning-of-line)
  1.1180 -    (push-mark)
  1.1181 +    (push-mark (point) t)
  1.1182      (YaTeX-goto-corresponding-environment)
  1.1183      (forward-line 1)
  1.1184      (funcall func YaTeX-comment-prefix t) ; t makes uncomment once
  1.1185 -    (pop-mark)
  1.1186      )
  1.1187  )
  1.1188  
  1.1189 @@ -900,12 +1277,6 @@
  1.1190    "Not implemented yet."
  1.1191  )
  1.1192  
  1.1193 -(defun YaTeX-on-begin-end-p ()
  1.1194 -  (save-excursion
  1.1195 -    (beginning-of-line)
  1.1196 -    (re-search-forward "\\(begin{\\)\\|\\(end{\\)" (point-end-of-line) t))
  1.1197 -)
  1.1198 -
  1.1199  (defun YaTeX-comment-paragraph ()
  1.1200    "Comment out current paragraph."
  1.1201    (interactive)
  1.1202 @@ -949,6 +1320,259 @@
  1.1203      (if once (end-of-line)))
  1.1204  )
  1.1205  
  1.1206 +(defun YaTeX-kill-some-pairs (predicate gofunc)
  1.1207 +  "Kill some matching pair."
  1.1208 +  (interactive)
  1.1209 +  (if ;(not (YaTeX-on-begin-end-p)) nil
  1.1210 +      (not (funcall predicate)) nil
  1.1211 +    (save-excursion
  1.1212 +      (push-mark (point) t)
  1.1213 +      ;(YaTeX-goto-corresponding-environment)
  1.1214 +      (funcall gofunc)
  1.1215 +      (beginning-of-line)
  1.1216 +      (kill-line 1)
  1.1217 +      (exchange-point-and-mark)
  1.1218 +      (beginning-of-line)
  1.1219 +      (kill-line 1)
  1.1220 +    t))
  1.1221 +)
  1.1222 +
  1.1223 +(defun YaTeX-read-environment (prompt)
  1.1224 +  "Read the LaTeX environment name with completion."
  1.1225 +  (let ((env
  1.1226 +	 (completing-read prompt (append user-env-table env-table) nil nil)))
  1.1227 +    (if (not (assoc env (append user-env-table env-table)))
  1.1228 +	(setq user-env-table (cons (list env) user-env-table)
  1.1229 +	      YaTeX-user-table-modified t))
  1.1230 +  env)
  1.1231 +)
  1.1232 +
  1.1233 +(defun YaTeX-change-environment ()
  1.1234 +  "Change the name of environment."
  1.1235 +  (interactive)
  1.1236 +  (if (not (YaTeX-on-begin-end-p)) nil
  1.1237 +    (save-excursion
  1.1238 +      (let (p env)
  1.1239 +	(beginning-of-line)
  1.1240 +	(skip-chars-forward "^{")
  1.1241 +	(forward-char 1)
  1.1242 +	(setq p (point))
  1.1243 +	(skip-chars-forward "^}")
  1.1244 +	(setq env (buffer-substring p (point)))
  1.1245 +	(beginning-of-line)
  1.1246 +	(set-mark-command nil)
  1.1247 +	(YaTeX-goto-corresponding-environment)
  1.1248 +	(setq newenv (YaTeX-read-environment
  1.1249 +		      (format "Change environment `%s' to: " env)))
  1.1250 +	(if (string= newenv "")
  1.1251 +	    (message "Change environment cancelled.")
  1.1252 +	  (search-forward (concat "{" env) (point-end-of-line) t)
  1.1253 +	  (replace-match (concat "{" newenv))
  1.1254 +	  (exchange-point-and-mark)
  1.1255 +	  (search-forward (concat "{" env) (point-end-of-line) t)
  1.1256 +	  (replace-match (concat "{" newenv)))
  1.1257 +	t)))
  1.1258 +)
  1.1259 +
  1.1260 +(defun YaTeX-kill-* ()
  1.1261 +  "Parse current line and call suitable function."
  1.1262 +  (interactive)
  1.1263 +  (cond
  1.1264 +   ((YaTeX-kill-some-pairs 'YaTeX-on-begin-end-p
  1.1265 +			   'YaTeX-goto-corresponding-environment))
  1.1266 +   ((YaTeX-kill-some-pairs 'YaTeX-on-BEGIN-END-p
  1.1267 +			   'YaTeX-goto-corresponding-BEGIN-END))
  1.1268 +   (t (message "I don't know what to kill.")))
  1.1269 +)
  1.1270 +
  1.1271 +(defun YaTeX-change-* ()
  1.1272 +  "Parse current line and call suitable function."
  1.1273 +  (interactive)
  1.1274 +  (cond
  1.1275 +   ((YaTeX-change-environment))
  1.1276 +   (t (message "I don't know what to change.")))
  1.1277 +)
  1.1278 +
  1.1279 +(defun YaTeX-addin (name)
  1.1280 +  "Check availability of addin function and call it if exists."
  1.1281 +  (if (fboundp (intern-soft (concat "YaTeX:" name)))
  1.1282 +      (funcall (intern (concat "YaTeX:" name))))
  1.1283 +)
  1.1284 +
  1.1285 +(defun YaTeX-in-environment-p (env)
  1.1286 +  "Return if current LaTeX environment is ENV."
  1.1287 +  (let ((cur-env (YaTeX-inner-environment)) p)
  1.1288 +    (cond
  1.1289 +     ((atom env) (equal env cur-env))
  1.1290 +     ((listp env)
  1.1291 +      (while (and env (not p))
  1.1292 +	(setq p (equal (car env) cur-env))
  1.1293 +	(setq env (cdr env)))
  1.1294 +      p)))
  1.1295 +)
  1.1296 +
  1.1297 +(defun YaTeX-quick-in-environment-p (env)
  1.1298 +  "Check quickly but unsure if current environment is ENV."
  1.1299 +  (let ((p (point))q)
  1.1300 +    (while (and (not q) (search-backward (concat "\\begin{" env "}")nil t))
  1.1301 +      ;;(goto-char (match-beginning 0))
  1.1302 +      (if (search-backward "%" (point-beginning-of-line) t) nil
  1.1303 +	(setq q t)))
  1.1304 +    (if q (setq q (not (re-search-forward
  1.1305 +			(concat "^[ 	]*\\\\end{" env "}") p t))))
  1.1306 +    (goto-char p)
  1.1307 +    q)
  1.1308 +)
  1.1309 +
  1.1310 +(defun YaTeX-remove-trailing-comment ()
  1.1311 +  "Remove trailing comment in current line."
  1.1312 +  (if (re-search-forward "[^\\\\]\\(%\\)" (point-end-of-line) t)
  1.1313 +      (delete-region (match-beginning 1) (point-end-of-line)))
  1.1314 +)
  1.1315 +
  1.1316 +(defun YaTeX-fill-item ()
  1.1317 +  "Fill item in itemize environment."
  1.1318 +  (interactive)
  1.1319 +  (save-excursion
  1.1320 +      (let* ((p (point))
  1.1321 +	     (bndry (prog2 (search-backward "\\begin{" nil t) (point)
  1.1322 +			   (goto-char p)))
  1.1323 +	     (item-term "\\(^$\\)\\|\\(\\\\item\\)\\|\\(\\\\end\\)")
  1.1324 +	     fill-prefix start s2 col)
  1.1325 +	(end-of-line)
  1.1326 +	(if (not (re-search-backward "\\\\item" bndry t))
  1.1327 +	    (error "\\item not found."))
  1.1328 +	(skip-chars-forward "^ 	" (point-end-of-line))
  1.1329 +	(skip-chars-forward " 	" (point-end-of-line))
  1.1330 +	(if (not (eolp))  nil
  1.1331 +	  (forward-line 1)
  1.1332 +	  (skip-chars-forward "	 "))
  1.1333 +	(setq start (point-beginning-of-line))
  1.1334 +	(setq col (current-column))
  1.1335 +	(YaTeX-remove-trailing-comment)	;should restrict to NTT-jTeX?
  1.1336 +	(forward-line 1)
  1.1337 +	(skip-chars-forward " 	")
  1.1338 +	(if (looking-at item-term) nil
  1.1339 +	  (delete-region (point) (point-beginning-of-line))
  1.1340 +	  (indent-to col)
  1.1341 +	  (setq s2 (point))
  1.1342 +	  (setq fill-prefix
  1.1343 +		(buffer-substring (point-beginning-of-line)(point)))
  1.1344 +	  (YaTeX-remove-trailing-comment);should restrict to NTT-jTeX?
  1.1345 +	  (re-search-forward item-term nil 1)
  1.1346 +	  (beginning-of-line)
  1.1347 +	  (push-mark (point) t)
  1.1348 +	  (while (> (point) s2)
  1.1349 +	    (forward-line -1)
  1.1350 +	    (skip-chars-forward "	 ")
  1.1351 +	    (delete-region (point) (point-beginning-of-line))
  1.1352 +	    (YaTeX-remove-trailing-comment))
  1.1353 +	  (fill-region-as-paragraph start (mark))
  1.1354 +	  (if NTT-jTeX
  1.1355 +	      (while (progn(forward-line -1)(end-of-line) (> (point) start))
  1.1356 +		(insert ?%)))
  1.1357 +	  (pop-mark))
  1.1358 +	))
  1.1359 +)
  1.1360 +
  1.1361 +(defun YaTeX-fill-* ()
  1.1362 +  "Fill paragraph according to its condition."
  1.1363 +  (interactive)
  1.1364 +  (cond
  1.1365 +   ((YaTeX-fill-item))
  1.1366 +   )
  1.1367 +)
  1.1368 +
  1.1369 +(defun YaTeX-save-buffers ()
  1.1370 +  "Save buffers with `.tex' extension."
  1.1371 +  (basic-save-buffer)
  1.1372 +  (save-excursion
  1.1373 +    (mapcar '(lambda (buf)
  1.1374 +	       (set-buffer buf)
  1.1375 +	       (if (and (buffer-file-name buf)
  1.1376 +			(string-match "\\.tex$" (buffer-file-name buf))
  1.1377 +			(buffer-modified-p buf)
  1.1378 +			(y-or-n-p (format "Save %s" (buffer-name buf))))
  1.1379 +		   (save-buffer buf)))
  1.1380 +	    (buffer-list)))
  1.1381 +)
  1.1382 +
  1.1383 +(defun YaTeX-read-accent-char (x)
  1.1384 +  "Read char in accent braces."
  1.1385 +  (let ((c (read-char)))
  1.1386 +    (concat
  1.1387 +     (if (and (or (= c ?i) (= c ?j))
  1.1388 +	      (not (string-match (regexp-quote x) "cdb")))
  1.1389 +	 "\\" "")
  1.1390 +     (char-to-string c)))
  1.1391 +)
  1.1392 +
  1.1393 +(defun YaTeX-make-accent ()
  1.1394 +  "Make accent usage."
  1.1395 +  (interactive)
  1.1396 +  (message "1:` 2:' 3:^ 4:\" 5:~ 6:= 7:. u v H t c d b")
  1.1397 +  (let ((c (read-char))(case-fold-search nil))
  1.1398 +    (setq c (cond ((and (> c ?0) (< c ?8))
  1.1399 +		   (substring "`'^\"~=." (1- (- c ?0)) (- c ?0)))
  1.1400 +		  ((= c ?h) "H")
  1.1401 +		  (t (char-to-string c))))
  1.1402 +    (if (not (string-match c "`'^\"~=.uvHtcdb")) nil
  1.1403 +      (insert "\\" c "{}")
  1.1404 +      (backward-char 1)
  1.1405 +      (insert (YaTeX-read-accent-char c))
  1.1406 +      (if (string= c "t") (insert (YaTeX-read-accent-char c)))
  1.1407 +      (forward-char 1)))
  1.1408 +)
  1.1409 +
  1.1410 +(defun YaTeX-replace-format (string format repl)
  1.1411 +  "In STRING, replace first appearance of FORMAT to REPL as if
  1.1412 +function `format' does.  FORMAT does not contain `%'"
  1.1413 +  (let ((beg (or (string-match (concat "^\\(%" format "\\)") string)
  1.1414 +		 (string-match (concat "[^%]\\(%" format "\\)") string)))
  1.1415 +	(len (length format)))
  1.1416 +    (if (null beg) string ;no conversion
  1.1417 +      (concat
  1.1418 +       (substring string 0 (match-beginning 1)) repl
  1.1419 +       (substring string (match-end 1)))))
  1.1420 +)
  1.1421 +(defun YaTeX-lpr (arg)
  1.1422 +  "Print out.  If prefix arg ARG is non nil, call print driver without
  1.1423 +page range description."
  1.1424 +  (interactive "P")
  1.1425 +  (let*(from to (cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format)))
  1.1426 +    (setq
  1.1427 +     cmd (YaTeX-replace-format
  1.1428 +	  cmd
  1.1429 +	  "f"
  1.1430 +	  (if arg
  1.1431 +	      ""
  1.1432 +	    (YaTeX-replace-format
  1.1433 +	     dviprint-from-format
  1.1434 +	     "b"
  1.1435 +	     (if (string=
  1.1436 +		  (setq from (read-string "From page(default 1): ")) "")
  1.1437 +		 "1" from)))))
  1.1438 +    (setq
  1.1439 +     cmd (YaTeX-replace-format
  1.1440 +	  cmd
  1.1441 +	  "t"
  1.1442 +	  (if (or arg
  1.1443 +		  (string= 
  1.1444 +		   (setq to (read-string "To page(default none): ")) ""))
  1.1445 +	      ""
  1.1446 +	    (YaTeX-replace-format dviprint-to-format "e" to))))
  1.1447 +    (setq cmd (read-string "Edit command line: "
  1.1448 +			   (format cmd (YaTeX-get-preview-file-name))))
  1.1449 +    (with-output-to-temp-buffer "*dvi-printing*"
  1.1450 +      (if (eq system-type 'ms-dos)
  1.1451 +	  (call-process shell-file-name "con" "*dvi-printing*" nil
  1.1452 +			"/c " cmd)
  1.1453 +	(start-process "print" "*dvi-printing*" shell-file-name "-c" cmd)
  1.1454 +	(message (concat "Starting " cmd " to printing "
  1.1455 +			 (YaTeX-get-preview-file-name))))
  1.1456 +    ))
  1.1457 +)
  1.1458 +
  1.1459  (defun YaTeX-read-user-completion-table ()
  1.1460    "Append user completion table of LaTeX word"
  1.1461    (message "Loading personal completion table")
  1.1462 @@ -1032,27 +1656,19 @@
  1.1463      index)
  1.1464  )
  1.1465  
  1.1466 -(defun point-beginning-of-line ()
  1.1467 -  (save-excursion (beginning-of-line)(point))
  1.1468 -)
  1.1469 -
  1.1470 -(defun point-end-of-line ()
  1.1471 -  (save-excursion (end-of-line)(point))
  1.1472 -)
  1.1473 -
  1.1474  (defun append-to-hook (hook hook-list)
  1.1475    "Add hook-list to certain emacs's hook correctly.
  1.1476  Argument hook-list is the list of function int the form to be called
  1.1477  Call this function with argument as next example,
  1.1478  	(append-to-hook '((ding))) ;If one function to add.
  1.1479  	(append-to-hook '((func1)(func2 arg)))."
  1.1480 -  (if (null (eval hook))   			;Not defined
  1.1481 +  (if (null (symbol-value hook))   			;Not defined
  1.1482        (set hook
  1.1483  	   (append '(lambda ()) hook-list))
  1.1484 -    (if (listp (eval hook))
  1.1485 -	(if (eq (car (eval hook)) 'lambda)	;'(lambda () ....)
  1.1486 +    (if (listp (symbol-value hook))
  1.1487 +	(if (eq (car (symbol-value hook)) 'lambda)	;'(lambda () ....)
  1.1488  	    (set hook
  1.1489 -		 (append (eval hook) hook-list))
  1.1490 +		 (append (symbol-value hook) hook-list))
  1.1491  	  (if (eq hook 'kill-emacs-hook)	;'(hook1 hook2 ...)
  1.1492  	      (progn				; this format is not
  1.1493  		(ding)				; for kill-emacs-hook
  1.1494 @@ -1060,12 +1676,12 @@
  1.1495  		 "Caution!! you have wrong format of kill-emacs-hook"))
  1.1496  	    (while (not (null hook-list))
  1.1497  	      (set hook
  1.1498 -		   (append (eval hook) (car hook-list)))
  1.1499 +		   (append (symbol-value hook) (car hook-list)))
  1.1500  	      (setq hook-list (cdr hook-list))))
  1.1501  	  )
  1.1502        (set hook					;'hook
  1.1503  	   (append '(lambda ())
  1.1504 -		   (cons (list (eval hook)) hook-list)))))
  1.1505 +		   (cons (list (symbol-value hook)) hook-list)))))
  1.1506  )
  1.1507  (append-to-hook 'kill-emacs-hook '((YaTeX-save-table)))
  1.1508  
  1.1509 @@ -1086,7 +1702,7 @@
  1.1510  ; 1.23 | 92/ 1/ 8 | Enable latex and preview command on DOS.
  1.1511  ; 1.24 |     1/ 9 | Add YaTeX-save-table to kill-emacs-hook automatically.
  1.1512  ; 1.25 |     1/16 | YaTeX-do-completion (prefix+SPC) and argument
  1.1513 -;      |          | acceptable YaTeX-make-section works. Put region into
  1.1514 +;      |          | acceptable YaTeX-make-section work. Put region into
  1.1515  ;      |          | \begin...\end by calling YaTeX-make-begin-end with ARG.
  1.1516  ;      |          | append-kill-emacs-hook was revised to append-to-hook.
  1.1517  ; 1.26 |     1/18 | Region mode is added to {\large }. Default fontsize.
  1.1518 @@ -1100,10 +1716,25 @@
  1.1519  ; 1.32 |    11/16 | YaTeX-goto-corresponding-environment.
  1.1520  ;      |          | Comment out region/paragraph added.
  1.1521  ; 1.33 |    11/29 | Variable default value, on DOS and other OS.
  1.1522 -;      |          | make dvi2-command buffer local.  Change the behavior of
  1.1523 +;      |          | Make dvi2-command buffer local.  Change the behavior of
  1.1524  ;      |          | comment out region/paragraph on the \begin{} or \end{}
  1.1525 -;      |          | line.  Make faster YaTeX-end-environment. Add YaTeX-
  1.1526 +;      |          | line.  Make YaTeX-end-environment faster. Add YaTeX-
  1.1527  ;      |          | define-key, YaTeX-define-begend-(region-)key.
  1.1528 +; 1.34 |    12/26 | YaTeX-goto-corresponding-* automatically choose its move.
  1.1529 +;      |          | YaTeX-prev-error supports separate typesetting.
  1.1530 +; 1.35 | 93/ 1/25 | YaTeX-kill-environment erases pair of begin/end.
  1.1531 +;      |          | YaTeX-change-environment change the environment name.
  1.1532 +;      |          | Auto indent at YaTeX-make-begin-end.
  1.1533 +; 1.36 |     1/27 | YaTeX-typeset-region typesets the region from %#BEGIN to
  1.1534 +;      |          | %#END, or simple region between point and mark.
  1.1535 +; 1.37 |     2/12 | YaTeX-kill-environment turns YaTeX-kill-some-pairs and
  1.1536 +;      |          | now it can kill %#BEGIN and %#END pairs.
  1.1537 +;      |          | Now YaTeX-goto-corresponding-environment detects nested
  1.1538 +;      |          | environment.  Put " by " in verbatim.  Auto save buffers
  1.1539 +;      |          | with quiery.  Add current file to includeonly list
  1.1540 +;      |          | automatically.  Support YaTeX-fill-item, YaTeX-make-
  1.1541 +;      |          | accent, YaTeX-visit-main-other-window.
  1.1542 +;      |          | [prefix] tl for lpr.  Revise YaTeX-view-error.
  1.1543  ;------+----------+---------------------------------------------------------
  1.1544  ;
  1.1545  ;----------------------------- End of yatex.el -----------------------------
     2.1 --- a/yatex.new	Mon Nov 30 07:29:11 1992 +0000
     2.2 +++ b/yatex.new	Tue Feb 16 08:51:15 1993 +0000
     2.3 @@ -2,6 +2,39 @@
     2.4  	Yet Another tex-mode for Emacs
     2.5  	yatex.el 各バージョンの変更点について。
     2.6  
     2.7 +1.37:	YaTeX-kill-* の、%#BEGIN/%#END対応。
     2.8 +	対応する環境へのジャンプで、ネストした環境を正しく検出。
     2.9 +	verbatim 環境では " は " のまま入力。
    2.10 +	タイプセット時に未保存の .tex バッファのセーブを確認。
    2.11 +	カレントファイルが、メインファイルの includeonly からもれている場
    2.12 +	合には、確認後自動的に includeonly に追加。
    2.13 +	[prefix] i の \item 項目の桁揃え(fill-prefix自動調整)追加。
    2.14 +	[prefix] a のアクセント記号入力メニュー追加。
    2.15 +	[prefix] 4^ で別ウィンドウでメインファイルを選択。
    2.16 +	[prefix] tl で lpr メニュー。view-error の見直し。
    2.17 +	Demacs でのタイプセット時には Hit Any Key を出さずに終了。
    2.18 +	修論が終わった:-)。
    2.19 +
    2.20 +1.36:	リジョン指定のタイプセットのサポート。%#BEGINと%#ENDで囲まれた領域、
    2.21 +	%#END が無ければ %#BEGIN 以降、両方なければマークとポイントの間を
    2.22 +	texput.tex に保存し、jlatex を起動する。
    2.23 +
    2.24 +1.35:	[prefix] k でカーソル上にあるオブジェクトの消去。まずは、対応する
    2.25 +	begin/end の消去(YaTeX-kill-environment)のみ。
    2.26 +	[prefix] c でカーソル上にあるオブジェクトの変更。まずは、LaTeX の
    2.27 +	環境名の変更(YaTeX-change-environment)のみ。
    2.28 +	アドイン関数のサポート。まずは、begin型補完時に呼び出せる関数があ
    2.29 +	るかチェック。
    2.30 +	補完入力した位置を YaTeX-current-position-register に保存。
    2.31 +	begin型補完を入力した位置と同じインデントで補完。
    2.32 +
    2.33 +1.34:	Mule 対応(漢字コード関係の見直し)。
    2.34 +	[prefix] g を押した時の行の内容により、動作を変えるようにした。
    2.35 +	YaTeX-prev-error で tex コマンドのログからどのファイルから出された
    2.36 +	エラーか調べ、そのファイルに switch-to-buffer するようにした。
    2.37 +	typeset 中に何かキーを押して、編集バッファに戻った場合、typeset が
    2.38 +	終了したら自動的に、typeset バッファの一番下を表示するようにした。
    2.39 +
    2.40  1.33:	コマンド名のデフォルト値を OS によって自動的に選択。
    2.41  	\begin{} \end{} の行でコメント操作したときの動作を変更。
    2.42  	dvi2-command をバッファローカルに。