yatex

annotate yatex.el @ 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
rev   line source
yuuji@0 1 ;;; -*- Emacs-Lisp -*-
yuuji@0 2 ;;; Yet Another tex-mode for emacs.
yuuji@4 3 ;;; yatex.el rev.1.33
yuuji@0 4 ;;; (c)1991 by Hirose Yuuji.[yuuji@ae.keio.ac.jp]
yuuji@4 5 ;;; Last modified Sun Nov 29 16:04:57 1992 on 98fa
yuuji@0 6
yuuji@0 7 (provide 'yatex-mode)
yuuji@3 8 (require 'comment)
yuuji@4 9 (defconst YaTeX-revision-number "1.33"
yuuji@0 10 "Revision number of running yatex.el"
yuuji@0 11 )
yuuji@0 12
yuuji@0 13 ;---------- Local variables ----------
yuuji@0 14 ;;;
yuuji@0 15 ;; Initialize local variable for yatex-mode.
yuuji@0 16 ;; Preserving user preferred definitions.
yuuji@0 17 ;; ** Check all of these defvar-ed values **
yuuji@0 18 ;; ** and setq other values more suitable **
yuuji@0 19 ;; ** for your site, if nedded. **
yuuji@0 20 ;;;
yuuji@0 21 (defvar YaTeX-prefix "\^C"
yuuji@0 22 "Prefix key to trigger YaTeX functions.
yuuji@0 23 You can select favorite prefix key by setq in your ~/.emacs."
yuuji@0 24 )
yuuji@0 25 (defvar YaTeX-open-lines 1
yuuji@0 26 "Blank lines between text and \??{??}"
yuuji@0 27 )
yuuji@1 28 (defvar YaTeX-fill-prefix ""
yuuji@0 29 "fill-prefix used for auto-fill-mode.
yuuji@0 30 The defalut value is single TAB."
yuuji@0 31 )
yuuji@4 32 (defvar YaTeX-comment-prefix "%"
yuuji@4 33 "TeX comment prefix."
yuuji@4 34 )
yuuji@4 35 (defvar YaTeX-user-completion-table
yuuji@4 36 (if (eq system-type 'ms-dos) "~/_yatexrc"
yuuji@4 37 "~/.yatexrc")
yuuji@0 38 "Default filename in which user completion table is saved."
yuuji@0 39 )
yuuji@0 40 (defvar tex-command "jlatex"
yuuji@0 41 "Default command for compiling LaTeX text."
yuuji@0 42 )
yuuji@0 43 (defvar dvi2-command ;previewer command for your site
yuuji@4 44 (if (eq system-type 'ms-dos)
yuuji@4 45 "dviout"
yuuji@4 46 (concat
yuuji@4 47 "xdvi -geo +0+0 -s 4 -display "
yuuji@4 48 (getenv "DISPLAY")))
yuuji@4 49 "Default previewer command including its option.
yuuji@0 50 This default value is for X window system. If you want to use this
yuuji@0 51 default, you have to make sure the environment variable DISPLAY is
yuuji@0 52 correctly set."
yuuji@0 53 )
yuuji@0 54 (defvar latex-warning-regexp "line.* [0-9]*"
yuuji@0 55 "Regular expression of line number of warning message by latex command."
yuuji@0 56 )
yuuji@0 57 (defvar latex-error-regexp "l\\.[1-9][0-9]*"
yuuji@0 58 "Regular expression of line number of latex error. Perhaps your latex
yuuji@0 59 command stops at this error message with line number of LaTeX source text."
yuuji@0 60 )
yuuji@1 61 (defvar latex-dos-emergency-message
yuuji@3 62 "Emergency stop" ;<- for Micro tex, ASCII-pTeX 1.6
yuuji@0 63 "Because Demacs (GNU Emacs on DOS) cannot have pararell process, the
yuuji@0 64 latex command which is stopping on a LaTeX error, is terminated by Demacs.
yuuji@0 65 Many latex command on DOS display some message when it is terminated by
yuuji@0 66 other process, user or OS. Define this variable a message string of your
yuuji@0 67 latex command on DOS shows at abnormal termination.
yuuji@0 68 Remember Demacs's call-process function is not oriented for interactive
yuuji@0 69 process."
yuuji@0 70 )
yuuji@0 71
yuuji@0 72 ;------------ Completion table ------------
yuuji@0 73 ; Set tex-section-like command possible completion
yuuji@0 74 (setq section-table
yuuji@0 75 '(("part") ("section") ("subsection") ("subsubsection")
yuuji@0 76 ("author") ("documentstyle") ("pagestyle")
yuuji@0 77 ("documentstyle[10pt]") ("documentstyle[11pt]")
yuuji@0 78 ("documentstyle[12pt]")
yuuji@3 79 ("title") ("chapter") ("part") ("paragraph")
yuuji@0 80 ("subparagraph") ("underline") ("label") ("footnote")
yuuji@0 81 ("hspace*") ("vspace*") ("bibliography") ("bibitem[]") ("cite[]")
yuuji@0 82 ("nocite") ("input") ("include") ("includeonly") ("mbox") ("hbox")
yuuji@0 83 ("caption") ("newcommand") ("setlength") ("addtolength")
yuuji@0 84 ("newenvironment") ("newtheorem")
yuuji@0 85 ))
yuuji@0 86 (defvar user-section-table nil)
yuuji@0 87
yuuji@0 88 ; Set style possible completion
yuuji@0 89 (setq article-table
yuuji@0 90 '(("article") ("jarticle") ("report") ("jreport") ("jbook")
yuuji@0 91 ("4em") ("2ex")
yuuji@0 92 ("empty") ("headings") ("\\textwidth")
yuuji@0 93 ("\\oddsidemargin") ("\\evensidemargin")
yuuji@0 94 ("\\textheight") ("\\topmargin")
yuuji@0 95 ("\\bottommargin") ("\\footskip") ("\\footheight")
yuuji@0 96 ))
yuuji@0 97 (defvar user-article-table nil)
yuuji@0 98
yuuji@0 99 ; Set tex-environment possible completion
yuuji@0 100 (setq env-table
yuuji@0 101 '(("quote") ("quotation") ("center") ("verse") ("document")
yuuji@0 102 ("verbatim") ("itemize") ("enumerate") ("description")
yuuji@0 103 ("list{}") ("tabular") ("table") ("titlepage")
yuuji@0 104 ("sloppypar") ("ref") ("quotation") ("quote") ("picture")
yuuji@0 105 ("eqnarray") ("figure") ("equation") ("abstract") ("array")
yuuji@0 106 ("thebibliography") ("theindex")
yuuji@0 107 ))
yuuji@0 108 (defvar user-env-table nil)
yuuji@0 109
yuuji@0 110 ; Set {\Large }-like comletion
yuuji@0 111 (setq fontsize-table
yuuji@0 112 '(("rm") ("em") ("bf") ("boldmath") ("it") ("sl") ("sf") ("sc") ("tt")
yuuji@0 113 ("dg") ("dm")
yuuji@0 114 ("tiny") ("scriptsize") ("footnotesize") ("small")("normalsize")
yuuji@0 115 ("large") ("Large") ("LARGE") ("huge") ("Huge")
yuuji@0 116 ))
yuuji@0 117 (defvar user-fontsize-table nil)
yuuji@0 118
yuuji@0 119 (setq singlecmd-table
yuuji@0 120 '(("maketitle") ("sloppy")
yuuji@0 121 ("alpha") ("beta") ("gamma") ("delta") ("epsilon") ("varepsilon")
yuuji@0 122 ("zeta") ("eta") ("theta")("vartheta") ("iota") ("kappa")
yuuji@0 123 ("lambda") ("mu") ("nu") ("xi") ("pi") ("varpi") ("rho") ("varrho")
yuuji@0 124 ("sigma") ("varsigma") ("tau") ("upsilon") ("phi") ("varphi")
yuuji@0 125 ("chi") ("psi") ("omega") ("Gamma") ("Delta") ("Theta") ("Lambda")
yuuji@0 126 ("Xi") ("Pi") ("Sigma") ("Upsilon") ("Phi") ("Psi") ("Omega")
yuuji@4 127 ("LaTeX") ("TeX") ("item[]")
yuuji@0 128 ))
yuuji@0 129 (defvar user-singlecmd-table nil)
yuuji@0 130
yuuji@0 131 ;---------- Key mode map ----------
yuuji@0 132 ;;;
yuuji@0 133 ;; Create new key map: YaTeX-mode-map
yuuji@0 134 ;; Do not change this section.
yuuji@0 135 ;;;
yuuji@4 136 (defvar YaTeX-inhibit-prefix-letter nil
yuuji@4 137 "Switch which determin whether inhibit yatex.el from defining
yuuji@4 138 key sequence \"C-c letter\" or not."
yuuji@4 139 )
yuuji@0 140 (defvar YaTeX-mode-map nil
yuuji@0 141 "Keymap used in YaTeX mode."
yuuji@0 142 )
yuuji@4 143 (defvar YaTeX-typesetting-mode-map nil
yuuji@4 144 "Keymap userd in YaTeX typesetting buffer."
yuuji@4 145 )
yuuji@4 146 (defvar YaTeX-prefix-map nil
yuuji@4 147 "Keymap used when YaTeX-prefix key pushed."
yuuji@0 148 )
yuuji@0 149
yuuji@0 150 ;---------- Define deafult key bindings on YaTeX mode map ----------
yuuji@4 151 (defun YaTeX-define-key (key binding)
yuuji@4 152 "Define key on YaTeX-prefix-map"
yuuji@4 153 (if YaTeX-inhibit-prefix-letter
yuuji@4 154 (let ((c (aref key 0)))
yuuji@4 155 (cond
yuuji@4 156 ((and (>= c ?a) (<= c ?z)) (aset key 0 (1+ (- c ?a))))
yuuji@4 157 ((and (>= c ?A) (<= c ?Z)) (aset key 0 (1+ (- c ?A))))
yuuji@4 158 (t nil))))
yuuji@4 159 (define-key YaTeX-prefix-map key binding)
yuuji@4 160 )
yuuji@4 161 (defun YaTeX-define-begend-key (key env)
yuuji@4 162 "Define short cut YaTeX-make-begin-end key."
yuuji@4 163 (YaTeX-define-key
yuuji@4 164 key
yuuji@4 165 (list 'lambda '(arg) '(interactive "P")
yuuji@4 166 (list 'YaTeX-insert-begin-end env 'arg)))
yuuji@4 167 )
yuuji@4 168 (defun YaTeX-define-begend-region-key (key env)
yuuji@4 169 "Define short cut YaTeX-make-begin-end-region key."
yuuji@4 170 (YaTeX-define-key key (list 'lambda nil '(interactive)
yuuji@4 171 (list 'YaTeX-insert-begin-end env t)))
yuuji@4 172 )
yuuji@0 173 ;;;
yuuji@0 174 ;; Define key table
yuuji@0 175 ;;;
yuuji@0 176 (if YaTeX-mode-map
yuuji@0 177 nil
yuuji@0 178 (setq YaTeX-mode-map (make-sparse-keymap))
yuuji@4 179 (setq YaTeX-prefix-map (make-sparse-keymap))
yuuji@4 180 (define-key YaTeX-mode-map "\"" 'YaTeX-insert-quote)
yuuji@4 181 (define-key YaTeX-mode-map YaTeX-prefix YaTeX-prefix-map)
yuuji@4 182 (YaTeX-define-key "t" 'YaTeX-typeset-menu)
yuuji@4 183 (define-key YaTeX-prefix-map "'" 'YaTeX-prev-error)
yuuji@4 184 (define-key YaTeX-prefix-map " " 'YaTeX-do-completion)
yuuji@4 185 (YaTeX-define-key "v" 'YaTeX-version)
yuuji@0 186
yuuji@4 187 (define-key YaTeX-prefix-map "{" 'YaTeX-insert-braces)
yuuji@4 188 (define-key YaTeX-prefix-map "}" 'YaTeX-insert-braces-region)
yuuji@4 189 (YaTeX-define-key "d" 'YaTeX-insert-dollar)
yuuji@4 190 (YaTeX-define-key
yuuji@4 191 "\\" '(lambda () (interactive) (YaTeX-insert-string "$\\backslash$")))
yuuji@4 192 (YaTeX-define-begend-region-key "Bd" "document")
yuuji@4 193 (YaTeX-define-begend-key "bd" "document")
yuuji@4 194 (YaTeX-define-begend-region-key "BD" "description")
yuuji@4 195 (YaTeX-define-begend-key "bD" "description")
yuuji@4 196 (YaTeX-define-begend-region-key "Be" "enumerate")
yuuji@4 197 (YaTeX-define-begend-key "be" "enumerate")
yuuji@4 198 (YaTeX-define-begend-region-key "Bi" "itemize")
yuuji@4 199 (YaTeX-define-begend-key "bi" "itemize")
yuuji@4 200 (YaTeX-define-begend-region-key "Bt" "tabbing")
yuuji@4 201 (YaTeX-define-begend-key "bt" "tabbing")
yuuji@4 202 (YaTeX-define-begend-region-key "BT" "tabular")
yuuji@4 203 (YaTeX-define-begend-key "bT" "tabular")
yuuji@4 204 (YaTeX-define-begend-region-key "Bq" "quote")
yuuji@4 205 (YaTeX-define-begend-key "bq" "quote")
yuuji@4 206 (YaTeX-define-begend-region-key "BQ" "quotation")
yuuji@4 207 (YaTeX-define-begend-key "bQ" "quotation")
yuuji@4 208 (YaTeX-define-key "." 'YaTeX-comment-paragraph)
yuuji@4 209 (YaTeX-define-key "," 'YaTeX-uncomment-paragraph)
yuuji@4 210 (YaTeX-define-key ">" 'YaTeX-comment-region)
yuuji@4 211 (YaTeX-define-key "<" 'YaTeX-uncomment-region)
yuuji@4 212 (YaTeX-define-key "B " 'YaTeX-make-begin-end-region)
yuuji@4 213 (YaTeX-define-key "b " 'YaTeX-make-begin-end)
yuuji@4 214 (YaTeX-define-key "e" 'YaTeX-end-environment)
yuuji@4 215 (YaTeX-define-key "s" 'YaTeX-make-section)
yuuji@4 216 (YaTeX-define-key "L" 'YaTeX-make-fontsize-region)
yuuji@4 217 (YaTeX-define-key "l" 'YaTeX-make-fontsize)
yuuji@4 218 (YaTeX-define-key "m" 'YaTeX-make-singlecmd)
yuuji@4 219 (YaTeX-define-key "g" 'YaTeX-goto-corresponding-environment)
yuuji@4 220 (YaTeX-define-key "\C-m"
yuuji@0 221 '(lambda () (interactive) (YaTeX-insert-string "\\\\")))
yuuji@0 222 (if (eq system-type 'ms-dos)
yuuji@4 223 (define-key YaTeX-prefix-map "\^L"
yuuji@0 224 '(lambda () (interactive)
yuuji@3 225 (set-screen-height YaTeX-saved-screen-height) (recenter))))
yuuji@0 226 )
yuuji@0 227
yuuji@4 228 (if YaTeX-typesetting-mode-map nil
yuuji@4 229 (setq YaTeX-typesetting-mode-map (make-keymap))
yuuji@4 230 (suppress-keymap YaTeX-typesetting-mode-map t)
yuuji@4 231 (define-key YaTeX-typesetting-mode-map " "
yuuji@0 232 'YaTeX-jump-error-line)
yuuji@0 233 )
yuuji@0 234
yuuji@0 235 ;---------- Customize as you like above ----------
yuuji@0 236
yuuji@0 237 ;---------- Define other variable ----------
yuuji@0 238 (defvar env-name "document") ;Initial tex-environment completion
yuuji@0 239 (defvar section-name "documentstyle[12pt]") ;Initial tex-section completion
yuuji@0 240 (defvar fontsize-name "large") ;Initial fontsize completion
yuuji@0 241 (defvar single-command "maketitle") ;Initial LaTeX single command
yuuji@0 242 (defvar YaTeX-user-table-has-read nil
yuuji@0 243 "Flag that means whether user completion table has read or not."
yuuji@0 244 )
yuuji@4 245 (defvar YaTeX-user-table-modified nil
yuuji@4 246 "Flag that means whether user completion table has modified or not."
yuuji@4 247 )
yuuji@0 248 (defvar yatex-mode-hook nil
yuuji@0 249 "List of functions to be called after .tex file is read
yuuji@0 250 and yatex-mode starts.")
yuuji@0 251
yuuji@0 252 ;---------- Produce YaTeX-mode ----------
yuuji@0 253 ;;;
yuuji@0 254 ;; Major mode definition
yuuji@0 255 ;;;
yuuji@0 256 (defun yatex-mode ()
yuuji@0 257 (interactive)
yuuji@0 258 (kill-all-local-variables)
yuuji@0 259 (setq major-mode 'YaTeX-mode)
yuuji@1 260 (setq mode-name "‚â‚Ä‚Ó‚à[‚Ç")
yuuji@0 261 (turn-on-auto-fill)
yuuji@4 262 (make-local-variable 'dvi2-command)
yuuji@1 263 (make-local-variable 'kanji-display-code)
yuuji@1 264 (make-local-variable 'kanji-fileio-code)
yuuji@1 265 (if (eq system-type 'ms-dos)
yuuji@1 266 (setq YaTeX-kanji-code 1)
yuuji@1 267 (defvar YaTeX-kanji-code 2))
yuuji@1 268 (setq kanji-display-code YaTeX-kanji-code
yuuji@1 269 kanji-fileio-code YaTeX-kanji-code)
yuuji@0 270 (make-local-variable 'fill-column)
yuuji@0 271 (make-local-variable 'fill-prefix)
yuuji@0 272 (setq fill-column 72
yuuji@0 273 fill-prefix YaTeX-fill-prefix)
yuuji@0 274 (use-local-map YaTeX-mode-map)
yuuji@0 275 (if (eq system-type 'ms-dos)
yuuji@3 276 (setq YaTeX-saved-screen-height (screen-height)))
yuuji@0 277 (if YaTeX-user-table-has-read nil
yuuji@0 278 (YaTeX-read-user-completion-table)
yuuji@0 279 (setq YaTeX-user-table-has-read t))
yuuji@0 280 (run-hooks 'yatex-mode-hook)
yuuji@0 281 )
yuuji@0 282
yuuji@0 283 ;---------- Define YaTeX-mode functions ----------
yuuji@0 284 ;;;
yuuji@0 285 ;; YaTeX-mode functions
yuuji@0 286 ;;;
yuuji@0 287 (defun YaTeX-insert-begin-end (env arg)
yuuji@0 288 "Insert \begin{mode-name} and \end{mode-name}."
yuuji@0 289 (if arg
yuuji@0 290 (save-excursion
yuuji@0 291 (if (> (point) (mark)) (exchange-point-and-mark))
yuuji@0 292 (insert "\\begin{" env "}\n")
yuuji@0 293 (exchange-point-and-mark)
yuuji@0 294 (insert "\\end{" env "}\n"))
yuuji@0 295 (delete-blank-lines)
yuuji@0 296 (insert "\\begin{" env "}\n")
yuuji@0 297 (newline (1+ (* 2 YaTeX-open-lines)))
yuuji@0 298 (insert "\\end{" env "}\n")
yuuji@0 299 (previous-line (+ 2 YaTeX-open-lines)))
yuuji@0 300 )
yuuji@0 301
yuuji@0 302 (defun YaTeX-make-begin-end (arg)
yuuji@0 303 "Make LaTeX environment command of \\begin{env.} ... \\end{env.}
yuuji@0 304 by completing read.
yuuji@0 305 If you invoke this command with universal argument,
yuuji@0 306 \(C-u or ESC-1 is typical prefix to invoke commands with ARG.\)
yuuji@0 307 you can put REGION into that environment between \\begin and \\end."
yuuji@0 308 (interactive "P")
yuuji@0 309 (let*
yuuji@0 310 ((mode (if arg " region" ""))
yuuji@0 311 (env
yuuji@0 312 (completing-read
yuuji@0 313 (format "Begin environment%s(default %s): " mode env-name)
yuuji@0 314 (append user-env-table env-table) nil nil)))
yuuji@0 315 (if (string= env "")
yuuji@0 316 (setq env env-name))
yuuji@0 317 (setq env-name env)
yuuji@4 318 (if (not (assoc env-name (append user-env-table env-table))) ;if not exist
yuuji@4 319 (setq user-env-table (cons (list env-name) user-env-table)
yuuji@4 320 YaTeX-user-table-modified t))
yuuji@0 321 (YaTeX-insert-begin-end env-name arg))
yuuji@0 322 )
yuuji@0 323
yuuji@0 324 (defun YaTeX-make-begin-end-region ()
yuuji@0 325 "Call YaTeX-make-begin-end with ARG to specify region mode."
yuuji@0 326 (interactive)
yuuji@0 327 (YaTeX-make-begin-end t)
yuuji@0 328 )
yuuji@0 329
yuuji@3 330 (defun YaTeX-end-environment ()
yuuji@3 331 "Close opening environment"
yuuji@3 332 (interactive)
yuuji@3 333 (let ((curp (point))
yuuji@4 334 s env (nest 0))
yuuji@3 335 (save-excursion
yuuji@3 336 (while
yuuji@3 337 (and
yuuji@3 338 (>= nest 0)
yuuji@3 339 (re-search-backward
yuuji@4 340 "\\(\\\\begin{\\).*}\\|\\(\\\\end{\\).*}" (point-min) t))
yuuji@4 341 (if (re-search-backward "^[ ]*%" (point-beginning-of-line) t)
yuuji@4 342 nil ;ignore TeX comment usage.
yuuji@4 343 (setq nest (if (eq (match-beginning 0) (match-beginning 1))
yuuji@4 344 (1- nest) (1+ nest)))))
yuuji@3 345 (if (>= nest 0)
yuuji@3 346 (message "No premature environment")
yuuji@4 347 (goto-char (match-end 1))
yuuji@3 348 (setq s (point))
yuuji@4 349 (skip-chars-forward "^}")
yuuji@3 350 (setq env (buffer-substring s (point)))
yuuji@3 351 ;;(recursive-edit)
yuuji@3 352 ))
yuuji@4 353 (if (not env) nil
yuuji@3 354 (save-excursion
yuuji@3 355 (if (and (re-search-forward "^[^\\%]*\\\\end{.*}" (point-max) t)
yuuji@3 356 (progn (goto-char (match-beginning 0))
yuuji@3 357 (re-search-forward env (match-end 0) t)))
yuuji@3 358 (if (y-or-n-p
yuuji@3 359 (concat "Environment `" env
yuuji@3 360 "' was already closed. Force close?"))
yuuji@3 361 nil
yuuji@4 362 (error "end environment aborted."))))
yuuji@3 363 (message "") ;Erase (y or n) message.
yuuji@4 364 (insert "\\end{" env "}")
yuuji@4 365 (setq curp (point))
yuuji@4 366 (goto-char s)
yuuji@4 367 (if (pos-visible-in-window-p)
yuuji@4 368 (sit-for 1)
yuuji@4 369 (message (concat "Matches \\begin{" env
yuuji@4 370 (format "} at line %d"
yuuji@3 371 (count-lines (point-min) s)))))
yuuji@4 372 (goto-char curp))
yuuji@3 373 )
yuuji@3 374 )
yuuji@3 375
yuuji@0 376 (defun YaTeX-make-section (arg)
yuuji@0 377 "Make LaTeX \\section{} type command with completing read.
yuuji@0 378 With ARG of numeric, you can specify the number of argument of
yuuji@0 379 LaTeX command.
yuuji@0 380 For example, if you want to produce LaTeX command
yuuji@0 381
yuuji@0 382 \\addtolength{\\topmargin}{8mm}
yuuji@0 383
yuuji@0 384 which has two argument. You can produce that sequence by typing...
yuuji@0 385 ESC 2 C-c s add SPC RET \\topm SPC RET 8mm RET
yuuji@0 386 \(by default\)
yuuji@0 387 You can complete symbol at LaTeX command and 1st argument."
yuuji@0 388 (interactive "p")
yuuji@0 389 (let*
yuuji@0 390 ((section
yuuji@0 391 (completing-read
yuuji@0 392 (format "\\???{} (default %s): " section-name)
yuuji@0 393 (append user-section-table section-table)
yuuji@0 394 nil nil))
yuuji@0 395 (section (if (string= section "") section-name section))
yuuji@0 396 (title
yuuji@0 397 (completing-read (concat "\\" section "{???}: ")
yuuji@0 398 (append user-article-table article-table)
yuuji@0 399 nil nil)))
yuuji@0 400 (setq section-name section)
yuuji@4 401 (if (not (assoc section-name (append user-section-table section-table)))
yuuji@0 402 (setq user-section-table
yuuji@4 403 (cons (list section-name) user-section-table)
yuuji@4 404 YaTeX-user-table-modified t))
yuuji@0 405 (insert "\\" section-name "{" title "}")
yuuji@0 406 (let ((j 2))
yuuji@0 407 (while (<= j arg)
yuuji@0 408 (insert (concat "{" (read-string (format "Argument %d: " j))))
yuuji@0 409 (insert "}")
yuuji@0 410 (setq j (1+ j)))
yuuji@0 411 )
yuuji@0 412 (if (string= title "") (forward-char -1)
yuuji@0 413 nil))
yuuji@0 414 )
yuuji@0 415
yuuji@0 416 ;(defun YaTeX-make-section-region ()
yuuji@0 417 ; "Call YaTeX-make-section with ARG to specify region mode."
yuuji@0 418 ; (interactive)
yuuji@0 419 ; (YaTeX-make-section t)
yuuji@0 420 ;)
yuuji@0 421
yuuji@0 422 (defun YaTeX-make-fontsize (arg)
yuuji@0 423 "Make completion like {\\large ...} or {\\slant ...} in minibuffer.
yuuji@0 424 If you invoke this command with universal argument, you can put region
yuuji@0 425 into {\\xxx } braces.
yuuji@0 426 \(C-u or ESC-1 are default key bindings of universal-argument.\)"
yuuji@0 427 (interactive "P")
yuuji@0 428 (let* ((mode (if arg "region" ""))
yuuji@0 429 (fontsize
yuuji@0 430 (completing-read
yuuji@0 431 (format "{\\??? %s} (default %s): " mode fontsize-name)
yuuji@0 432 (append user-fontsize-table fontsize-table)
yuuji@0 433 nil nil )))
yuuji@0 434 (if (string= fontsize "")
yuuji@0 435 (setq fontsize fontsize-name))
yuuji@0 436 (setq fontsize-name fontsize)
yuuji@4 437 (if (not (assoc fontsize-name (append user-fontsize-table fontsize-table)))
yuuji@0 438 (setq user-fontsize-table
yuuji@4 439 (cons (list fontsize-name) user-fontsize-table)
yuuji@4 440 YaTeX-user-table-modified t))
yuuji@0 441 (if arg
yuuji@0 442 (save-excursion
yuuji@0 443 (if (> (point) (mark)) (exchange-point-and-mark))
yuuji@0 444 (insert "{\\" fontsize-name " ")
yuuji@0 445 (exchange-point-and-mark)
yuuji@0 446 (insert "}"))
yuuji@0 447 (insert "{\\" fontsize-name " }")
yuuji@0 448 (forward-char -1)))
yuuji@0 449 )
yuuji@0 450
yuuji@0 451 (defun YaTeX-make-fontsize-region ()
yuuji@0 452 "Call functino:YaTeX-make-fontsize with ARG to specify region mode."
yuuji@0 453 (interactive)
yuuji@0 454 (YaTeX-make-fontsize t)
yuuji@0 455 )
yuuji@0 456
yuuji@0 457 (defun YaTeX-make-singlecmd (single)
yuuji@0 458 (interactive
yuuji@0 459 (list (completing-read
yuuji@0 460 (format "\\??? (default %s): " single-command)
yuuji@0 461 (append user-singlecmd-table singlecmd-table)
yuuji@0 462 nil nil )))
yuuji@0 463 (if (string= single "")
yuuji@0 464 (setq single single-command))
yuuji@0 465 (setq single-command single)
yuuji@4 466 (if (not (assoc single-command
yuuji@4 467 (append user-singlecmd-table singlecmd-table)))
yuuji@0 468 (setq user-singlecmd-table
yuuji@4 469 (cons (list single-command) user-singlecmd-table)
yuuji@4 470 YaTeX-user-table-modified t))
yuuji@0 471 (insert "\\" single-command " ")
yuuji@0 472 )
yuuji@0 473
yuuji@0 474 (defvar YaTeX-completion-begin-regexp "[{\\]"
yuuji@0 475 "Regular expression of limit where LaTeX command's
yuuji@0 476 completion begins.")
yuuji@0 477
yuuji@0 478 (defun YaTeX-do-completion ()
yuuji@0 479 "Try completion on LaTeX command preceding point."
yuuji@0 480 (interactive)
yuuji@0 481 (if
yuuji@0 482 (or (eq (preceding-char) ? )
yuuji@0 483 (eq (preceding-char) ?\t)
yuuji@0 484 (eq (preceding-char) ?\n)
yuuji@0 485 (bobp))
yuuji@0 486 (message "Nothing to complete.") ;Do not complete
yuuji@0 487 (let* ((end (point))
yuuji@0 488 (limit (save-excursion (beginning-of-line) (point)))
yuuji@0 489 (completion-begin
yuuji@0 490 (progn (re-search-backward "[ \t\n]" limit 1)
yuuji@0 491 (point)))
yuuji@0 492 (begin (progn
yuuji@0 493 (goto-char end)
yuuji@0 494 (if (re-search-backward YaTeX-completion-begin-regexp
yuuji@0 495 completion-begin t)
yuuji@0 496 (1+ (point))
yuuji@0 497 nil))))
yuuji@0 498 (goto-char end)
yuuji@0 499 (cond
yuuji@0 500 ((null begin)
yuuji@0 501 (message "I think it is not LaTeX sequence."))
yuuji@0 502 (t
yuuji@0 503 (let* ((pattern (buffer-substring begin end))
yuuji@0 504 (all-table (append section-table user-section-table
yuuji@0 505 article-table user-article-table
yuuji@0 506 env-table user-env-table
yuuji@0 507 singlecmd-table user-singlecmd-table))
yuuji@0 508 ;; First,
yuuji@0 509 ;; search completion without backslash.
yuuji@0 510 (completion (try-completion pattern all-table nil)))
yuuji@0 511 (if
yuuji@0 512 (eq completion nil)
yuuji@0 513 ;; Next,
yuuji@0 514 ;; search completion with backslash
yuuji@0 515 (setq completion
yuuji@0 516 (try-completion (buffer-substring (1- begin) end)
yuuji@0 517 all-table nil)
yuuji@0 518 begin (1- begin)))
yuuji@0 519 (cond
yuuji@0 520 ((null completion)
yuuji@0 521 (message (concat "Can't find completion for '" pattern "'"))
yuuji@0 522 (ding))
yuuji@0 523 ((eq completion t) (message "Sole completion."))
yuuji@0 524 ((not (string= completion pattern))
yuuji@0 525 (kill-region begin end)
yuuji@0 526 (insert completion)
yuuji@0 527 )
yuuji@0 528 (t
yuuji@0 529 (message "Making completion list...")
yuuji@0 530 (with-output-to-temp-buffer "*Help*"
yuuji@0 531 (display-completion-list
yuuji@0 532 (all-completions pattern all-table))) )
yuuji@0 533 ))))))
yuuji@0 534 )
yuuji@0 535
yuuji@0 536 (defun YaTeX-insert-quote ()
yuuji@0 537 (interactive)
yuuji@0 538 (insert
yuuji@0 539 (cond
yuuji@0 540 ((= (preceding-char) ?\\ ) ?\")
yuuji@0 541 ((= (preceding-char) ?\( ) ?\")
yuuji@0 542 ((= (preceding-char) 32) "``")
yuuji@0 543 ((= (preceding-char) 9) "``")
yuuji@0 544 ((= (preceding-char) ?\n) "``")
yuuji@0 545 ((bobp) "``")
yuuji@0 546 (t "''")
yuuji@0 547 )))
yuuji@0 548
yuuji@0 549
yuuji@0 550 (defun YaTeX-insert-braces-region (beg end)
yuuji@0 551 (interactive "r")
yuuji@0 552 (save-excursion
yuuji@0 553 (goto-char end)
yuuji@0 554 (insert "}")
yuuji@0 555 (goto-char beg)
yuuji@0 556 (insert "{"))
yuuji@0 557 )
yuuji@0 558
yuuji@0 559 (defun YaTeX-insert-braces ()
yuuji@0 560 (interactive)
yuuji@0 561 (insert "{}")
yuuji@0 562 (forward-char -1)
yuuji@0 563 )
yuuji@0 564
yuuji@0 565 (defun YaTeX-insert-dollar ()
yuuji@0 566 (interactive)
yuuji@0 567 (insert "$$")
yuuji@0 568 (forward-char -1)
yuuji@0 569 )
yuuji@0 570
yuuji@0 571 (defun YaTeX-insert-string (s)
yuuji@0 572 (insert s)
yuuji@0 573 )
yuuji@0 574
yuuji@0 575 (defun YaTeX-version ()
yuuji@0 576 "Return string of the version of running YaTeX."
yuuji@0 577 (interactive)
yuuji@0 578 (message
yuuji@1 579 (concat "Yet Another TeX mode u–ì’¹v Revision "
yuuji@0 580 YaTeX-revision-number))
yuuji@0 581 )
yuuji@0 582
yuuji@4 583 (defun YaTeX-typeset-sentinel (proc mes)
yuuji@0 584 (cond ((null (buffer-name (process-buffer proc)))
yuuji@0 585 ;; buffer killed
yuuji@0 586 (set-process-buffer proc nil))
yuuji@0 587 ((memq (process-status proc) '(signal exit))
yuuji@0 588 (let* ((obuf (current-buffer)))
yuuji@0 589 ;; save-excursion isn't the right thing if
yuuji@0 590 ;; process-buffer is current-buffer
yuuji@0 591 (unwind-protect
yuuji@0 592 (progn
yuuji@4 593 ;; Write something in *typesetting* and hack its mode line
yuuji@0 594 (set-buffer (process-buffer proc))
yuuji@0 595 (goto-char (point-max))
yuuji@4 596 (insert ?\n "jlatex typesetting " mes)
yuuji@0 597 (forward-char -1)
yuuji@0 598 (insert " at "
yuuji@0 599 (substring (current-time-string) 0 -5))
yuuji@0 600 (insert "\n * Hit any key to return * ")
yuuji@0 601 (forward-char 1)
yuuji@0 602 (setq mode-line-process
yuuji@0 603 (concat ": "
yuuji@0 604 (symbol-name (process-status proc))))
yuuji@0 605 ;; If buffer and mode line will show that the process
yuuji@0 606 ;; is dead, we can delete it now. Otherwise it
yuuji@0 607 ;; will stay around until M-x list-processes.
yuuji@0 608 (delete-process proc)
yuuji@0 609 )
yuuji@4 610 (setq YaTeX-typesetting-process nil)
yuuji@0 611 ;; Force mode line redisplay soon
yuuji@0 612 (set-buffer-modified-p (buffer-modified-p))
yuuji@0 613 )
yuuji@0 614 (set-buffer obuf)
yuuji@0 615 )))
yuuji@0 616 )
yuuji@0 617
yuuji@4 618 (defvar YaTeX-typesetting-process nil
yuuji@0 619 "Process identifier for jlatex"
yuuji@0 620 )
yuuji@0 621
yuuji@4 622 (defun YaTeX-typeset ()
yuuji@4 623 "Execute jlatex (or other) to LaTeX typeset."
yuuji@0 624 (interactive)
yuuji@4 625 (if YaTeX-typesetting-process
yuuji@4 626 (if (eq (process-status YaTeX-typesetting-process) 'run)
yuuji@4 627 (progn (interrupt-process YaTeX-typesetting-process)
yuuji@0 628 (sit-for 1)
yuuji@4 629 (delete-process YaTeX-typesetting-process))
yuuji@0 630 nil) nil)
yuuji@0 631 ; (compile1 (concat tex-command " " (buffer-name))
yuuji@4 632 ; "TeX error" "*TeX typesetting*")
yuuji@4 633 (setq YaTeX-typesetting-process nil)
yuuji@0 634 (if (eq system-type 'ms-dos) ;if MS-DOS
yuuji@4 635 (with-output-to-temp-buffer "*YaTeX-typesetting*"
yuuji@0 636 (message (concat "Compiling " (buffer-name) "..."))
yuuji@1 637 (YaTeX-put-nonstopmode)
yuuji@1 638 (basic-save-buffer)
yuuji@1 639 (call-process shell-file-name
yuuji@1 640 nil
yuuji@4 641 "*YaTeX-typesetting*" nil
yuuji@1 642 "/c" (YaTeX-get-latex-command))
yuuji@1 643 (YaTeX-remove-nonstopmode))
yuuji@4 644 (setq YaTeX-typesetting-process ;if UNIX
yuuji@4 645 (with-output-to-temp-buffer "*YaTeX-typesetting*"
yuuji@1 646 (basic-save-buffer)
yuuji@4 647 (start-process "LaTeX" "*YaTeX-typesetting*" shell-file-name "-c"
yuuji@1 648 (YaTeX-get-latex-command))
yuuji@0 649 ))
yuuji@4 650 (set-process-sentinel YaTeX-typesetting-process 'YaTeX-typeset-sentinel))
yuuji@0 651 (setq current-TeX-buffer (buffer-name))
yuuji@0 652 (other-window 1)
yuuji@4 653 (use-local-map YaTeX-typesetting-mode-map)
yuuji@0 654 (set-kanji-process-code YaTeX-kanji-code)
yuuji@0 655 (message "Type SPC to continue.")
yuuji@0 656 (goto-char (point-max))
yuuji@0 657 (sit-for 30)
yuuji@0 658 (read-char) ;hit any key
yuuji@4 659 (if (not (= (window-start) (point-min)))
yuuji@4 660 (while (eq (point) (point-max))
yuuji@4 661 (scroll-down 1)))
yuuji@0 662 (other-window -1)
yuuji@0 663 )
yuuji@0 664
yuuji@0 665 (defun YaTeX-preview (preview-command preview-file)
yuuji@0 666 "Execute xdvi (or other) to tex-preview."
yuuji@0 667 (interactive
yuuji@0 668 (list (read-string "Preview command: " dvi2-command)
yuuji@0 669 (read-string "Prefiew file[.dvi]: "
yuuji@3 670 ;;(substring (buffer-name) 0 -4)
yuuji@3 671 (YaTeX-get-preview-file-name) ;ver 1.31
yuuji@0 672 )))
yuuji@0 673 (setq dvi2-command preview-command)
yuuji@0 674 (with-output-to-temp-buffer "*dvi-preview*"
yuuji@0 675 (if (eq system-type 'ms-dos)
yuuji@0 676 (progn (send-string-to-terminal "\e[2J") ;if MS-DOS
yuuji@0 677 (call-process shell-file-name "con" "*dvi-preview*" nil
yuuji@0 678 "/c " dvi2-command preview-file)
yuuji@0 679 (redraw-display))
yuuji@0 680 (start-process "xdvi" "*dvi-preview*" shell-file-name "-c"
yuuji@0 681 (concat dvi2-command " " preview-file)) ;if UNIX
yuuji@0 682 (message (concat "Starting " dvi2-command " to preview " preview-file)))
yuuji@0 683 )
yuuji@0 684 )
yuuji@0 685
yuuji@0 686 (defun YaTeX-prev-error ()
yuuji@0 687 "Visit previous error. The reason why not NEXT-error is to
yuuji@0 688 avoid make confliction of line numbers by editing."
yuuji@0 689 (interactive)
yuuji@0 690 (setq cur-buf (buffer-name)
yuuji@0 691 YaTeX-error-line nil)
yuuji@4 692 (if (null (get-buffer "*YaTeX-typesetting*"))
yuuji@4 693 (message "There is no output buffer of typesetting.")
yuuji@4 694 (pop-to-buffer "*YaTeX-typesetting*")
yuuji@0 695 (if (eq system-type 'ms-dos)
yuuji@0 696 (if (search-backward latex-dos-emergency-message nil t)
yuuji@0 697 (progn (goto-char (point-max))
yuuji@0 698 (setq error-regexp latex-error-regexp))
yuuji@0 699 (beginning-of-line)
yuuji@0 700 (forward-char -1)
yuuji@0 701 (setq error-regexp latex-warning-regexp))
yuuji@4 702 (if YaTeX-typesetting-process ; if jlatex on UNIX
yuuji@4 703 (if (eq (process-status YaTeX-typesetting-process) 'run)
yuuji@0 704 (progn
yuuji@0 705 (goto-char (point-max))
yuuji@0 706 (setq error-regexp latex-error-regexp)))
yuuji@0 707 (beginning-of-line)
yuuji@0 708 (setq error-regexp latex-warning-regexp)))
yuuji@0 709 (if (re-search-backward error-regexp nil t)
yuuji@0 710 (save-restriction
yuuji@0 711 (set-mark-command nil)
yuuji@0 712 (end-of-line)
yuuji@0 713 (narrow-to-region (point) (mark))
yuuji@0 714 (goto-char (point-min))
yuuji@0 715 (re-search-forward "[0-9]")
yuuji@0 716 (forward-char -1)
yuuji@0 717 (set-mark (point))
yuuji@1 718 (skip-chars-forward "0-9")
yuuji@0 719 (narrow-to-region (point) (mark))
yuuji@0 720 (goto-char (point-min))
yuuji@0 721 (setq YaTeX-error-line (read (current-buffer))))
yuuji@0 722 (message "No more error on %s" cur-buf)
yuuji@0 723 (ding)
yuuji@0 724 )
yuuji@0 725 (other-window -1)
yuuji@0 726 (switch-to-buffer cur-buf)
yuuji@0 727 (if (null YaTeX-error-line)
yuuji@0 728 nil
yuuji@0 729 (goto-line YaTeX-error-line)
yuuji@0 730 (message "latex error or warning at line: %d" YaTeX-error-line)
yuuji@0 731 (other-window 1)
yuuji@0 732 (skip-chars-backward "[0-9]")
yuuji@0 733 (recenter (/ (window-height) 2))
yuuji@0 734 (sit-for 3)
yuuji@0 735 (forward-line -1)
yuuji@0 736 (other-window -1)
yuuji@0 737 ))
yuuji@0 738 )
yuuji@0 739
yuuji@0 740 (defun YaTeX-jump-error-line ()
yuuji@0 741 "Jump corresponding line on latex command's error message."
yuuji@0 742 (interactive)
yuuji@0 743 (let ((end (progn (end-of-line) (point)))
yuuji@0 744 (begin (progn (beginning-of-line)(point))))
yuuji@0 745 (if (null (re-search-forward "l[ ines]*\\.*[1-9][0-9]*" end t))
yuuji@0 746 (message "No line number expression")
yuuji@0 747 (goto-char (match-beginning 0))
yuuji@0 748 (re-search-forward "[1-9][0-9]*" end t)
yuuji@0 749 (save-restriction
yuuji@0 750 (narrow-to-region (match-beginning 0) (match-end 0))
yuuji@0 751 (goto-char (point-min))
yuuji@0 752 (let ((error-line (read (current-buffer))))
yuuji@0 753 (other-window -1)
yuuji@0 754 (switch-to-buffer current-TeX-buffer)
yuuji@0 755 (goto-line error-line)))))
yuuji@0 756 )
yuuji@0 757
yuuji@0 758 (defun YaTeX-view-error ()
yuuji@0 759 (interactive)
yuuji@0 760 (other-window 1)
yuuji@0 761 (goto-char (point-max))
yuuji@0 762 (other-window -1)
yuuji@0 763 )
yuuji@0 764
yuuji@1 765 (defun YaTeX-put-nonstopmode ()
yuuji@1 766 (if (boundp 'YaTeX-need-nonstop)
yuuji@1 767 (if (re-search-backward "\\nonstopmode{}" (point-min) t)
yuuji@1 768 nil ;if already written in text then do nothing
yuuji@1 769 (save-excursion
yuuji@1 770 (goto-char (point-min))
yuuji@1 771 (insert "\\nonstopmode{}%_YaTeX_%\n")))
yuuji@1 772 )
yuuji@1 773 )
yuuji@1 774
yuuji@1 775 (defun YaTeX-remove-nonstopmode ()
yuuji@1 776 (if (boundp 'YaTeX-need-nonstop) ;for speed
yuuji@1 777 (save-excursion
yuuji@1 778 (goto-char (point-min))
yuuji@1 779 (forward-line 1)
yuuji@1 780 (narrow-to-region (point-min) (point))
yuuji@1 781 (goto-char (point-min))
yuuji@1 782 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$")
yuuji@1 783 (widen)))
yuuji@1 784 )
yuuji@1 785
yuuji@4 786 (defun YaTeX-typeset-menu ()
yuuji@4 787 "Typeset, preview, visit error and miscellaneous convinient menu."
yuuji@4 788 (interactive)
yuuji@4 789 (message "J)latex P)review V)iewerror")
yuuji@4 790 (let ((c (read-char)))
yuuji@4 791 (cond
yuuji@4 792 ((= c ?j) (YaTeX-typeset))
yuuji@4 793 ((= c ?p) (call-interactively 'YaTeX-preview))
yuuji@4 794 ((= c ?v) (YaTeX-view-error))
yuuji@4 795 ((= c ?b) (YaTeX-insert-string "\\"))))
yuuji@4 796 )
yuuji@4 797
yuuji@3 798 (defun YaTeX-get-preview-file-name ()
yuuji@3 799 "Get file name to preview by inquiring YaTeX-get-latex-command"
yuuji@3 800 (let* ((latex-cmd (YaTeX-get-latex-command))
yuuji@3 801 (fname (substring latex-cmd (1+ (rindex latex-cmd ? ))))
yuuji@3 802 (period))
yuuji@3 803 (if (eq fname "")
yuuji@3 804 (setq fname (substring (buffer-name) 0 -4))
yuuji@3 805 (setq period (rindex fname ?.))
yuuji@3 806 (setq fname (substring fname 0 (if (eq -1 period) nil period)))
yuuji@3 807 ))
yuuji@3 808 )
yuuji@3 809
yuuji@1 810 (defun YaTeX-get-latex-command ()
yuuji@1 811 "Specify the latex-command name and its argument.
yuuji@1 812 If there is a line which begins by string: \"%#!\", the following
yuuji@1 813 strings are assumed to be the latex-command and arguments. The
yuuji@1 814 default value of latex-command is:
yuuji@1 815 tex-command (buffer-name)
yuuji@1 816 and if you write \"%#!jlatex\" in the beginning of certain line.
yuuji@1 817 \"jlatex \" (buffer-name)
yuuji@1 818 will be the latex-command,
yuuji@1 819 and you write \"%#!jlatex main.tex\"
yuuji@1 820 \"jlatex main.tex\"
yuuji@1 821 will be given to the shell."
yuuji@1 822 (let*
yuuji@1 823 ((default-command
yuuji@1 824 (concat tex-command " " (buffer-name)))) ;default value
yuuji@1 825 (save-excursion
yuuji@1 826 (goto-char (point-min))
yuuji@1 827 (if (null (re-search-forward "^%#!" (point-max) t))
yuuji@1 828 default-command
yuuji@1 829 (skip-chars-forward "%#! ")
yuuji@4 830 (if (eolp)1z
yuuji@1 831 default-command
yuuji@1 832 (let ((s (point)))
yuuji@1 833 (skip-chars-forward "A-z") ;Skip command name
yuuji@1 834 ;(setq YaTeX-latex-command (buffer-substring s (point)))
yuuji@1 835 (if (eolp) ;Only change command name
yuuji@1 836 (concat (buffer-substring s (point)) " " (buffer-name))
yuuji@1 837 (end-of-line) ;Change entire command name
yuuji@1 838 (buffer-substring s (point)) ;including arguments.
yuuji@1 839 ))
yuuji@1 840 ))))
yuuji@1 841 )
yuuji@1 842
yuuji@3 843 (defun YaTeX-goto-corresponding-environment ()
yuuji@3 844 "Go to corresponding begin/end enclosure."
yuuji@3 845 (interactive)
yuuji@4 846 (if (not (YaTeX-on-begin-end-p))
yuuji@3 847 (error "No environment declaration"))
yuuji@4 848 (let ((p (match-end 0) env)
yuuji@3 849 (m0 (match-beginning 0))
yuuji@3 850 (m1 (match-beginning 1))
yuuji@3 851 (m2 (match-beginning 2)))
yuuji@4 852 (if (not
yuuji@4 853 (save-excursion
yuuji@4 854 (goto-char p)
yuuji@4 855 (search-forward "}" (point-end-of-line) t)))
yuuji@3 856 (error "Unterminated brackets for begin/end"))
yuuji@3 857 (setq env (buffer-substring p (match-beginning 0))) ;get current env
yuuji@3 858 (cond
yuuji@3 859 ((equal m0 m1) ;if begin{xxx}
yuuji@4 860 (search-forward (concat "end{" env "}")))
yuuji@3 861 ((equal m0 m2) ;if end{xxx}
yuuji@4 862 (search-backward (concat "begin{" env "}")))
yuuji@3 863 )
yuuji@3 864 (beginning-of-line)
yuuji@3 865 );let
yuuji@3 866 )
yuuji@3 867
yuuji@4 868 (defun YaTeX-comment-region ()
yuuji@4 869 "Comment out region by '%'. If you call this function on the 'begin{}' or
yuuji@4 870 'end{}' line, it comments out whole environment"
yuuji@4 871 (interactive)
yuuji@4 872 (if (not (YaTeX-on-begin-end-p))
yuuji@4 873 (comment-region YaTeX-comment-prefix)
yuuji@4 874 (YaTeX-comment-uncomment-env 'comment-region))
yuuji@4 875 )
yuuji@4 876
yuuji@4 877 (defun YaTeX-uncomment-region ()
yuuji@4 878 "Uncomment out region by '%'."
yuuji@4 879 (interactive)
yuuji@4 880 (if (not (YaTeX-on-begin-end-p))
yuuji@4 881 (uncomment-region YaTeX-comment-prefix)
yuuji@4 882 (YaTeX-comment-uncomment-env 'uncomment-region))
yuuji@4 883 )
yuuji@4 884
yuuji@4 885 (defun YaTeX-comment-uncomment-env (func)
yuuji@4 886 "Comment or uncomment out one LaTeX environment switching function by FUNC."
yuuji@4 887 (save-excursion
yuuji@4 888 (if (eq (match-beginning 0) (match-beginning 2)) ; if on the '\end{}' line
yuuji@4 889 (YaTeX-goto-corresponding-environment)) ; goto '\begin{}' line
yuuji@4 890 (beginning-of-line)
yuuji@4 891 (push-mark)
yuuji@4 892 (YaTeX-goto-corresponding-environment)
yuuji@4 893 (forward-line 1)
yuuji@4 894 (funcall func YaTeX-comment-prefix t) ; t makes uncomment once
yuuji@4 895 (pop-mark)
yuuji@4 896 )
yuuji@4 897 )
yuuji@4 898
yuuji@4 899 (defun YaTeX-mark-environment ()
yuuji@4 900 "Not implemented yet."
yuuji@4 901 )
yuuji@4 902
yuuji@4 903 (defun YaTeX-on-begin-end-p ()
yuuji@4 904 (save-excursion
yuuji@4 905 (beginning-of-line)
yuuji@4 906 (re-search-forward "\\(begin{\\)\\|\\(end{\\)" (point-end-of-line) t))
yuuji@4 907 )
yuuji@4 908
yuuji@3 909 (defun YaTeX-comment-paragraph ()
yuuji@3 910 "Comment out current paragraph."
yuuji@3 911 (interactive)
yuuji@3 912 (save-excursion
yuuji@4 913 (if (YaTeX-on-begin-end-p)
yuuji@4 914 (progn
yuuji@4 915 (beginning-of-line)
yuuji@4 916 (insert YaTeX-comment-prefix)
yuuji@4 917 (YaTeX-goto-corresponding-environment)
yuuji@4 918 (beginning-of-line)
yuuji@4 919 (insert YaTeX-comment-prefix))
yuuji@4 920 (mark-paragraph)
yuuji@4 921 (if (not (bobp)) (forward-line 1))
yuuji@4 922 (comment-region "%")))
yuuji@3 923 )
yuuji@3 924
yuuji@3 925 (defun YaTeX-uncomment-paragraph ()
yuuji@3 926 "Uncomment current paragraph."
yuuji@3 927 (interactive)
yuuji@3 928 (save-excursion
yuuji@4 929 (if (YaTeX-on-begin-end-p)
yuuji@4 930 (progn
yuuji@4 931 (YaTeX-remove-prefix YaTeX-comment-prefix t)
yuuji@4 932 (YaTeX-goto-corresponding-environment)
yuuji@4 933 (YaTeX-remove-prefix YaTeX-comment-prefix t))
yuuji@4 934 (let ((prefix fill-prefix))
yuuji@4 935 (setq fill-prefix "")
yuuji@4 936 (mark-paragraph)
yuuji@4 937 (if (not (bobp)) (forward-line 1))
yuuji@4 938 (uncomment-region "%")
yuuji@4 939 (setq fill-prefix prefix))))
yuuji@4 940 )
yuuji@4 941
yuuji@4 942 (defun YaTeX-remove-prefix (prefix &optional once)
yuuji@4 943 "Remove prefix on current line so far as prefix detected. But
yuuji@4 944 optional argument ONCE makes deletion once."
yuuji@4 945 (interactive "sPrefix:")
yuuji@4 946 (beginning-of-line)
yuuji@4 947 (while (re-search-forward (concat "^" prefix) (point-end-of-line) t)
yuuji@4 948 (replace-match "")
yuuji@4 949 (if once (end-of-line)))
yuuji@3 950 )
yuuji@3 951
yuuji@0 952 (defun YaTeX-read-user-completion-table ()
yuuji@0 953 "Append user completion table of LaTeX word"
yuuji@0 954 (message "Loading personal completion table")
yuuji@0 955 (let ((user-table (expand-file-name YaTeX-user-completion-table)))
yuuji@0 956 (if (file-exists-p user-table)
yuuji@0 957 (load-file user-table)
yuuji@0 958 (message "Personal completion table not found."))
yuuji@0 959 ))
yuuji@0 960
yuuji@0 961 (defun YaTeX-save-table ()
yuuji@0 962 "Save personal completion table as dictionary."
yuuji@0 963 (interactive)
yuuji@4 964 (if (not YaTeX-user-table-modified)
yuuji@4 965 nil
yuuji@4 966 (message "Saving user table in %s" YaTeX-user-completion-table)
yuuji@4 967 (find-file (expand-file-name YaTeX-user-completion-table))
yuuji@4 968 (erase-buffer)
yuuji@4 969 ;; (prin1-to-string user-section-table)
yuuji@4 970 (insert "(setq user-section-table '(\n")
yuuji@4 971 (mapcar '(lambda (s)
yuuji@4 972 (insert (prin1-to-string s))
yuuji@4 973 (insert "\n"))
yuuji@4 974 user-section-table)
yuuji@4 975 (insert "))\n\n")
yuuji@4 976
yuuji@4 977 (insert "(setq user-article-table '(\n")
yuuji@4 978 (mapcar '(lambda (s)
yuuji@4 979 (insert (prin1-to-string s))
yuuji@4 980 (insert "\n"))
yuuji@4 981 user-article-table)
yuuji@4 982 (insert "))\n\n")
yuuji@4 983
yuuji@4 984 (insert "(setq user-env-table '(\n")
yuuji@4 985 (mapcar '(lambda (s)
yuuji@4 986 (insert (prin1-to-string s))
yuuji@4 987 (insert "\n"))
yuuji@4 988 user-env-table)
yuuji@4 989 (insert "))\n\n")
yuuji@4 990
yuuji@4 991 (insert "(setq user-fontsize-table '(\n")
yuuji@4 992 (mapcar '(lambda (s)
yuuji@4 993 (insert (prin1-to-string s))
yuuji@4 994 (insert "\n"))
yuuji@4 995 user-fontsize-table)
yuuji@4 996 (insert "))\n\n")
yuuji@4 997
yuuji@4 998 (insert "(setq user-singlecmd-table '(\n")
yuuji@4 999 (mapcar '(lambda (s)
yuuji@4 1000 (insert (prin1-to-string s))
yuuji@4 1001 (insert "\n"))
yuuji@4 1002 user-singlecmd-table)
yuuji@4 1003 (insert "))\n")
yuuji@4 1004
yuuji@4 1005 (basic-save-buffer)
yuuji@4 1006 (kill-buffer (current-buffer))
yuuji@4 1007 (message "")
yuuji@4 1008 (setq YaTeX-user-table-modified nil))
yuuji@0 1009 )
yuuji@0 1010
yuuji@3 1011 ;; --------------- General sub functions ---------------
yuuji@3 1012
yuuji@3 1013 ;(defun index (string char)
yuuji@3 1014 ; (let ((pos 0)(len (1- (length string)))(index -1))
yuuji@3 1015 ; (while (<= pos len)
yuuji@3 1016 ; (cond
yuuji@3 1017 ; ((= (aref string pos) char)
yuuji@3 1018 ; (setq index pos) (setq pos len))
yuuji@3 1019 ; (t (setq pos (1+ pos))))
yuuji@3 1020 ; )
yuuji@3 1021 ; index)
yuuji@3 1022 ;)
yuuji@3 1023
yuuji@3 1024 (defun rindex (string char)
yuuji@3 1025 (let ((pos (1- (length string)))(index -1))
yuuji@3 1026 (while (>= pos 0)
yuuji@3 1027 (cond
yuuji@3 1028 ((= (aref string pos) char)
yuuji@3 1029 (setq index pos) (setq pos -1))
yuuji@3 1030 (t (setq pos (1- pos))))
yuuji@3 1031 )
yuuji@3 1032 index)
yuuji@3 1033 )
yuuji@3 1034
yuuji@3 1035 (defun point-beginning-of-line ()
yuuji@3 1036 (save-excursion (beginning-of-line)(point))
yuuji@3 1037 )
yuuji@3 1038
yuuji@3 1039 (defun point-end-of-line ()
yuuji@3 1040 (save-excursion (end-of-line)(point))
yuuji@3 1041 )
yuuji@3 1042
yuuji@0 1043 (defun append-to-hook (hook hook-list)
yuuji@0 1044 "Add hook-list to certain emacs's hook correctly.
yuuji@0 1045 Argument hook-list is the list of function int the form to be called
yuuji@0 1046 Call this function with argument as next example,
yuuji@0 1047 (append-to-hook '((ding))) ;If one function to add.
yuuji@0 1048 (append-to-hook '((func1)(func2 arg)))."
yuuji@0 1049 (if (null (eval hook)) ;Not defined
yuuji@0 1050 (set hook
yuuji@0 1051 (append '(lambda ()) hook-list))
yuuji@0 1052 (if (listp (eval hook))
yuuji@0 1053 (if (eq (car (eval hook)) 'lambda) ;'(lambda () ....)
yuuji@0 1054 (set hook
yuuji@0 1055 (append (eval hook) hook-list))
yuuji@0 1056 (if (eq hook 'kill-emacs-hook) ;'(hook1 hook2 ...)
yuuji@0 1057 (progn ; this format is not
yuuji@0 1058 (ding) ; for kill-emacs-hook
yuuji@0 1059 (message
yuuji@0 1060 "Caution!! you have wrong format of kill-emacs-hook"))
yuuji@0 1061 (while (not (null hook-list))
yuuji@0 1062 (set hook
yuuji@0 1063 (append (eval hook) (car hook-list)))
yuuji@0 1064 (setq hook-list (cdr hook-list))))
yuuji@0 1065 )
yuuji@0 1066 (set hook ;'hook
yuuji@0 1067 (append '(lambda ())
yuuji@0 1068 (cons (list (eval hook)) hook-list)))))
yuuji@0 1069 )
yuuji@0 1070 (append-to-hook 'kill-emacs-hook '((YaTeX-save-table)))
yuuji@0 1071
yuuji@0 1072 ;--------------------------------- History ---------------------------------
yuuji@0 1073 ; Rev. | Date | Contents
yuuji@0 1074 ;------+----------+---------------------------------------------------------
yuuji@0 1075 ; 1.00 | 91/ 6/13 | Initial version.
yuuji@0 1076 ; | | Auto compilation & preview.
yuuji@0 1077 ; | | \section{}-type and \begin{}\end{}-type completion.
yuuji@0 1078 ; 1.01 | 91/ 6/14 | Add {\large ..} type completion (prefix+l).
yuuji@0 1079 ; 1.10 | 6/21 | Add learning feature of completion.
yuuji@0 1080 ; 1.11 | 6/27 | Simplify function begin-document etc. using lambda.
yuuji@0 1081 ; 1.12 | 7/ 6 | Modify YaTeX-make-section, show section-name.
yuuji@0 1082 ; 1.13 | 12/ 4 | Delete blank lines in make begin/end environment.
yuuji@0 1083 ; 1.20 | 12/ 5 | Saving learned completion into user file.
yuuji@0 1084 ; 1.21 | 12/ 6 | Add \maketitle type completion (prefix+m).
yuuji@0 1085 ; 1.22 | 12/30 | Port yatex.el to DOS(Demacs).
yuuji@0 1086 ; 1.23 | 92/ 1/ 8 | Enable latex and preview command on DOS.
yuuji@0 1087 ; 1.24 | 1/ 9 | Add YaTeX-save-table to kill-emacs-hook automatically.
yuuji@0 1088 ; 1.25 | 1/16 | YaTeX-do-completion (prefix+SPC) and argument
yuuji@3 1089 ; | | acceptable YaTeX-make-section works. Put region into
yuuji@0 1090 ; | | \begin...\end by calling YaTeX-make-begin-end with ARG.
yuuji@0 1091 ; | | append-kill-emacs-hook was revised to append-to-hook.
yuuji@0 1092 ; 1.26 | 1/18 | Region mode is added to {\large }. Default fontsize.
yuuji@3 1093 ; 1.27 | 1/21 | Default name on completing-read.
yuuji@1 1094 ; 1.28 | 7/ 2 | Add \nonstopmode{} automatically on DOS.
yuuji@1 1095 ; | 7/20 | %#! usage to specify latex command and its arguments.
yuuji@3 1096 ; | | Change default fill-prefix from TAB to null string.
yuuji@3 1097 ; 1.29 | 7/21 | Add YaTeX-end-environment.
yuuji@3 1098 ; 1.30 | 9/26 | Support project 30 lines(other than 25 lines).
yuuji@3 1099 ; 1.31 | 10/28 | Variable argument for previewer from %#! usage.
yuuji@4 1100 ; 1.32 | 11/16 | YaTeX-goto-corresponding-environment.
yuuji@4 1101 ; | | Comment out region/paragraph added.
yuuji@4 1102 ; 1.33 | 11/29 | Variable default value, on DOS and other OS.
yuuji@4 1103 ; | | make dvi2-command buffer local. Change the behavior of
yuuji@4 1104 ; | | comment out region/paragraph on the \begin{} or \end{}
yuuji@4 1105 ; | | line. Make faster YaTeX-end-environment. Add YaTeX-
yuuji@4 1106 ; | | define-key, YaTeX-define-begend-(region-)key.
yuuji@0 1107 ;------+----------+---------------------------------------------------------
yuuji@0 1108 ;
yuuji@0 1109 ;----------------------------- End of yatex.el -----------------------------