yatex

changeset 4:78dfe28b6a35

Provide service function to define begin/end insert key-bind. Support environment wide commenting/de-commenting. Revise YaTeX-end-environment. Add YaTeX-inhibit-prefix-alphabet to avoid "C-c letter".
author yuuji
date Mon, 30 Nov 1992 07:29:11 +0000
parents 191610912c8b
children 370a391533fd
files yatex.el yatex.new
diffstat 2 files changed, 317 insertions(+), 245 deletions(-) [+]
line diff
     1.1 --- a/yatex.el	Thu Nov 19 02:27:25 1992 +0000
     1.2 +++ b/yatex.el	Mon Nov 30 07:29:11 1992 +0000
     1.3 @@ -1,12 +1,12 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5  ;;; Yet Another tex-mode for emacs.
     1.6 -;;; yatex.el rev.1.32
     1.7 +;;; yatex.el rev.1.33
     1.8  ;;; (c)1991 by Hirose Yuuji.[yuuji@ae.keio.ac.jp]
     1.9 -;;; Last modified Tue Nov 17 01:01:12 1992 on 98fa
    1.10 +;;; Last modified Sun Nov 29 16:04:57 1992 on 98fa
    1.11  
    1.12  (provide 'yatex-mode)
    1.13  (require 'comment)
    1.14 -(defconst YaTeX-revision-number "1.32"
    1.15 +(defconst YaTeX-revision-number "1.33"
    1.16    "Revision number of running yatex.el"
    1.17  )
    1.18  
    1.19 @@ -29,17 +29,24 @@
    1.20    "fill-prefix used for auto-fill-mode.
    1.21  The defalut value is single TAB."
    1.22  )
    1.23 -(defvar YaTeX-user-completion-table "~/.yatexrc"
    1.24 +(defvar YaTeX-comment-prefix "%"
    1.25 +  "TeX comment prefix."
    1.26 +)
    1.27 +(defvar YaTeX-user-completion-table
    1.28 +  (if (eq system-type 'ms-dos) "~/_yatexrc"
    1.29 +    "~/.yatexrc")
    1.30    "Default filename in which user completion table is saved."
    1.31  )
    1.32  (defvar tex-command "jlatex"
    1.33    "Default command for compiling LaTeX text."
    1.34  )
    1.35  (defvar dvi2-command		;previewer command for your site
    1.36 -  (concat
    1.37 -   "xdvi -geo +0+0 -s 4 -display "
    1.38 -   (getenv "DISPLAY"))
    1.39 -  "Default previewer command including its option.
    1.40 +  (if (eq system-type 'ms-dos)
    1.41 +      "dviout"
    1.42 +    (concat
    1.43 +     "xdvi -geo +0+0 -s 4 -display "
    1.44 +     (getenv "DISPLAY")))
    1.45 +    "Default previewer command including its option.
    1.46  This default value is for X window system.  If you want to use this
    1.47  default, you have to make sure the environment variable DISPLAY is
    1.48  correctly set."
    1.49 @@ -117,7 +124,7 @@
    1.50  	("sigma") ("varsigma") ("tau") ("upsilon") ("phi") ("varphi")
    1.51  	("chi") ("psi") ("omega") ("Gamma") ("Delta") ("Theta") ("Lambda")
    1.52  	("Xi") ("Pi") ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")
    1.53 -	("LaTeX") ("TeX") ("item[]") 
    1.54 +	("LaTeX") ("TeX") ("item[]")
    1.55  ))
    1.56  (defvar user-singlecmd-table nil)
    1.57  
    1.58 @@ -126,129 +133,102 @@
    1.59  ;; Create new key map: YaTeX-mode-map
    1.60  ;; Do not change this section.
    1.61  ;;;
    1.62 +(defvar YaTeX-inhibit-prefix-letter nil
    1.63 +  "Switch which determin whether inhibit yatex.el from defining
    1.64 +key sequence \"C-c letter\" or not."
    1.65 +)
    1.66  (defvar YaTeX-mode-map nil
    1.67    "Keymap used in YaTeX mode."
    1.68  )
    1.69 -(defvar YaTeX-compilation-mode-map nil
    1.70 -  "Keymap userd in YaTeX compilation buffer."
    1.71 +(defvar YaTeX-typesetting-mode-map nil
    1.72 +  "Keymap userd in YaTeX typesetting buffer."
    1.73 +)
    1.74 +(defvar YaTeX-prefix-map nil
    1.75 +  "Keymap used when YaTeX-prefix key pushed."
    1.76  )
    1.77  
    1.78  ;---------- Define deafult key bindings on YaTeX mode map ----------
    1.79 +(defun YaTeX-define-key (key binding)
    1.80 +  "Define key on YaTeX-prefix-map"
    1.81 +  (if YaTeX-inhibit-prefix-letter
    1.82 +      (let ((c (aref key 0)))
    1.83 +	(cond
    1.84 +	 ((and (>= c ?a) (<= c ?z)) (aset key 0 (1+ (- c ?a))))
    1.85 +	 ((and (>= c ?A) (<= c ?Z)) (aset key 0 (1+ (- c ?A))))
    1.86 +	 (t nil))))
    1.87 +  (define-key YaTeX-prefix-map key binding)
    1.88 +)
    1.89 +(defun YaTeX-define-begend-key (key env)
    1.90 +  "Define short cut YaTeX-make-begin-end key."
    1.91 +  (YaTeX-define-key
    1.92 +   key
    1.93 +   (list 'lambda '(arg) '(interactive "P")
    1.94 +	 (list 'YaTeX-insert-begin-end env 'arg)))
    1.95 +)
    1.96 +(defun YaTeX-define-begend-region-key (key env)
    1.97 +  "Define short cut YaTeX-make-begin-end-region key."
    1.98 +  (YaTeX-define-key key (list 'lambda nil '(interactive)
    1.99 +			      (list 'YaTeX-insert-begin-end env t)))
   1.100 +)
   1.101  ;;;
   1.102  ;; Define key table
   1.103  ;;;
   1.104  (if YaTeX-mode-map 
   1.105      nil
   1.106 -  (global-unset-key (concat YaTeX-prefix "b"))
   1.107    (setq YaTeX-mode-map (make-sparse-keymap))
   1.108 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "tj")
   1.109 -    'YaTeX-compile)
   1.110 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "tx")
   1.111 -    'YaTeX-preview)
   1.112 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "tv")
   1.113 -    'YaTeX-view-error)
   1.114 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "tb")
   1.115 -    '(lambda () (interactive) (YaTeX-insert-string "\\")))
   1.116 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "'")
   1.117 -    'YaTeX-prev-error)
   1.118 -  (define-key YaTeX-mode-map (concat YaTeX-prefix " ")
   1.119 -    'YaTeX-do-completion)
   1.120 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "v")
   1.121 -    'YaTeX-version)
   1.122 +  (setq YaTeX-prefix-map (make-sparse-keymap))
   1.123 +  (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
   1.124 +  (define-key YaTeX-mode-map YaTeX-prefix YaTeX-prefix-map)
   1.125 +  (YaTeX-define-key "t" 'YaTeX-typeset-menu)
   1.126 +  (define-key YaTeX-prefix-map "'" 'YaTeX-prev-error)
   1.127 +  (define-key YaTeX-prefix-map " " 'YaTeX-do-completion)
   1.128 +  (YaTeX-define-key "v" 'YaTeX-version)
   1.129  
   1.130 -  (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
   1.131 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "{")
   1.132 -    'YaTeX-insert-braces)
   1.133 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "}")
   1.134 -    'YaTeX-insert-braces-region)
   1.135 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "d")
   1.136 -    'YaTeX-insert-dollar)
   1.137 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "\\")
   1.138 -    '(lambda () (interactive) (YaTeX-insert-string "$\\backslash$")))
   1.139 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "bd")
   1.140 -    '(lambda (arg) (interactive "P")
   1.141 -       (YaTeX-insert-begin-end "document" arg)))
   1.142 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "Bd")
   1.143 -    '(lambda () (interactive)
   1.144 -       (YaTeX-insert-begin-end "document" t)))
   1.145 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "bD")
   1.146 -    '(lambda (arg) (interactive "P")
   1.147 -       (YaTeX-insert-begin-end "description" arg)))
   1.148 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "BD")
   1.149 -    '(lambda () (interactive)
   1.150 -       (YaTeX-insert-begin-end "description" t)))
   1.151 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "be")
   1.152 -    '(lambda (arg) (interactive "P")
   1.153 -       (YaTeX-insert-begin-end "enumerate" arg)))
   1.154 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "Be")
   1.155 -    '(lambda () (interactive)
   1.156 -       (YaTeX-insert-begin-end "enumerate" t)))
   1.157 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "bi")
   1.158 -    '(lambda (arg) (interactive "P")
   1.159 -       (YaTeX-insert-begin-end "itemize" arg)))
   1.160 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "Bi")
   1.161 -    '(lambda () (interactive)
   1.162 -       (YaTeX-insert-begin-end "itemize" t)))
   1.163 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "bt")
   1.164 -    '(lambda (arg) (interactive "P")
   1.165 -       (YaTeX-insert-begin-end "tabbing" arg)))
   1.166 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "Bt")
   1.167 -    '(lambda () (interactive)
   1.168 -       (YaTeX-insert-begin-end "tabbing" t)))
   1.169 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "bT")
   1.170 -    '(lambda (arg) (interactive "P")
   1.171 -       (YaTeX-insert-begin-end "tabular" arg)))
   1.172 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "BT")
   1.173 -    '(lambda () (interactive)
   1.174 -       (YaTeX-insert-begin-end "tabular" t)))
   1.175 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "bq")
   1.176 -    '(lambda (arg) (interactive "P")
   1.177 -       (YaTeX-insert-begin-end "quote" arg)))
   1.178 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "Bq")
   1.179 -    '(lambda () (interactive)
   1.180 -       (YaTeX-insert-begin-end "quote" t)))
   1.181 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "bQ")
   1.182 -    '(lambda (arg) (interactive "P")
   1.183 -       (YaTeX-insert-begin-end "quotation" arg)))
   1.184 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "BQ")
   1.185 -    '(lambda () (interactive)
   1.186 -       (YaTeX-insert-begin-end "quotation" t)))
   1.187 -  (define-key YaTeX-mode-map (concat YaTeX-prefix ".")
   1.188 -    'YaTeX-comment-paragraph)
   1.189 -  (define-key YaTeX-mode-map (concat YaTeX-prefix ",")
   1.190 -    'YaTeX-uncomment-paragraph)
   1.191 -  (define-key YaTeX-mode-map (concat YaTeX-prefix ">")
   1.192 -    '(lambda () (interactive) (comment-region "%")))
   1.193 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "<")
   1.194 -    '(lambda () (interactive) (uncomment-region "%")))
   1.195 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "b ")
   1.196 -    'YaTeX-make-begin-end)
   1.197 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "B ")
   1.198 -    'YaTeX-make-begin-end-region)
   1.199 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "e")
   1.200 -    'YaTeX-end-environment)
   1.201 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "s")
   1.202 -    'YaTeX-make-section)
   1.203 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "l")
   1.204 -    'YaTeX-make-fontsize)
   1.205 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "L")
   1.206 -    'YaTeX-make-fontsize-region)
   1.207 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "m")
   1.208 -    'YaTeX-make-singlecmd)
   1.209 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "g")
   1.210 -    'YaTeX-goto-corresponding-environment)
   1.211 -  (define-key YaTeX-mode-map (concat YaTeX-prefix "\C-m")
   1.212 +  (define-key YaTeX-prefix-map "{" 'YaTeX-insert-braces)
   1.213 +  (define-key YaTeX-prefix-map "}" 'YaTeX-insert-braces-region)
   1.214 +  (YaTeX-define-key "d" 'YaTeX-insert-dollar)
   1.215 +  (YaTeX-define-key
   1.216 +   "\\" '(lambda () (interactive) (YaTeX-insert-string "$\\backslash$")))
   1.217 +  (YaTeX-define-begend-region-key "Bd" "document")
   1.218 +  (YaTeX-define-begend-key "bd" "document")
   1.219 +  (YaTeX-define-begend-region-key "BD" "description")
   1.220 +  (YaTeX-define-begend-key "bD" "description")
   1.221 +  (YaTeX-define-begend-region-key  "Be" "enumerate")
   1.222 +  (YaTeX-define-begend-key  "be" "enumerate")
   1.223 +  (YaTeX-define-begend-region-key  "Bi" "itemize")
   1.224 +  (YaTeX-define-begend-key  "bi" "itemize")
   1.225 +  (YaTeX-define-begend-region-key  "Bt" "tabbing")
   1.226 +  (YaTeX-define-begend-key  "bt" "tabbing")
   1.227 +  (YaTeX-define-begend-region-key  "BT" "tabular")
   1.228 +  (YaTeX-define-begend-key  "bT" "tabular")
   1.229 +  (YaTeX-define-begend-region-key  "Bq" "quote")
   1.230 +  (YaTeX-define-begend-key  "bq" "quote")
   1.231 +  (YaTeX-define-begend-region-key  "BQ" "quotation")
   1.232 +  (YaTeX-define-begend-key  "bQ" "quotation")
   1.233 +  (YaTeX-define-key "." 'YaTeX-comment-paragraph)
   1.234 +  (YaTeX-define-key "," 'YaTeX-uncomment-paragraph)
   1.235 +  (YaTeX-define-key ">" 'YaTeX-comment-region)
   1.236 +  (YaTeX-define-key "<" 'YaTeX-uncomment-region)
   1.237 +  (YaTeX-define-key "B " 'YaTeX-make-begin-end-region)
   1.238 +  (YaTeX-define-key "b " 'YaTeX-make-begin-end)
   1.239 +  (YaTeX-define-key "e" 'YaTeX-end-environment)
   1.240 +  (YaTeX-define-key "s" 'YaTeX-make-section)
   1.241 +  (YaTeX-define-key "L" 'YaTeX-make-fontsize-region)
   1.242 +  (YaTeX-define-key "l" 'YaTeX-make-fontsize)
   1.243 +  (YaTeX-define-key "m" 'YaTeX-make-singlecmd)
   1.244 +  (YaTeX-define-key "g" 'YaTeX-goto-corresponding-environment)
   1.245 +  (YaTeX-define-key "\C-m"
   1.246      '(lambda () (interactive) (YaTeX-insert-string "\\\\")))
   1.247    (if (eq system-type 'ms-dos)
   1.248 -      (define-key YaTeX-mode-map (concat YaTeX-prefix "\^L")
   1.249 +      (define-key YaTeX-prefix-map "\^L"
   1.250  	'(lambda () (interactive)
   1.251  	   (set-screen-height YaTeX-saved-screen-height) (recenter))))
   1.252  )
   1.253  
   1.254 -(if YaTeX-compilation-mode-map nil
   1.255 -  (setq YaTeX-compilation-mode-map (make-keymap))
   1.256 -  (suppress-keymap YaTeX-compilation-mode-map t)
   1.257 -  (define-key YaTeX-compilation-mode-map " "
   1.258 +(if YaTeX-typesetting-mode-map nil
   1.259 +  (setq YaTeX-typesetting-mode-map (make-keymap))
   1.260 +  (suppress-keymap YaTeX-typesetting-mode-map t)
   1.261 +  (define-key YaTeX-typesetting-mode-map " "
   1.262      'YaTeX-jump-error-line)
   1.263  )
   1.264  
   1.265 @@ -262,6 +242,9 @@
   1.266  (defvar YaTeX-user-table-has-read nil
   1.267    "Flag that means whether user completion table has read or not."
   1.268  )
   1.269 +(defvar YaTeX-user-table-modified nil
   1.270 +  "Flag that means whether user completion table has modified or not."
   1.271 +)
   1.272  (defvar yatex-mode-hook nil
   1.273    "List of functions to be called after .tex file is read
   1.274  and yatex-mode starts.")
   1.275 @@ -276,6 +259,7 @@
   1.276    (setq major-mode 'YaTeX-mode)
   1.277    (setq mode-name "やてふもーど")
   1.278    (turn-on-auto-fill)
   1.279 +  (make-local-variable 'dvi2-command)
   1.280    (make-local-variable 'kanji-display-code)
   1.281    (make-local-variable 'kanji-fileio-code)
   1.282    (if (eq system-type 'ms-dos)
   1.283 @@ -315,14 +299,6 @@
   1.284      (previous-line (+ 2 YaTeX-open-lines)))
   1.285  )
   1.286  
   1.287 -(defun YaTeX-exist-completion-table (elm table)
   1.288 -  "Return nil, if single list element:elm was
   1.289 -not found in possible completion table."
   1.290 -  (while (not (or (null table) (equal elm (car table))))
   1.291 -    (setq table (cdr table)))
   1.292 -  table
   1.293 -)
   1.294 -
   1.295  (defun YaTeX-make-begin-end (arg)
   1.296    "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
   1.297  by completing read.
   1.298 @@ -339,9 +315,9 @@
   1.299      (if (string= env "")
   1.300  	(setq env env-name))
   1.301      (setq env-name env)
   1.302 -    (if (not (YaTeX-exist-completion-table
   1.303 -	      (list env-name) (append user-env-table env-table)))
   1.304 -	(setq user-env-table (cons (list env-name) user-env-table)))
   1.305 +    (if (not (assoc env-name (append user-env-table env-table))) ;if not exist
   1.306 +	(setq user-env-table (cons (list env-name) user-env-table)
   1.307 +	    YaTeX-user-table-modified t))
   1.308      (YaTeX-insert-begin-end env-name arg))
   1.309  )
   1.310  
   1.311 @@ -355,24 +331,26 @@
   1.312    "Close opening environment"
   1.313    (interactive)
   1.314    (let ((curp (point))
   1.315 -	(s)(env nil)(nest 0))
   1.316 +	s env (nest 0))
   1.317      (save-excursion
   1.318        (while
   1.319  	  (and
   1.320  	   (>= nest 0)
   1.321  	   (re-search-backward
   1.322 -	    "^[^\\%]*\\(\\\\begin{.*}\\)\\|\\(\\\\end{.*}\\)" (point-min) t))
   1.323 -	(setq nest (if (re-search-forward "begin{" (match-end 0) t)
   1.324 -		       (1- nest) (1+ nest))))
   1.325 +	    "\\(\\\\begin{\\).*}\\|\\(\\\\end{\\).*}" (point-min) t))
   1.326 +	(if (re-search-backward "^[ 	]*%" (point-beginning-of-line) t)
   1.327 +	    nil	;ignore TeX comment usage.
   1.328 +	  (setq nest (if (eq (match-beginning 0) (match-beginning 1))
   1.329 +			 (1- nest) (1+ nest)))))
   1.330        (if (>= nest 0)
   1.331  	  (message "No premature environment")
   1.332 -	(goto-char (match-end 0))
   1.333 +	(goto-char (match-end 1))
   1.334  	(setq s (point))
   1.335 -	(skip-chars-forward "0-9_A-z")
   1.336 +	(skip-chars-forward "^}")
   1.337  	(setq env (buffer-substring s (point)))
   1.338  	;;(recursive-edit)
   1.339  	))
   1.340 -    (if (null env) nil
   1.341 +    (if (not env) nil
   1.342        (save-excursion
   1.343  	(if (and (re-search-forward "^[^\\%]*\\\\end{.*}" (point-max) t)
   1.344  		 (progn (goto-char (match-beginning 0))
   1.345 @@ -381,18 +359,17 @@
   1.346  		 (concat "Environment `" env
   1.347  			 "' was already closed. Force close?"))
   1.348  		nil
   1.349 -	      (setq env nil))))
   1.350 +	      (error "end environment aborted."))))
   1.351        (message "")			;Erase (y or n) message.
   1.352 -      (if (null env) nil
   1.353 -	(insert "\\end{" env "}")
   1.354 -	(setq curp (point))
   1.355 -	(goto-char s)
   1.356 -	(if (pos-visible-in-window-p)
   1.357 -	    (sit-for 1)
   1.358 -	  (message (concat "Matches \\begin{" env
   1.359 -			   (format "} at line %d"
   1.360 +      (insert "\\end{" env "}")
   1.361 +      (setq curp (point))
   1.362 +      (goto-char s)
   1.363 +      (if (pos-visible-in-window-p)
   1.364 +	  (sit-for 1)
   1.365 +	(message (concat "Matches \\begin{" env
   1.366 +			 (format "} at line %d"
   1.367  				   (count-lines (point-min) s)))))
   1.368 -	(goto-char curp)))
   1.369 +      (goto-char curp))
   1.370      )
   1.371  )
   1.372  
   1.373 @@ -421,10 +398,10 @@
   1.374  			 (append user-article-table article-table)
   1.375  			 nil nil)))
   1.376      (setq section-name section)
   1.377 -    (if (not (YaTeX-exist-completion-table
   1.378 -	      (list section-name) (append user-section-table section-table)))
   1.379 +    (if (not (assoc section-name (append user-section-table section-table)))
   1.380  	(setq user-section-table
   1.381 -	      (cons (list section-name) user-section-table)))
   1.382 +	      (cons (list section-name) user-section-table)
   1.383 +	      YaTeX-user-table-modified t))
   1.384      (insert "\\" section-name "{" title "}")
   1.385      (let ((j 2))
   1.386        (while (<= j arg)
   1.387 @@ -457,11 +434,10 @@
   1.388      (if (string= fontsize "")
   1.389  	(setq fontsize fontsize-name))
   1.390      (setq fontsize-name fontsize)
   1.391 -    (if (not (YaTeX-exist-completion-table
   1.392 -	      (list fontsize-name)
   1.393 -	      (append user-fontsize-table fontsize-table)))
   1.394 +    (if (not (assoc fontsize-name (append user-fontsize-table fontsize-table)))
   1.395  	(setq user-fontsize-table
   1.396 -	    (cons (list fontsize-name) user-fontsize-table)))
   1.397 +	      (cons (list fontsize-name) user-fontsize-table)
   1.398 +	      YaTeX-user-table-modified t))
   1.399      (if arg
   1.400  	(save-excursion
   1.401  	  (if (> (point) (mark)) (exchange-point-and-mark))
   1.402 @@ -487,11 +463,11 @@
   1.403    (if (string= single "")
   1.404        (setq single single-command))
   1.405    (setq single-command single)
   1.406 -  (if (not (YaTeX-exist-completion-table
   1.407 -	    (list single-command)
   1.408 -	    (append user-singlecmd-table singlecmd-table)))
   1.409 +  (if (not (assoc single-command
   1.410 +		  (append user-singlecmd-table singlecmd-table)))
   1.411        (setq user-singlecmd-table
   1.412 -	    (cons (list single-command) user-singlecmd-table)))
   1.413 +	    (cons (list single-command) user-singlecmd-table)
   1.414 +	    YaTeX-user-table-modified t))
   1.415    (insert "\\" single-command " ")
   1.416  )
   1.417  
   1.418 @@ -604,7 +580,7 @@
   1.419  	   YaTeX-revision-number))
   1.420  )
   1.421  
   1.422 -(defun YaTeX-compile-sentinel (proc mes)
   1.423 +(defun YaTeX-typeset-sentinel (proc mes)
   1.424    (cond ((null (buffer-name (process-buffer proc)))
   1.425           ;; buffer killed
   1.426           (set-process-buffer proc nil))
   1.427 @@ -614,10 +590,10 @@
   1.428             ;;  process-buffer is current-buffer
   1.429             (unwind-protect
   1.430                 (progn
   1.431 -                 ;; Write something in *compilation* and hack its mode line
   1.432 +                 ;; Write something in *typesetting* and hack its mode line
   1.433                   (set-buffer (process-buffer proc))
   1.434                   (goto-char (point-max))
   1.435 -                 (insert ?\n "jlatex compilation " mes)
   1.436 +                 (insert ?\n "jlatex typesetting " mes)
   1.437                   (forward-char -1)
   1.438                   (insert " at "
   1.439                           (substring (current-time-string) 0 -5))
   1.440 @@ -631,7 +607,7 @@
   1.441                   ;; will stay around until M-x list-processes.
   1.442                   (delete-process proc)
   1.443  		 )
   1.444 -             (setq YaTeX-compilation-process nil)
   1.445 +             (setq YaTeX-typesetting-process nil)
   1.446               ;; Force mode line redisplay soon
   1.447               (set-buffer-modified-p (buffer-modified-p))
   1.448  	     )
   1.449 @@ -639,49 +615,50 @@
   1.450  )))
   1.451  )
   1.452  
   1.453 -(defvar YaTeX-compilation-process nil
   1.454 +(defvar YaTeX-typesetting-process nil
   1.455    "Process identifier for jlatex"
   1.456  )
   1.457  
   1.458 -(defun YaTeX-compile ()
   1.459 -  "Execute jlatex (or other) to LaTeX compile."
   1.460 +(defun YaTeX-typeset ()
   1.461 +  "Execute jlatex (or other) to LaTeX typeset."
   1.462    (interactive)
   1.463 -  (if YaTeX-compilation-process
   1.464 -   (if (eq (process-status YaTeX-compilation-process) 'run)
   1.465 -	(progn (interrupt-process YaTeX-compilation-process)
   1.466 +  (if YaTeX-typesetting-process
   1.467 +   (if (eq (process-status YaTeX-typesetting-process) 'run)
   1.468 +	(progn (interrupt-process YaTeX-typesetting-process)
   1.469  	       (sit-for 1)
   1.470 -	       (delete-process YaTeX-compilation-process))
   1.471 +	       (delete-process YaTeX-typesetting-process))
   1.472        nil) nil)
   1.473  ;  (compile1 (concat tex-command " " (buffer-name))
   1.474 -;	    "TeX error" "*TeX compilation*")
   1.475 -  (setq YaTeX-compilation-process nil)
   1.476 +;	    "TeX error" "*TeX typesetting*")
   1.477 +  (setq YaTeX-typesetting-process nil)
   1.478    (if (eq system-type 'ms-dos)				;if MS-DOS
   1.479 -      (with-output-to-temp-buffer "*YaTeX-compilation*"
   1.480 +      (with-output-to-temp-buffer "*YaTeX-typesetting*"
   1.481  	(message (concat "Compiling " (buffer-name) "..."))
   1.482  	(YaTeX-put-nonstopmode)
   1.483  	(basic-save-buffer)
   1.484  	(call-process shell-file-name
   1.485  		      nil
   1.486 -		      "*YaTeX-compilation*" nil
   1.487 +		      "*YaTeX-typesetting*" nil
   1.488  		      "/c" (YaTeX-get-latex-command))
   1.489 -		      ;;;"/c " tex-command (buffer-name) )
   1.490  	(YaTeX-remove-nonstopmode))
   1.491 -    (setq YaTeX-compilation-process			;if UNIX
   1.492 -	  (with-output-to-temp-buffer "*YaTeX-compilation*"
   1.493 +    (setq YaTeX-typesetting-process			;if UNIX
   1.494 +	  (with-output-to-temp-buffer "*YaTeX-typesetting*"
   1.495  	    (basic-save-buffer)
   1.496 -	    (start-process "LaTeX" "*YaTeX-compilation*" shell-file-name "-c"
   1.497 +	    (start-process "LaTeX" "*YaTeX-typesetting*" shell-file-name "-c"
   1.498  			   (YaTeX-get-latex-command))
   1.499 -			   ;;;tex-command (buffer-name) "")
   1.500  	    ))
   1.501 -    (set-process-sentinel YaTeX-compilation-process 'YaTeX-compile-sentinel))
   1.502 +    (set-process-sentinel YaTeX-typesetting-process 'YaTeX-typeset-sentinel))
   1.503    (setq current-TeX-buffer (buffer-name))
   1.504    (other-window 1)
   1.505 -  (use-local-map YaTeX-compilation-mode-map)
   1.506 +  (use-local-map YaTeX-typesetting-mode-map)
   1.507    (set-kanji-process-code YaTeX-kanji-code)
   1.508    (message "Type SPC to continue.")
   1.509    (goto-char (point-max))
   1.510    (sit-for 30)
   1.511    (read-char)	;hit any key
   1.512 +  (if (not (= (window-start) (point-min)))
   1.513 +      (while (eq (point) (point-max))
   1.514 +	(scroll-down 1)))
   1.515    (other-window -1)
   1.516  )
   1.517  
   1.518 @@ -712,9 +689,9 @@
   1.519    (interactive)
   1.520    (setq cur-buf (buffer-name)
   1.521  	YaTeX-error-line nil)
   1.522 -  (if (null (get-buffer "*YaTeX-compilation*"))
   1.523 -      (message "There is no output buffer of compilation.")
   1.524 -    (pop-to-buffer "*YaTeX-compilation*")
   1.525 +  (if (null (get-buffer "*YaTeX-typesetting*"))
   1.526 +      (message "There is no output buffer of typesetting.")
   1.527 +    (pop-to-buffer "*YaTeX-typesetting*")
   1.528      (if (eq system-type 'ms-dos)
   1.529  	(if (search-backward latex-dos-emergency-message nil t)
   1.530  	    (progn (goto-char (point-max))
   1.531 @@ -722,8 +699,8 @@
   1.532  	  (beginning-of-line)
   1.533  	  (forward-char -1)
   1.534  	  (setq error-regexp latex-warning-regexp))
   1.535 -      (if YaTeX-compilation-process      ; if jlatex on UNIX
   1.536 -	  (if (eq (process-status YaTeX-compilation-process) 'run)
   1.537 +      (if YaTeX-typesetting-process      ; if jlatex on UNIX
   1.538 +	  (if (eq (process-status YaTeX-typesetting-process) 'run)
   1.539  	      (progn
   1.540  		(goto-char (point-max))
   1.541  		(setq error-regexp latex-error-regexp)))
   1.542 @@ -806,6 +783,18 @@
   1.543  	(widen)))
   1.544  )
   1.545  
   1.546 +(defun YaTeX-typeset-menu ()
   1.547 +  "Typeset, preview, visit error and miscellaneous convinient menu."
   1.548 +  (interactive)
   1.549 +  (message "J)latex P)review V)iewerror")
   1.550 +  (let ((c (read-char)))
   1.551 +    (cond
   1.552 +     ((= c ?j) (YaTeX-typeset))
   1.553 +     ((= c ?p) (call-interactively 'YaTeX-preview))
   1.554 +     ((= c ?v) (YaTeX-view-error))
   1.555 +     ((= c ?b) (YaTeX-insert-string "\\"))))
   1.556 +)
   1.557 +
   1.558  (defun YaTeX-get-preview-file-name ()
   1.559    "Get file name to preview by inquiring YaTeX-get-latex-command"
   1.560    (let* ((latex-cmd (YaTeX-get-latex-command))
   1.561 @@ -838,7 +827,7 @@
   1.562        (if (null (re-search-forward "^%#!" (point-max) t))
   1.563  	  default-command
   1.564  	(skip-chars-forward "%#! 	")
   1.565 -	(if (eolp)
   1.566 +	(if (eolp)1z
   1.567  	    default-command
   1.568  	  (let ((s (point)))
   1.569  	    (skip-chars-forward "A-z")	;Skip command name
   1.570 @@ -854,46 +843,110 @@
   1.571  (defun YaTeX-goto-corresponding-environment ()
   1.572    "Go to corresponding begin/end enclosure."
   1.573    (interactive)
   1.574 -  (beginning-of-line)
   1.575 -  (if (not (re-search-forward
   1.576 -	    "\\(begin{\\)\\|\\(end{\\)" (point-end-of-line) t))
   1.577 +  (if (not (YaTeX-on-begin-end-p))
   1.578        (error "No environment declaration"))
   1.579 -  (let ((p  (point) env)
   1.580 +  (let ((p  (match-end 0) env)
   1.581  	(m0 (match-beginning 0))
   1.582  	(m1 (match-beginning 1))
   1.583  	(m2 (match-beginning 2)))
   1.584 -    (if (not (re-search-forward "}" (point-end-of-line) t))
   1.585 +    (if (not
   1.586 +	 (save-excursion
   1.587 +	   (goto-char p)
   1.588 +	   (search-forward "}" (point-end-of-line) t)))
   1.589  	(error "Unterminated brackets for begin/end"))
   1.590      (setq env (buffer-substring p (match-beginning 0))) ;get current env
   1.591      (cond
   1.592       ((equal m0 m1)		;if begin{xxx}
   1.593 -      (re-search-forward (concat "end{" env "}")))
   1.594 +      (search-forward (concat "end{" env "}")))
   1.595       ((equal m0 m2)		;if end{xxx}
   1.596 -      (re-search-backward (concat "begin{" env "}")))
   1.597 +      (search-backward (concat "begin{" env "}")))
   1.598       )
   1.599      (beginning-of-line)
   1.600      );let
   1.601  )
   1.602  
   1.603 +(defun YaTeX-comment-region ()
   1.604 +  "Comment out region by '%'. If you call this function on the 'begin{}' or
   1.605 +'end{}' line, it comments out whole environment"
   1.606 +  (interactive)
   1.607 +  (if (not (YaTeX-on-begin-end-p))
   1.608 +      (comment-region YaTeX-comment-prefix)
   1.609 +    (YaTeX-comment-uncomment-env 'comment-region))
   1.610 +)
   1.611 +
   1.612 +(defun YaTeX-uncomment-region ()
   1.613 +  "Uncomment out region by '%'."
   1.614 +  (interactive)
   1.615 +  (if (not (YaTeX-on-begin-end-p))
   1.616 +      (uncomment-region YaTeX-comment-prefix)
   1.617 +    (YaTeX-comment-uncomment-env 'uncomment-region))
   1.618 +)
   1.619 +
   1.620 +(defun YaTeX-comment-uncomment-env (func)
   1.621 +  "Comment or uncomment out one LaTeX environment switching function by FUNC."
   1.622 +  (save-excursion
   1.623 +    (if (eq (match-beginning 0) (match-beginning 2)) ; if on the '\end{}' line
   1.624 +	(YaTeX-goto-corresponding-environment)) ; goto '\begin{}' line
   1.625 +    (beginning-of-line)
   1.626 +    (push-mark)
   1.627 +    (YaTeX-goto-corresponding-environment)
   1.628 +    (forward-line 1)
   1.629 +    (funcall func YaTeX-comment-prefix t) ; t makes uncomment once
   1.630 +    (pop-mark)
   1.631 +    )
   1.632 +)
   1.633 +
   1.634 +(defun YaTeX-mark-environment ()
   1.635 +  "Not implemented yet."
   1.636 +)
   1.637 +
   1.638 +(defun YaTeX-on-begin-end-p ()
   1.639 +  (save-excursion
   1.640 +    (beginning-of-line)
   1.641 +    (re-search-forward "\\(begin{\\)\\|\\(end{\\)" (point-end-of-line) t))
   1.642 +)
   1.643 +
   1.644  (defun YaTeX-comment-paragraph ()
   1.645    "Comment out current paragraph."
   1.646    (interactive)
   1.647    (save-excursion
   1.648 -    (mark-paragraph)
   1.649 -    (if (not (bobp)) (forward-line 1))
   1.650 -    (comment-region "%"))
   1.651 +    (if (YaTeX-on-begin-end-p)
   1.652 +	(progn
   1.653 +	  (beginning-of-line)
   1.654 +	  (insert YaTeX-comment-prefix)
   1.655 +	  (YaTeX-goto-corresponding-environment)
   1.656 +	  (beginning-of-line)
   1.657 +	  (insert YaTeX-comment-prefix))
   1.658 +      (mark-paragraph)
   1.659 +      (if (not (bobp)) (forward-line 1))
   1.660 +      (comment-region "%")))
   1.661  )
   1.662  
   1.663  (defun YaTeX-uncomment-paragraph ()
   1.664    "Uncomment current paragraph."
   1.665    (interactive)
   1.666    (save-excursion
   1.667 -    (let ((prefix fill-prefix))
   1.668 -      (setq fill-prefix "")
   1.669 -      (mark-paragraph)
   1.670 -      (if (not (bobp)) (forward-line 1))
   1.671 -      (uncomment-region "%")
   1.672 -      (setq fill-prefix prefix)))
   1.673 +    (if (YaTeX-on-begin-end-p)
   1.674 +	(progn
   1.675 +	  (YaTeX-remove-prefix YaTeX-comment-prefix t)
   1.676 +	  (YaTeX-goto-corresponding-environment)
   1.677 +	  (YaTeX-remove-prefix YaTeX-comment-prefix t))
   1.678 +      (let ((prefix fill-prefix))
   1.679 +	(setq fill-prefix "")
   1.680 +	(mark-paragraph)
   1.681 +	(if (not (bobp)) (forward-line 1))
   1.682 +	(uncomment-region "%")
   1.683 +	(setq fill-prefix prefix))))
   1.684 +)
   1.685 +
   1.686 +(defun YaTeX-remove-prefix (prefix &optional once)
   1.687 +  "Remove prefix on current line so far as prefix detected. But
   1.688 +optional argument ONCE makes deletion once."
   1.689 +  (interactive "sPrefix:")
   1.690 +  (beginning-of-line)
   1.691 +  (while (re-search-forward (concat "^" prefix) (point-end-of-line) t)
   1.692 +    (replace-match "")
   1.693 +    (if once (end-of-line)))
   1.694  )
   1.695  
   1.696  (defun YaTeX-read-user-completion-table ()
   1.697 @@ -908,48 +961,51 @@
   1.698  (defun YaTeX-save-table ()
   1.699    "Save personal completion table as dictionary."
   1.700    (interactive)
   1.701 -  (message "Saving user table in %s" YaTeX-user-completion-table)
   1.702 -  (find-file (expand-file-name YaTeX-user-completion-table))
   1.703 -  (erase-buffer)
   1.704 -;  (prin1-to-string user-section-table)
   1.705 -  (insert "(setq user-section-table '(\n")
   1.706 -  (mapcar '(lambda (s)
   1.707 -	     (insert (prin1-to-string s))
   1.708 -	     (insert "\n"))
   1.709 -	  user-section-table)
   1.710 -  (insert "))\n\n")
   1.711 -
   1.712 -  (insert "(setq user-article-table '(\n")
   1.713 -  (mapcar '(lambda (s)
   1.714 -	     (insert (prin1-to-string s))
   1.715 -	     (insert "\n"))
   1.716 -	  user-article-table)
   1.717 -  (insert "))\n\n")
   1.718 -
   1.719 -  (insert "(setq user-env-table '(\n")
   1.720 -  (mapcar '(lambda (s)
   1.721 -	     (insert (prin1-to-string s))
   1.722 -	     (insert "\n"))
   1.723 -	  user-env-table)
   1.724 -  (insert "))\n\n")
   1.725 -
   1.726 -  (insert "(setq user-fontsize-table '(\n")
   1.727 -  (mapcar '(lambda (s)
   1.728 -	     (insert (prin1-to-string s))
   1.729 -	     (insert "\n"))
   1.730 -	  user-fontsize-table)
   1.731 -  (insert "))\n\n")
   1.732 -
   1.733 -  (insert "(setq user-singlecmd-table '(\n")
   1.734 -  (mapcar '(lambda (s)
   1.735 -	   (insert (prin1-to-string s))
   1.736 -	   (insert "\n"))
   1.737 -	user-singlecmd-table)
   1.738 -  (insert "))\n")
   1.739 -
   1.740 -  (basic-save-buffer)
   1.741 -  (kill-buffer (current-buffer))
   1.742 -  (message "")
   1.743 +  (if (not YaTeX-user-table-modified)
   1.744 +      nil
   1.745 +    (message "Saving user table in %s" YaTeX-user-completion-table)
   1.746 +    (find-file (expand-file-name YaTeX-user-completion-table))
   1.747 +    (erase-buffer)
   1.748 +    ;;  (prin1-to-string user-section-table)
   1.749 +    (insert "(setq user-section-table '(\n")
   1.750 +    (mapcar '(lambda (s)
   1.751 +	       (insert (prin1-to-string s))
   1.752 +	       (insert "\n"))
   1.753 +	    user-section-table)
   1.754 +    (insert "))\n\n")
   1.755 +    
   1.756 +    (insert "(setq user-article-table '(\n")
   1.757 +    (mapcar '(lambda (s)
   1.758 +	       (insert (prin1-to-string s))
   1.759 +	       (insert "\n"))
   1.760 +	    user-article-table)
   1.761 +    (insert "))\n\n")
   1.762 +    
   1.763 +    (insert "(setq user-env-table '(\n")
   1.764 +    (mapcar '(lambda (s)
   1.765 +	       (insert (prin1-to-string s))
   1.766 +	       (insert "\n"))
   1.767 +	    user-env-table)
   1.768 +    (insert "))\n\n")
   1.769 +    
   1.770 +    (insert "(setq user-fontsize-table '(\n")
   1.771 +    (mapcar '(lambda (s)
   1.772 +	       (insert (prin1-to-string s))
   1.773 +	       (insert "\n"))
   1.774 +	    user-fontsize-table)
   1.775 +    (insert "))\n\n")
   1.776 +    
   1.777 +    (insert "(setq user-singlecmd-table '(\n")
   1.778 +    (mapcar '(lambda (s)
   1.779 +	       (insert (prin1-to-string s))
   1.780 +	       (insert "\n"))
   1.781 +	    user-singlecmd-table)
   1.782 +    (insert "))\n")
   1.783 +    
   1.784 +    (basic-save-buffer)
   1.785 +    (kill-buffer (current-buffer))
   1.786 +    (message "")
   1.787 +    (setq YaTeX-user-table-modified nil))
   1.788  )
   1.789  
   1.790  ;; --------------- General sub functions ---------------
   1.791 @@ -1041,7 +1097,13 @@
   1.792  ; 1.29 |     7/21 | Add YaTeX-end-environment.
   1.793  ; 1.30 |     9/26 | Support project 30 lines(other than 25 lines).
   1.794  ; 1.31 |    10/28 | Variable argument for previewer from %#! usage.
   1.795 -; 1.32 |    10/16 | YaTeX-goto-corresponding-environment.
   1.796 +; 1.32 |    11/16 | YaTeX-goto-corresponding-environment.
   1.797 +;      |          | Comment out region/paragraph added.
   1.798 +; 1.33 |    11/29 | Variable default value, on DOS and other OS.
   1.799 +;      |          | make dvi2-command buffer local.  Change the behavior of
   1.800 +;      |          | comment out region/paragraph on the \begin{} or \end{}
   1.801 +;      |          | line.  Make faster YaTeX-end-environment. Add YaTeX-
   1.802 +;      |          | define-key, YaTeX-define-begend-(region-)key.
   1.803  ;------+----------+---------------------------------------------------------
   1.804  ;
   1.805  ;----------------------------- End of yatex.el -----------------------------
     2.1 --- a/yatex.new	Thu Nov 19 02:27:25 1992 +0000
     2.2 +++ b/yatex.new	Mon Nov 30 07:29:11 1992 +0000
     2.3 @@ -2,16 +2,26 @@
     2.4  	Yet Another tex-mode for Emacs
     2.5  	yatex.el 各バージョンの変更点について。
     2.6  
     2.7 -1.32:	リジョン/パラグラフをコメントアウトする機能を追加
     2.8 -	対応する \begin{}/\end{} 間でジャンプする機能を追加
     2.9 +1.33:	コマンド名のデフォルト値を OS によって自動的に選択。
    2.10 +	\begin{} \end{} の行でコメント操作したときの動作を変更。
    2.11 +	dvi2-command をバッファローカルに。
    2.12 +	prefixキーの直後のキーバインドの英字の使用を禁止するスイッチと機能
    2.13 +	を追加。
    2.14 +	YaTeX-end-environment の見直し。begin/end 検索の正規表現を変え、高
    2.15 +	速化&確実化。
    2.16 +	\begin{環境}\end{環境} 挿入のショートカットキーを定義するためのユー
    2.17 +	ザ開放関数を追加。
    2.18  
    2.19 -1.31:	Previewer に渡すデフォルトのファイル名も %#! に指定したものを使用
    2.20 +1.32:	リジョン/パラグラフをコメントアウトする機能を追加。
    2.21 +	対応する \begin{}/\end{} 間でジャンプする機能を追加。
    2.22  
    2.23 -1.30:	30行計画に対応(要するに行数可変にした)
    2.24 +1.31:	Previewer に渡すデフォルトのファイル名も %#! に指定したものを使用。
    2.25  
    2.26 -1.29:	現在開いている環境名を閉じる YaTeX-end-environment を追加
    2.27 +1.30:	30行計画に対応(要するに行数可変にした)。
    2.28  
    2.29 -1.28:	%#! に続くコマンド名を latex コマンドとして実行するようにした
    2.30 +1.29:	現在開いている環境名を閉じる YaTeX-end-environment を追加。
    2.31 +
    2.32 +1.28:	%#! に続くコマンド名を latex コマンドとして実行するようにした。
    2.33  	fill-prefix を null にした。
    2.34  
    2.35  1.27:	最初の正式リリース版