yatex

changeset 0:9c72144baf95

First releas version (at ftp.ae).
author yuuji
date Mon, 20 Jul 1992 14:41:40 +0000
parents
children 912f6e258cba
files yatex.el
diffstat 1 files changed, 830 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/yatex.el	Mon Jul 20 14:41:40 1992 +0000
     1.3 @@ -0,0 +1,830 @@
     1.4 +;;; -*- Emacs-Lisp -*-
     1.5 +;;; Yet Another tex-mode for emacs.
     1.6 +;;; yatex.el rev.1.27
     1.7 +;;; (c)1991 by Hirose Yuuji.[yuuji@ae.keio.ac.jp]
     1.8 +;;; Last modified Thu Jun  4 20:03:06 1992 on figaro
     1.9 +
    1.10 +(provide 'yatex-mode)
    1.11 +(defconst YaTeX-revision-number "1.27"
    1.12 +  "Revision number of running yatex.el"
    1.13 +)
    1.14 +
    1.15 +;---------- Local variables ----------
    1.16 +;;;
    1.17 +;; Initialize local variable for yatex-mode.
    1.18 +;; Preserving user preferred definitions.
    1.19 +;; ** Check all of these defvar-ed values **
    1.20 +;; ** and setq other values more suitable **
    1.21 +;; ** for your site, if nedded.           **
    1.22 +;;;
    1.23 +(defvar YaTeX-prefix "\^C"
    1.24 +  "Prefix key to trigger YaTeX functions.
    1.25 +You can select favorite prefix key by setq in your ~/.emacs."
    1.26 +)
    1.27 +(defvar YaTeX-open-lines 1
    1.28 +  "Blank lines between text and \??{??}"
    1.29 +)
    1.30 +(defvar YaTeX-fill-prefix "\t"
    1.31 +  "fill-prefix used for auto-fill-mode.
    1.32 +The defalut value is single TAB."
    1.33 +)
    1.34 +(defvar YaTeX-user-completion-table "~/.yatexrc"
    1.35 +  "Default filename in which user completion table is saved."
    1.36 +)
    1.37 +(defvar tex-command "jlatex"
    1.38 +  "Default command for compiling LaTeX text."
    1.39 +)
    1.40 +(defvar dvi2-command		;previewer command for your site
    1.41 +  (concat
    1.42 +   "xdvi -geo +0+0 -s 4 -display "
    1.43 +   (getenv "DISPLAY"))
    1.44 +  "Default previewer command including its option.
    1.45 +This default value is for X window system.  If you want to use this
    1.46 +default, you have to make sure the environment variable DISPLAY is
    1.47 +correctly set."
    1.48 +)
    1.49 +(defvar latex-warning-regexp "line.* [0-9]*"
    1.50 +  "Regular expression of line number of warning message by latex command."
    1.51 +)
    1.52 +(defvar latex-error-regexp "l\\.[1-9][0-9]*"
    1.53 +  "Regular expression of line number of latex error.  Perhaps your latex
    1.54 +command stops at this error message with line number of LaTeX source text."
    1.55 +)
    1.56 +(defvar latex-dos-emergency-message "Emergency stop"
    1.57 +  "Because Demacs (GNU Emacs on DOS) cannot have pararell process, the
    1.58 +latex command which is stopping on a LaTeX error, is terminated by Demacs.
    1.59 +Many latex command on DOS display some message when it is terminated by
    1.60 +other process, user or OS.  Define this variable a message string of your
    1.61 +latex command on DOS shows at abnormal termination.
    1.62 +  Remember Demacs's call-process function is not oriented for interactive
    1.63 +process."
    1.64 +)
    1.65 +
    1.66 +;------------ Completion table ------------
    1.67 +; Set tex-section-like command possible completion
    1.68 +(setq section-table
    1.69 +      '(("part") ("section") ("subsection") ("subsubsection")
    1.70 +	("author") ("documentstyle") ("pagestyle")
    1.71 +	("documentstyle[10pt]") ("documentstyle[11pt]")
    1.72 +	("documentstyle[12pt]")
    1.73 +	("item[]") ("title") ("chapter") ("part") ("paragraph")
    1.74 +	("subparagraph") ("underline") ("label") ("footnote")
    1.75 +	("hspace*") ("vspace*") ("bibliography") ("bibitem[]") ("cite[]")
    1.76 +	("nocite") ("input") ("include") ("includeonly") ("mbox") ("hbox")
    1.77 +	("caption") ("newcommand") ("setlength") ("addtolength")
    1.78 +	("newenvironment") ("newtheorem")
    1.79 +))
    1.80 +(defvar user-section-table nil)
    1.81 +
    1.82 +; Set style possible completion
    1.83 +(setq article-table
    1.84 +      '(("article") ("jarticle") ("report") ("jreport") ("jbook")
    1.85 +	("4em") ("2ex")
    1.86 +	("empty") ("headings") ("\\textwidth")
    1.87 +	("\\oddsidemargin") ("\\evensidemargin")
    1.88 +	("\\textheight") ("\\topmargin")
    1.89 +	("\\bottommargin") ("\\footskip") ("\\footheight")
    1.90 +))
    1.91 +(defvar user-article-table nil)
    1.92 +
    1.93 +; Set tex-environment possible completion
    1.94 +(setq env-table
    1.95 +      '(("quote") ("quotation") ("center") ("verse") ("document")
    1.96 +	("verbatim") ("itemize") ("enumerate") ("description")
    1.97 +	("list{}") ("tabular") ("table") ("titlepage")
    1.98 +	("sloppypar") ("ref") ("quotation") ("quote") ("picture")
    1.99 +	("eqnarray") ("figure") ("equation") ("abstract") ("array")
   1.100 +	("thebibliography") ("theindex")
   1.101 +))
   1.102 +(defvar user-env-table nil)
   1.103 +
   1.104 +; Set {\Large }-like comletion
   1.105 +(setq fontsize-table
   1.106 +      '(("rm") ("em") ("bf") ("boldmath") ("it") ("sl") ("sf") ("sc") ("tt")
   1.107 +	("dg") ("dm")
   1.108 +	("tiny") ("scriptsize") ("footnotesize") ("small")("normalsize")
   1.109 +	("large") ("Large") ("LARGE") ("huge") ("Huge")
   1.110 +))
   1.111 +(defvar user-fontsize-table nil)
   1.112 +
   1.113 +(setq singlecmd-table
   1.114 +      '(("maketitle") ("sloppy")
   1.115 +	("alpha") ("beta") ("gamma") ("delta") ("epsilon") ("varepsilon")
   1.116 +	("zeta") ("eta") ("theta")("vartheta") ("iota") ("kappa")
   1.117 +	("lambda") ("mu") ("nu") ("xi") ("pi") ("varpi") ("rho") ("varrho")
   1.118 +	("sigma") ("varsigma") ("tau") ("upsilon") ("phi") ("varphi")
   1.119 +	("chi") ("psi") ("omega") ("Gamma") ("Delta") ("Theta") ("Lambda")
   1.120 +	("Xi") ("Pi") ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")
   1.121 +	("LaTeX") ("TeX")
   1.122 +))
   1.123 +(defvar user-singlecmd-table nil)
   1.124 +
   1.125 +;---------- Key mode map ----------
   1.126 +;;;
   1.127 +;; Create new key map: YaTeX-mode-map
   1.128 +;; Do not change this section.
   1.129 +;;;
   1.130 +(defvar YaTeX-mode-map nil
   1.131 +  "Keymap used in YaTeX mode."
   1.132 +)
   1.133 +(defvar YaTeX-compilation-mode-map nil
   1.134 +  "Keymap userd in YaTeX compilation buffer."
   1.135 +)
   1.136 +
   1.137 +;---------- Define deafult key bindings on YaTeX mode map ----------
   1.138 +;;;
   1.139 +;; Define key table
   1.140 +;;;
   1.141 +(if YaTeX-mode-map 
   1.142 +    nil
   1.143 +  (global-unset-key (concat YaTeX-prefix "b"))
   1.144 +  (setq YaTeX-mode-map (make-sparse-keymap))
   1.145 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "tj")
   1.146 +    'YaTeX-compile)
   1.147 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "tx")
   1.148 +    'YaTeX-preview)
   1.149 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "tv")
   1.150 +    'YaTeX-view-error)
   1.151 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "tb")
   1.152 +    '(lambda () (interactive) (YaTeX-insert-string "\\")))
   1.153 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "'")
   1.154 +    'YaTeX-prev-error)
   1.155 +  (define-key YaTeX-mode-map (concat YaTeX-prefix " ")
   1.156 +    'YaTeX-do-completion)
   1.157 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "v")
   1.158 +    'YaTeX-version)
   1.159 +
   1.160 +  (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
   1.161 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "{")
   1.162 +    'YaTeX-insert-braces)
   1.163 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "}")
   1.164 +    'YaTeX-insert-braces-region)
   1.165 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "d")
   1.166 +    'YaTeX-insert-dollar)
   1.167 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "\\")
   1.168 +    '(lambda () (interactive) (YaTeX-insert-string "$\\backslash$")))
   1.169 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "bd")
   1.170 +    '(lambda (arg) (interactive "P")
   1.171 +       (YaTeX-insert-begin-end "document" arg)))
   1.172 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "Bd")
   1.173 +    '(lambda () (interactive)
   1.174 +       (YaTeX-insert-begin-end "document" t)))
   1.175 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "bD")
   1.176 +    '(lambda (arg) (interactive "P")
   1.177 +       (YaTeX-insert-begin-end "description" arg)))
   1.178 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "BD")
   1.179 +    '(lambda () (interactive)
   1.180 +       (YaTeX-insert-begin-end "description" t)))
   1.181 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "be")
   1.182 +    '(lambda (arg) (interactive "P")
   1.183 +       (YaTeX-insert-begin-end "enumerate" arg)))
   1.184 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "Be")
   1.185 +    '(lambda () (interactive)
   1.186 +       (YaTeX-insert-begin-end "enumerate" t)))
   1.187 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "bi")
   1.188 +    '(lambda (arg) (interactive "P")
   1.189 +       (YaTeX-insert-begin-end "itemize" arg)))
   1.190 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "Bi")
   1.191 +    '(lambda () (interactive)
   1.192 +       (YaTeX-insert-begin-end "itemize" t)))
   1.193 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "bt")
   1.194 +    '(lambda (arg) (interactive "P")
   1.195 +       (YaTeX-insert-begin-end "tabbing" arg)))
   1.196 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "Bt")
   1.197 +    '(lambda () (interactive)
   1.198 +       (YaTeX-insert-begin-end "tabbing" t)))
   1.199 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "bT")
   1.200 +    '(lambda (arg) (interactive "P")
   1.201 +       (YaTeX-insert-begin-end "tabular" arg)))
   1.202 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "BT")
   1.203 +    '(lambda () (interactive)
   1.204 +       (YaTeX-insert-begin-end "tabular" t)))
   1.205 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "bq")
   1.206 +    '(lambda (arg) (interactive "P")
   1.207 +       (YaTeX-insert-begin-end "quote" arg)))
   1.208 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "Bq")
   1.209 +    '(lambda () (interactive)
   1.210 +       (YaTeX-insert-begin-end "quote" t)))
   1.211 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "bQ")
   1.212 +    '(lambda (arg) (interactive "P")
   1.213 +       (YaTeX-insert-begin-end "quotation" arg)))
   1.214 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "BQ")
   1.215 +    '(lambda () (interactive)
   1.216 +       (YaTeX-insert-begin-end "quotation" t)))
   1.217 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "b ")
   1.218 +    'YaTeX-make-begin-end)
   1.219 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "B ")
   1.220 +    'YaTeX-make-begin-end-region)
   1.221 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "s")
   1.222 +    'YaTeX-make-section)
   1.223 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "l")
   1.224 +    'YaTeX-make-fontsize)
   1.225 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "L")
   1.226 +    'YaTeX-make-fontsize-region)
   1.227 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "m")
   1.228 +    'YaTeX-make-singlecmd)
   1.229 +  (define-key YaTeX-mode-map (concat YaTeX-prefix "\C-m")
   1.230 +    '(lambda () (interactive) (YaTeX-insert-string "\\\\")))
   1.231 +  (if (eq system-type 'ms-dos)
   1.232 +      (define-key YaTeX-mode-map (concat YaTeX-prefix "\^L")
   1.233 +	'(lambda () (interactive)
   1.234 +	   (set-screen-height 24) (recenter))))
   1.235 +)
   1.236 +
   1.237 +(if YaTeX-compilation-mode-map nil
   1.238 +  (setq YaTeX-compilation-mode-map (make-keymap))
   1.239 +  (suppress-keymap YaTeX-compilation-mode-map t)
   1.240 +  (define-key YaTeX-compilation-mode-map " "
   1.241 +    'YaTeX-jump-error-line)
   1.242 +)
   1.243 +
   1.244 +;---------- Customize as you like above ----------
   1.245 +
   1.246 +;---------- Kanji code selection ----------
   1.247 +(if (eq system-type 'ms-dos)
   1.248 +    (setq YaTeX-kanji-code 1)
   1.249 +  (setq YaTeX-kanji-code 2))
   1.250 +
   1.251 +(setq kanji-display-code YaTeX-kanji-code
   1.252 +      kanji-fileio-code  YaTeX-kanji-code)
   1.253 +;---------- Define other variable ----------
   1.254 +(defvar env-name "document")		;Initial tex-environment completion
   1.255 +(defvar section-name "documentstyle[12pt]") ;Initial tex-section completion
   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 +)
   1.261 +(defvar yatex-mode-hook nil
   1.262 +  "List of functions to be called after .tex file is read
   1.263 +and yatex-mode starts.")
   1.264 +
   1.265 +;---------- Produce YaTeX-mode ----------
   1.266 +;;;
   1.267 +;; Major mode definition
   1.268 +;;;
   1.269 +(defun yatex-mode ()
   1.270 +  (interactive)
   1.271 +  (kill-all-local-variables)
   1.272 +  (setq major-mode 'YaTeX-mode)
   1.273 +  (setq mode-name "$@$d$F$U$b!<$I(J")
   1.274 +  (turn-on-auto-fill)
   1.275 +  (make-local-variable 'fill-column)
   1.276 +  (make-local-variable 'fill-prefix)
   1.277 +  (setq fill-column 72
   1.278 +	fill-prefix YaTeX-fill-prefix)
   1.279 +  (use-local-map YaTeX-mode-map)
   1.280 +  (if (eq system-type 'ms-dos)
   1.281 +      (set-screen-height 24))
   1.282 +  (if YaTeX-user-table-has-read nil
   1.283 +    (YaTeX-read-user-completion-table)
   1.284 +    (setq YaTeX-user-table-has-read t))
   1.285 +  (run-hooks 'yatex-mode-hook)
   1.286 +)
   1.287 +
   1.288 +;---------- Define YaTeX-mode functions ----------
   1.289 +;;;
   1.290 +;; YaTeX-mode functions
   1.291 +;;;
   1.292 +(defun YaTeX-insert-begin-end (env arg)
   1.293 +  "Insert \begin{mode-name} and \end{mode-name}."
   1.294 +  (if arg
   1.295 +      (save-excursion
   1.296 +	(if (> (point) (mark)) (exchange-point-and-mark))
   1.297 +	(insert "\\begin{" env "}\n")
   1.298 +	(exchange-point-and-mark)
   1.299 +	(insert "\\end{" env "}\n"))
   1.300 +    (delete-blank-lines)
   1.301 +    (insert "\\begin{" env "}\n")
   1.302 +    (newline (1+ (* 2 YaTeX-open-lines)))
   1.303 +    (insert "\\end{" env "}\n")
   1.304 +    (previous-line (+ 2 YaTeX-open-lines)))
   1.305 +)
   1.306 +
   1.307 +(defun YaTeX-exist-completion-table (elm table)
   1.308 +  "Return nil, if single list element:elm was
   1.309 +not found in possible completion table."
   1.310 +  (while (not (or (null table) (equal elm (car table))))
   1.311 +    (setq table (cdr table)))
   1.312 +  table
   1.313 +)
   1.314 +
   1.315 +(defun YaTeX-make-begin-end (arg)
   1.316 +  "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
   1.317 +by completing read.
   1.318 + If you invoke this command with universal argument,
   1.319 +\(C-u or ESC-1 is typical prefix to invoke commands with ARG.\)
   1.320 +you can put REGION into that environment between \\begin and \\end."
   1.321 +  (interactive "P")
   1.322 +  (let*
   1.323 +      ((mode (if arg " region" ""))
   1.324 +       (env
   1.325 +	(completing-read
   1.326 +	 (format "Begin environment%s(default %s): " mode env-name)
   1.327 +	 (append user-env-table env-table) nil nil)))
   1.328 +    (if (string= env "")
   1.329 +	(setq env env-name))
   1.330 +    (setq env-name env)
   1.331 +    (if (not (YaTeX-exist-completion-table
   1.332 +	      (list env-name) (append user-env-table env-table)))
   1.333 +	(setq user-env-table (cons (list env-name) user-env-table)))
   1.334 +    (YaTeX-insert-begin-end env-name arg))
   1.335 +)
   1.336 +
   1.337 +(defun YaTeX-make-begin-end-region ()
   1.338 +  "Call YaTeX-make-begin-end with ARG to specify region mode."
   1.339 +  (interactive)
   1.340 +  (YaTeX-make-begin-end t)
   1.341 +)
   1.342 +
   1.343 +(defun YaTeX-make-section (arg)
   1.344 +  "Make LaTeX \\section{} type command with completing read.
   1.345 +With ARG of numeric, you can specify the number of argument of
   1.346 +LaTeX command.
   1.347 +  For example, if you want to produce LaTeX command
   1.348 +
   1.349 +	\\addtolength{\\topmargin}{8mm}
   1.350 +
   1.351 +which has two argument.  You can produce that sequence by typing...
   1.352 +	ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
   1.353 +\(by default\)
   1.354 +You can complete symbol at LaTeX command and 1st argument."
   1.355 +  (interactive "p")
   1.356 +  (let*
   1.357 +      ((section
   1.358 +	(completing-read
   1.359 +	 (format "\\???{} (default %s): " section-name)
   1.360 +	 (append user-section-table section-table)
   1.361 +	 nil nil))
   1.362 +       (section (if (string= section "") section-name section))
   1.363 +       (title
   1.364 +	(completing-read (concat "\\" section "{???}: ")
   1.365 +			 (append user-article-table article-table)
   1.366 +			 nil nil)))
   1.367 +    (setq section-name section)
   1.368 +    (if (not (YaTeX-exist-completion-table
   1.369 +	      (list section-name) (append user-section-table section-table)))
   1.370 +	(setq user-section-table
   1.371 +	      (cons (list section-name) user-section-table)))
   1.372 +    (insert "\\" section-name "{" title "}")
   1.373 +    (let ((j 2))
   1.374 +      (while (<= j arg)
   1.375 +	(insert (concat "{" (read-string (format "Argument %d: " j))))
   1.376 +	(insert "}")
   1.377 +	(setq j (1+ j)))
   1.378 +      )
   1.379 +    (if (string= title "") (forward-char -1)
   1.380 +      nil))
   1.381 +)
   1.382 +
   1.383 +;(defun YaTeX-make-section-region ()
   1.384 +;  "Call YaTeX-make-section with ARG to specify region mode."
   1.385 +; (interactive)
   1.386 +; (YaTeX-make-section t)
   1.387 +;)
   1.388 +
   1.389 +(defun YaTeX-make-fontsize (arg)
   1.390 +  "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
   1.391 +If you invoke this command with universal argument, you can put region
   1.392 +into {\\xxx } braces.
   1.393 +\(C-u or ESC-1 are default key bindings of universal-argument.\)"
   1.394 +  (interactive "P")
   1.395 +  (let* ((mode (if arg "region" ""))
   1.396 +	 (fontsize
   1.397 +	  (completing-read
   1.398 +	   (format "{\\??? %s} (default %s): " mode fontsize-name)
   1.399 +	   (append user-fontsize-table fontsize-table)
   1.400 +	   nil nil )))
   1.401 +    (if (string= fontsize "")
   1.402 +	(setq fontsize fontsize-name))
   1.403 +    (setq fontsize-name fontsize)
   1.404 +    (if (not (YaTeX-exist-completion-table
   1.405 +	      (list fontsize-name)
   1.406 +	      (append user-fontsize-table fontsize-table)))
   1.407 +	(setq user-fontsize-table
   1.408 +	    (cons (list fontsize-name) user-fontsize-table)))
   1.409 +    (if arg
   1.410 +	(save-excursion
   1.411 +	  (if (> (point) (mark)) (exchange-point-and-mark))
   1.412 +	  (insert "{\\" fontsize-name " ")
   1.413 +	  (exchange-point-and-mark)
   1.414 +	  (insert "}"))
   1.415 +      (insert "{\\" fontsize-name " }")
   1.416 +      (forward-char -1)))
   1.417 +)
   1.418 +
   1.419 +(defun YaTeX-make-fontsize-region ()
   1.420 +  "Call functino:YaTeX-make-fontsize with ARG to specify region mode."
   1.421 +  (interactive)
   1.422 +  (YaTeX-make-fontsize t)
   1.423 +)
   1.424 +
   1.425 +(defun YaTeX-make-singlecmd (single)
   1.426 +  (interactive
   1.427 +   (list (completing-read
   1.428 +	  (format "\\??? (default %s): " single-command)
   1.429 +	  (append user-singlecmd-table singlecmd-table)
   1.430 +	  nil nil )))
   1.431 +  (if (string= single "")
   1.432 +      (setq single single-command))
   1.433 +  (setq single-command single)
   1.434 +  (if (not (YaTeX-exist-completion-table
   1.435 +	    (list single-command)
   1.436 +	    (append user-singlecmd-table singlecmd-table)))
   1.437 +      (setq user-singlecmd-table
   1.438 +	    (cons (list single-command) user-singlecmd-table)))
   1.439 +  (insert "\\" single-command " ")
   1.440 +)
   1.441 +
   1.442 +(defvar YaTeX-completion-begin-regexp "[{\\]"
   1.443 +  "Regular expression of limit where LaTeX command's
   1.444 +completion begins.")
   1.445 +
   1.446 +(defun YaTeX-do-completion ()
   1.447 +  "Try completion on LaTeX command preceding point."
   1.448 +  (interactive)
   1.449 +  (if
   1.450 +      (or (eq (preceding-char) ? )
   1.451 +	  (eq (preceding-char) ?\t)
   1.452 +	  (eq (preceding-char) ?\n)
   1.453 +	  (bobp))
   1.454 +      (message "Nothing to complete.")   ;Do not complete
   1.455 +    (let* ((end (point))
   1.456 +	   (limit (save-excursion (beginning-of-line) (point)))
   1.457 +	   (completion-begin 
   1.458 +	    (progn (re-search-backward "[ \t\n]" limit 1)
   1.459 +		   (point)))
   1.460 +	   (begin (progn
   1.461 +		    (goto-char end)
   1.462 +		    (if (re-search-backward YaTeX-completion-begin-regexp
   1.463 +					    completion-begin t)
   1.464 +			(1+ (point))
   1.465 +		      nil))))
   1.466 +      (goto-char end)
   1.467 +      (cond
   1.468 +       ((null begin)
   1.469 +	(message "I think it is not LaTeX sequence."))
   1.470 +       (t
   1.471 +	(let* ((pattern (buffer-substring begin end))
   1.472 +	       (all-table (append section-table user-section-table
   1.473 +				  article-table user-article-table
   1.474 +				  env-table     user-env-table
   1.475 +				  singlecmd-table user-singlecmd-table))
   1.476 +	       ;; First,
   1.477 +	       ;; search completion without backslash.
   1.478 +	       (completion (try-completion pattern all-table nil)))
   1.479 +	  (if
   1.480 +	      (eq completion nil)
   1.481 +	      ;; Next,
   1.482 +	      ;; search completion with backslash
   1.483 +	      (setq completion
   1.484 +		    (try-completion (buffer-substring (1- begin) end)
   1.485 +				    all-table nil)
   1.486 +		    begin (1- begin)))
   1.487 +	  (cond
   1.488 +	   ((null completion)
   1.489 +	    (message (concat "Can't find completion for '" pattern "'"))
   1.490 +	    (ding))
   1.491 +	   ((eq completion t) (message "Sole completion."))
   1.492 +	   ((not (string= completion pattern))
   1.493 +	    (kill-region begin end)
   1.494 +	    (insert completion)
   1.495 +	    )
   1.496 +	   (t
   1.497 +	    (message "Making completion list...")
   1.498 +	    (with-output-to-temp-buffer "*Help*"
   1.499 +	      (display-completion-list
   1.500 +	       (all-completions pattern all-table))) )
   1.501 +	   ))))))
   1.502 +)
   1.503 +
   1.504 +(defun YaTeX-insert-quote ()
   1.505 +  (interactive)
   1.506 +  (insert
   1.507 +   (cond
   1.508 +    ((= (preceding-char) ?\\ ) ?\")
   1.509 +    ((= (preceding-char) ?\( ) ?\")
   1.510 +    ((= (preceding-char) 32)  "``")
   1.511 +    ((= (preceding-char) 9)   "``")
   1.512 +    ((= (preceding-char) ?\n) "``")
   1.513 +    ((bobp) "``")
   1.514 +    (t  "''")
   1.515 +)))
   1.516 +
   1.517 +
   1.518 +(defun YaTeX-insert-braces-region (beg end)
   1.519 +  (interactive "r")
   1.520 +  (save-excursion
   1.521 +    (goto-char end)
   1.522 +    (insert "}")
   1.523 +    (goto-char beg)
   1.524 +    (insert "{"))
   1.525 +)
   1.526 +
   1.527 +(defun YaTeX-insert-braces ()
   1.528 +  (interactive)
   1.529 +  (insert "{}")
   1.530 +  (forward-char -1)
   1.531 +)
   1.532 +
   1.533 +(defun YaTeX-insert-dollar ()
   1.534 +  (interactive)
   1.535 +  (insert "$$")
   1.536 +  (forward-char -1)
   1.537 +)
   1.538 +
   1.539 +(defun YaTeX-insert-string (s)
   1.540 +  (insert s)
   1.541 +)
   1.542 +
   1.543 +(defun YaTeX-version ()
   1.544 +  "Return string of the version of running YaTeX."
   1.545 +  (interactive)
   1.546 +  (message
   1.547 +   (concat "Yet Another TeX mode $@!VLnD;!W(J Revision "
   1.548 +	   YaTeX-revision-number))
   1.549 +)
   1.550 +
   1.551 +(defun YaTeX-compile-sentinel (proc mes)
   1.552 +  (cond ((null (buffer-name (process-buffer proc)))
   1.553 +         ;; buffer killed
   1.554 +         (set-process-buffer proc nil))
   1.555 +        ((memq (process-status proc) '(signal exit))
   1.556 +         (let* ((obuf (current-buffer)))
   1.557 +           ;; save-excursion isn't the right thing if
   1.558 +           ;;  process-buffer is current-buffer
   1.559 +           (unwind-protect
   1.560 +               (progn
   1.561 +                 ;; Write something in *compilation* and hack its mode line
   1.562 +                 (set-buffer (process-buffer proc))
   1.563 +                 (goto-char (point-max))
   1.564 +                 (insert ?\n "jlatex compilation " mes)
   1.565 +                 (forward-char -1)
   1.566 +                 (insert " at "
   1.567 +                         (substring (current-time-string) 0 -5))
   1.568 +		 (insert "\n * Hit any key to return * ")
   1.569 +                 (forward-char 1)
   1.570 +                 (setq mode-line-process
   1.571 +                       (concat ": "
   1.572 +                               (symbol-name (process-status proc))))
   1.573 +                 ;; If buffer and mode line will show that the process
   1.574 +                 ;; is dead, we can delete it now.  Otherwise it
   1.575 +                 ;; will stay around until M-x list-processes.
   1.576 +                 (delete-process proc)
   1.577 +		 )
   1.578 +             (setq YaTeX-compilation-process nil)
   1.579 +             ;; Force mode line redisplay soon
   1.580 +             (set-buffer-modified-p (buffer-modified-p))
   1.581 +	     )
   1.582 +	   (set-buffer obuf)
   1.583 +)))
   1.584 +)
   1.585 +
   1.586 +(defvar YaTeX-compilation-process nil
   1.587 +  "Process identifier for jlatex"
   1.588 +)
   1.589 +
   1.590 +(defun YaTeX-compile ()
   1.591 +  "Execute jlatex (or other) to LaTeX compile."
   1.592 +  (interactive)
   1.593 +  (basic-save-buffer)
   1.594 +  (if YaTeX-compilation-process
   1.595 +   (if (eq (process-status YaTeX-compilation-process) 'run)
   1.596 +	(progn (interrupt-process YaTeX-compilation-process)
   1.597 +	       (sit-for 1)
   1.598 +	       (delete-process YaTeX-compilation-process))
   1.599 +      nil) nil)
   1.600 +;  (compile1 (concat tex-command " " (buffer-name))
   1.601 +;	    "TeX error" "*TeX compilation*")
   1.602 +  (setq YaTeX-compilation-process nil)
   1.603 +  (if (eq system-type 'ms-dos)				;if MS-DOS
   1.604 +      (with-output-to-temp-buffer "*YaTeX-compilation*"
   1.605 +	(message (concat "Compiling " (buffer-name) "..."))
   1.606 +	(call-process shell-file-name nil "*YaTeX-compilation*" nil
   1.607 +		      "/c " tex-command (buffer-name) ))
   1.608 +    (setq YaTeX-compilation-process			;if UNIX
   1.609 +	  (with-output-to-temp-buffer "*YaTeX-compilation*"
   1.610 +	    (start-process "LaTeX" "*YaTeX-compilation*" shell-file-name "-c"
   1.611 +			   (concat tex-command " "(buffer-name) ""))
   1.612 +	    ))
   1.613 +    (set-process-sentinel YaTeX-compilation-process 'YaTeX-compile-sentinel))
   1.614 +  (setq current-TeX-buffer (buffer-name))
   1.615 +  (other-window 1)
   1.616 +  (use-local-map YaTeX-compilation-mode-map)
   1.617 +  (set-kanji-process-code YaTeX-kanji-code)
   1.618 +  (message "Type SPC to continue.")
   1.619 +  (goto-char (point-max))
   1.620 +  (sit-for 30)
   1.621 +  (read-char)	;hit any key
   1.622 +  (other-window -1)
   1.623 +)
   1.624 +
   1.625 +(defun YaTeX-preview (preview-command preview-file)
   1.626 +  "Execute xdvi (or other) to tex-preview."
   1.627 +  (interactive
   1.628 +   (list (read-string "Preview command: " dvi2-command)
   1.629 +	 (read-string "Prefiew file[.dvi]: "
   1.630 +		      (substring (buffer-name) 0 -4)
   1.631 +	 )))
   1.632 +  (setq dvi2-command preview-command)
   1.633 +  (with-output-to-temp-buffer "*dvi-preview*"
   1.634 +    (if (eq system-type 'ms-dos)
   1.635 +	(progn (send-string-to-terminal "\e[2J")	;if MS-DOS
   1.636 +	       (call-process shell-file-name "con" "*dvi-preview*" nil
   1.637 +			     "/c " dvi2-command preview-file)
   1.638 +	       (redraw-display))
   1.639 +      (start-process "xdvi" "*dvi-preview*" shell-file-name "-c"
   1.640 +		     (concat dvi2-command " " preview-file)) ;if UNIX
   1.641 +      (message (concat "Starting " dvi2-command " to preview " preview-file)))
   1.642 +  )
   1.643 +)
   1.644 +
   1.645 +(defun YaTeX-prev-error ()
   1.646 +  "Visit previous error.  The reason why not NEXT-error is to
   1.647 +avoid make confliction of line numbers by editing."
   1.648 +  (interactive)
   1.649 +  (setq cur-buf (buffer-name)
   1.650 +	YaTeX-error-line nil)
   1.651 +  (if (null (get-buffer "*YaTeX-compilation*"))
   1.652 +      (message "There is no output buffer of compilation.")
   1.653 +    (pop-to-buffer "*YaTeX-compilation*")
   1.654 +    (if (eq system-type 'ms-dos)
   1.655 +	(if (search-backward latex-dos-emergency-message nil t)
   1.656 +	    (progn (goto-char (point-max))
   1.657 +		   (setq error-regexp latex-error-regexp))
   1.658 +	  (beginning-of-line)
   1.659 +	  (forward-char -1)
   1.660 +	  (setq error-regexp latex-warning-regexp))
   1.661 +      (if YaTeX-compilation-process      ; if jlatex on UNIX
   1.662 +	  (if (eq (process-status YaTeX-compilation-process) 'run)
   1.663 +	      (progn
   1.664 +		(goto-char (point-max))
   1.665 +		(setq error-regexp latex-error-regexp)))
   1.666 +	(beginning-of-line)
   1.667 +	(setq error-regexp latex-warning-regexp)))
   1.668 +    (if (re-search-backward error-regexp nil t)
   1.669 +	(save-restriction
   1.670 +	  (set-mark-command nil)
   1.671 +	  (end-of-line)
   1.672 +	  (narrow-to-region (point) (mark))
   1.673 +	  (goto-char (point-min))
   1.674 +	  (re-search-forward "[0-9]")
   1.675 +	  (forward-char -1)
   1.676 +	  (set-mark (point))
   1.677 +	  (skip-chars-forward "[0-9]")
   1.678 +	  (narrow-to-region (point) (mark))
   1.679 +	  (goto-char (point-min))
   1.680 +	  (setq YaTeX-error-line (read (current-buffer))))
   1.681 +      (message "No more error on %s" cur-buf)
   1.682 +      (ding)
   1.683 +      )
   1.684 +    (other-window -1)
   1.685 +    (switch-to-buffer cur-buf)
   1.686 +    (if (null YaTeX-error-line)
   1.687 +	nil
   1.688 +      (goto-line YaTeX-error-line)
   1.689 +      (message "latex error or warning at line: %d" YaTeX-error-line)
   1.690 +      (other-window 1)
   1.691 +      (skip-chars-backward "[0-9]")
   1.692 +      (recenter (/ (window-height) 2))
   1.693 +      (sit-for 3)
   1.694 +      (forward-line -1)
   1.695 +      (other-window -1)
   1.696 +      ))
   1.697 +)
   1.698 +
   1.699 +(defun YaTeX-jump-error-line ()
   1.700 +  "Jump corresponding line on latex command's error message."
   1.701 +  (interactive)
   1.702 +  (let ((end (progn (end-of-line) (point)))
   1.703 +	(begin (progn (beginning-of-line)(point))))
   1.704 +    (if (null (re-search-forward "l[ ines]*\\.*[1-9][0-9]*" end t))
   1.705 +	(message "No line number expression")
   1.706 +      (goto-char (match-beginning 0))
   1.707 +      (re-search-forward "[1-9][0-9]*" end t)
   1.708 +      (save-restriction
   1.709 +	(narrow-to-region (match-beginning 0) (match-end 0))
   1.710 +	(goto-char (point-min))
   1.711 +	(let ((error-line (read (current-buffer))))
   1.712 +	  (other-window -1)
   1.713 +	  (switch-to-buffer current-TeX-buffer)
   1.714 +	  (goto-line error-line)))))
   1.715 +)
   1.716 +
   1.717 +(defun YaTeX-view-error ()
   1.718 +  (interactive)
   1.719 +  (other-window 1)
   1.720 +  (goto-char (point-max))
   1.721 +  (other-window -1)
   1.722 +)
   1.723 +
   1.724 +(defun YaTeX-read-user-completion-table ()
   1.725 +  "Append user completion table of LaTeX word"
   1.726 +  (message "Loading personal completion table")
   1.727 +  (let ((user-table (expand-file-name YaTeX-user-completion-table)))
   1.728 +    (if (file-exists-p user-table)
   1.729 +	(load-file user-table)
   1.730 +      (message "Personal completion table not found."))
   1.731 +))
   1.732 +
   1.733 +(defun YaTeX-save-table ()
   1.734 +  "Save personal completion table as dictionary."
   1.735 +  (interactive)
   1.736 +  (message "Saving user table in %s" YaTeX-user-completion-table)
   1.737 +  (find-file (expand-file-name YaTeX-user-completion-table))
   1.738 +  (erase-buffer)
   1.739 +;  (prin1-to-string user-section-table)
   1.740 +  (insert "(setq user-section-table '(\n")
   1.741 +  (mapcar '(lambda (s)
   1.742 +	     (insert (prin1-to-string s))
   1.743 +	     (insert "\n"))
   1.744 +	  user-section-table)
   1.745 +  (insert "))\n\n")
   1.746 +
   1.747 +  (insert "(setq user-article-table '(\n")
   1.748 +  (mapcar '(lambda (s)
   1.749 +	     (insert (prin1-to-string s))
   1.750 +	     (insert "\n"))
   1.751 +	  user-article-table)
   1.752 +  (insert "))\n\n")
   1.753 +
   1.754 +  (insert "(setq user-env-table '(\n")
   1.755 +  (mapcar '(lambda (s)
   1.756 +	     (insert (prin1-to-string s))
   1.757 +	     (insert "\n"))
   1.758 +	  user-env-table)
   1.759 +  (insert "))\n\n")
   1.760 +
   1.761 +  (insert "(setq user-fontsize-table '(\n")
   1.762 +  (mapcar '(lambda (s)
   1.763 +	     (insert (prin1-to-string s))
   1.764 +	     (insert "\n"))
   1.765 +	  user-fontsize-table)
   1.766 +  (insert "))\n\n")
   1.767 +
   1.768 +  (insert "(setq user-singlecmd-table '(\n")
   1.769 +  (mapcar '(lambda (s)
   1.770 +	   (insert (prin1-to-string s))
   1.771 +	   (insert "\n"))
   1.772 +	user-singlecmd-table)
   1.773 +  (insert "))\n")
   1.774 +
   1.775 +  (basic-save-buffer)
   1.776 +  (kill-buffer (current-buffer))
   1.777 +  (message "")
   1.778 +)
   1.779 +
   1.780 +(defun append-to-hook (hook hook-list)
   1.781 +  "Add hook-list to certain emacs's hook correctly.
   1.782 +Argument hook-list is the list of function int the form to be called
   1.783 +Call this function with argument as next example,
   1.784 +	(append-to-hook '((ding))) ;If one function to add.
   1.785 +	(append-to-hook '((func1)(func2 arg)))."
   1.786 +  (if (null (eval hook))   			;Not defined
   1.787 +      (set hook
   1.788 +	   (append '(lambda ()) hook-list))
   1.789 +    (if (listp (eval hook))
   1.790 +	(if (eq (car (eval hook)) 'lambda)	;'(lambda () ....)
   1.791 +	    (set hook
   1.792 +		 (append (eval hook) hook-list))
   1.793 +	  (if (eq hook 'kill-emacs-hook)	;'(hook1 hook2 ...)
   1.794 +	      (progn				; this format is not
   1.795 +		(ding)				; for kill-emacs-hook
   1.796 +		(message
   1.797 +		 "Caution!! you have wrong format of kill-emacs-hook"))
   1.798 +	    (while (not (null hook-list))
   1.799 +	      (set hook
   1.800 +		   (append (eval hook) (car hook-list)))
   1.801 +	      (setq hook-list (cdr hook-list))))
   1.802 +	  )
   1.803 +      (set hook					;'hook
   1.804 +	   (append '(lambda ())
   1.805 +		   (cons (list (eval hook)) hook-list)))))
   1.806 +)
   1.807 +(append-to-hook 'kill-emacs-hook '((YaTeX-save-table)))
   1.808 +
   1.809 +;--------------------------------- History ---------------------------------
   1.810 +; Rev. |   Date   | Contents
   1.811 +;------+----------+---------------------------------------------------------
   1.812 +; 1.00 | 91/ 6/13 | Initial version.
   1.813 +;      |          | Auto compilation & preview.
   1.814 +;      |          | \section{}-type and \begin{}\end{}-type completion.
   1.815 +; 1.01 | 91/ 6/14 | Add {\large ..} type completion (prefix+l).
   1.816 +; 1.10 |     6/21 | Add learning feature of completion.
   1.817 +; 1.11 |     6/27 | Simplify function begin-document etc. using lambda.
   1.818 +; 1.12 |     7/ 6 | Modify YaTeX-make-section, show section-name.
   1.819 +; 1.13 |    12/ 4 | Delete blank lines in make begin/end environment.
   1.820 +; 1.20 |    12/ 5 | Saving learned completion into user file.
   1.821 +; 1.21 |    12/ 6 | Add \maketitle type completion (prefix+m).
   1.822 +; 1.22 |    12/30 | Port yatex.el to DOS(Demacs).
   1.823 +; 1.23 | 92/ 1/ 8 | Enable latex and preview command on DOS.
   1.824 +; 1.24 |     1/ 9 | Add YaTeX-save-table to kill-emacs-hook automatically.
   1.825 +; 1.25 |     1/16 | YaTeX-do-completion (prefix+SPC) and argument
   1.826 +;      |          | acceptable YaTeX-make-section work. Put region into
   1.827 +;      |          | \begin...\end by calling YaTeX-make-begin-end with ARG.
   1.828 +;      |          | append-kill-emacs-hook was revised to append-to-hook.
   1.829 +; 1.26 |     1/18 | Region mode is added to {\large }. Default fontsize.
   1.830 +; 1.27 |     1/21 | Default name on completing-read,
   1.831 +;------+----------+---------------------------------------------------------
   1.832 +;
   1.833 +;----------------------------- End of yatex.el -----------------------------