yatex

annotate yatexprc.el @ 23:b00c74813e56

Change the YaTeX-math-mode's prefix from `,' to `;'. Add YaTeX-apropos, YaTeX-what-column, YaTeX-beginning-of-environment, YaTeX-end-of-environment. Add variables YaTeX-default-pop-window-height, YaTeX-close-paren-always, YaTeX-no-begend-shortcut, YaTeX-auto-math-mode. Remove Greek letters from maketitle-type. Make YaTeX-inner-environment two times faster and more reliable. C-u for [prefix] k kills contents too. Fix the detection of the range of section-type commands when nested. Add \end{ completion. Add YaTeX-generate-simple. Refine documents(using Texinfo). %#REQUIRE for sub-preambles.
author yuuji
date Thu, 07 Jul 1994 16:37:05 +0000
parents adc2f1472409
children 23737513bf5f
rev   line source
yuuji@7 1 ;;; -*- Emacs-Lisp -*-
yuuji@7 2 ;;; YaTeX process handler.
yuuji@13 3 ;;; yatexprc.el
yuuji@14 4 ;;; (c )1993-1994 by HIROSE Yuuji.[yuuji@ae.keio.ac.jp]
yuuji@23 5 ;;; Last modified Fri Jul 1 02:44:32 1994 on figaro
yuuji@7 6 ;;; $Id$
yuuji@7 7
yuuji@7 8 (require 'yatex)
yuuji@7 9
yuuji@7 10 (defvar YaTeX-typeset-process nil
yuuji@7 11 "Process identifier for jlatex"
yuuji@7 12 )
yuuji@7 13 (defvar YaTeX-typeset-buffer "*YaTeX-typesetting*"
yuuji@7 14 "Process buffer for jlatex")
yuuji@7 15
yuuji@11 16 (defvar YaTeX-typeset-buffer-syntax nil
yuuji@11 17 "*Syntax table for typesetting buffer")
yuuji@11 18
yuuji@14 19 (defvar YaTeX-current-TeX-buffer nil
yuuji@14 20 "Keeps the buffer on which recently typeset run.")
yuuji@14 21
yuuji@11 22 (if YaTeX-typeset-buffer-syntax nil
yuuji@11 23 (setq YaTeX-typeset-buffer-syntax
yuuji@11 24 (make-syntax-table (standard-syntax-table)))
yuuji@11 25 (modify-syntax-entry ?\{ "w" YaTeX-typeset-buffer-syntax)
yuuji@11 26 (modify-syntax-entry ?\} "w" YaTeX-typeset-buffer-syntax)
yuuji@11 27 (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax)
yuuji@11 28 (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax)
yuuji@11 29 )
yuuji@11 30
yuuji@7 31 (defun YaTeX-typeset (command buffer)
yuuji@7 32 "Execute jlatex (or other) to LaTeX typeset."
yuuji@7 33 (interactive)
yuuji@12 34 (let ((window (selected-window)))
yuuji@12 35 (if (and YaTeX-typeset-process
yuuji@12 36 (eq (process-status YaTeX-typeset-process) 'run))
yuuji@12 37 ;; if tex command is halting.
yuuji@12 38 (YaTeX-kill-typeset-process YaTeX-typeset-process))
yuuji@12 39 (YaTeX-visit-main t);;execution directory
yuuji@14 40 ;;Select lower-most window if there are more than 2 windows and
yuuji@13 41 ;;typeset buffer not seen.
yuuji@12 42 (YaTeX-showup-buffer
yuuji@12 43 buffer (function (lambda (x) (nth 3 (window-edges x)))))
yuuji@12 44 (with-output-to-temp-buffer buffer
yuuji@13 45 (if YaTeX-dos ;if MS-DOS
yuuji@12 46 (progn
yuuji@23 47 (message (format "Calling `%s'..." command))
yuuji@12 48 (YaTeX-put-nonstopmode)
yuuji@12 49 (call-process shell-file-name
yuuji@12 50 nil buffer nil "/c" command)
yuuji@12 51 (YaTeX-remove-nonstopmode))
yuuji@12 52 (setq YaTeX-typeset-process ;if UNIX
yuuji@7 53 (start-process "LaTeX" buffer shell-file-name "-c"
yuuji@7 54 command))
yuuji@12 55 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
yuuji@14 56 (setq YaTeX-current-TeX-buffer (buffer-name))
yuuji@11 57 (select-window (get-buffer-window buffer))
yuuji@11 58 (use-local-map YaTeX-typesetting-mode-map)
yuuji@11 59 (set-syntax-table YaTeX-typeset-buffer-syntax)
yuuji@11 60 (setq mode-name "typeset")
yuuji@12 61 (if YaTeX-typeset-process ; if process is running (maybe on UNIX)
yuuji@11 62 (cond ((boundp 'MULE)
yuuji@11 63 (set-current-process-coding-system
yuuji@11 64 YaTeX-latex-message-code YaTeX-coding-system))
yuuji@11 65 ((boundp 'NEMACS)
yuuji@11 66 (set-kanji-process-code YaTeX-latex-message-code))))
yuuji@11 67 (goto-char (point-max))
yuuji@13 68 (if YaTeX-dos (message "Done.")
yuuji@23 69 (insert " ")
yuuji@12 70 (set-marker (process-mark YaTeX-typeset-process) (1- (point))))
yuuji@11 71 (if (bolp) (forward-line -1))
yuuji@11 72 (recenter -1)
yuuji@12 73 (select-window window))
yuuji@7 74 )
yuuji@7 75
yuuji@7 76 (defun YaTeX-typeset-sentinel (proc mes)
yuuji@7 77 (cond ((null (buffer-name (process-buffer proc)))
yuuji@7 78 ;; buffer killed
yuuji@7 79 (set-process-buffer proc nil))
yuuji@7 80 ((memq (process-status proc) '(signal exit))
yuuji@11 81 (let* ((obuf (current-buffer)) (pbuf (process-buffer proc))
yuuji@23 82 (pwin (get-buffer-window pbuf))
yuuji@11 83 (owin (selected-window)) win)
yuuji@7 84 ;; save-excursion isn't the right thing if
yuuji@7 85 ;; process-buffer is current-buffer
yuuji@7 86 (unwind-protect
yuuji@7 87 (progn
yuuji@7 88 ;; Write something in *typesetting* and hack its mode line
yuuji@23 89 (if pwin
yuuji@23 90 (select-window pwin)
yuuji@23 91 (set-buffer pbuf))
yuuji@23 92 ;;(YaTeX-showup-buffer pbuf nil t)
yuuji@7 93 (goto-char (point-max))
yuuji@23 94 (if pwin (recenter -3))
yuuji@7 95 (insert ?\n "latex typesetting " mes)
yuuji@7 96 (forward-char -1)
yuuji@7 97 (insert " at " (substring (current-time-string) 0 -5) "\n")
yuuji@7 98 (forward-char 1)
yuuji@7 99 (setq mode-line-process
yuuji@7 100 (concat ": "
yuuji@7 101 (symbol-name (process-status proc))))
yuuji@7 102 (message "latex typesetting done.")
yuuji@13 103 ;; If buffer and mode line shows that the process
yuuji@7 104 ;; is dead, we can delete it now. Otherwise it
yuuji@7 105 ;; will stay around until M-x list-processes.
yuuji@7 106 (delete-process proc)
yuuji@7 107 )
yuuji@7 108 (setq YaTeX-typesetting-process nil)
yuuji@7 109 ;; Force mode line redisplay soon
yuuji@7 110 (set-buffer-modified-p (buffer-modified-p))
yuuji@7 111 )
yuuji@11 112 (select-window owin)
yuuji@7 113 (set-buffer obuf))))
yuuji@7 114 )
yuuji@7 115
yuuji@7 116 (defvar YaTeX-texput-file "texput.tex"
yuuji@7 117 "*File name for temporary file of typeset-region."
yuuji@7 118 )
yuuji@7 119
yuuji@7 120 (defun YaTeX-typeset-region ()
yuuji@7 121 "Paste the region to the file `texput.tex' and execute jlatex (or other)
yuuji@7 122 to LaTeX typeset. The region is specified by the rule:
yuuji@7 123 (1)If keyword `%#BEGIN' is found in the upper direction from (point).
yuuji@7 124 (1-1)if the keyword `%#END' is found after `%#BEGIN',
yuuji@7 125 ->Assume the text between `%#BEGIN' and `%#END' as region.
yuuji@7 126 (1-2)if the keyword `%#END' is not found anywhere after `%#BEGIN',
yuuji@7 127 ->Assume the text after `%#BEGIN' as region.
yuuji@7 128 (2)If no `%#BEGIN' usage is found before the (point),
yuuji@7 129 ->Assume the text between current (point) and (mark) as region.
yuuji@7 130 DON'T forget to eliminate the `%#BEGIN/%#END' notation after editing
yuuji@7 131 operation to the region."
yuuji@7 132 (interactive)
yuuji@7 133 (save-excursion
yuuji@7 134 (let*
yuuji@7 135 ((end "") typeout ;Type out message that tells the method of cutting.
yuuji@7 136 (cmd (concat (YaTeX-get-latex-command nil) " " YaTeX-texput-file))
yuuji@23 137 (buffer (current-buffer)) opoint preamble (subpreamble "") main
yuuji@16 138 reg-begin reg-end)
yuuji@23 139
yuuji@23 140 (if (search-backward "%#BEGIN" nil t)
yuuji@16 141 (progn
yuuji@23 142 (setq typeout "--- Region from BEGIN to "
yuuji@23 143 end "the end of the buffer ---"
yuuji@16 144 reg-begin (match-end 0))
yuuji@23 145 (if (search-forward "%#END" nil t)
yuuji@16 146 (setq reg-end (match-beginning 0)
yuuji@23 147 end "END ---")
yuuji@16 148 (setq reg-end (point-max))))
yuuji@16 149 (setq typeout "=== Region from (point) to (mark) ===")
yuuji@16 150 (setq reg-begin (point) reg-end (mark)))
yuuji@23 151 (goto-char (point-min))
yuuji@23 152 (while (search-forward "%#REQUIRE" nil t)
yuuji@23 153 (setq subpreamble
yuuji@23 154 (concat subpreamble
yuuji@23 155 (cond
yuuji@23 156 ((eolp)
yuuji@23 157 (buffer-substring
yuuji@23 158 (match-beginning 0)
yuuji@23 159 (point-beginning-of-line)))
yuuji@23 160 (t (buffer-substring
yuuji@23 161 (match-end 0)
yuuji@23 162 (point-end-of-line))))
yuuji@23 163 "\n"))
yuuji@23 164 (goto-char (match-end 0)))
yuuji@7 165 (YaTeX-visit-main t)
yuuji@16 166 (setq main (current-buffer))
yuuji@7 167 (setq opoint (point))
yuuji@7 168 (goto-char (point-min))
yuuji@7 169 (setq
yuuji@7 170 preamble
yuuji@7 171 (if (re-search-forward "^[ ]*\\\\begin.*{document}" nil t)
yuuji@7 172 (buffer-substring (point-min) (match-end 0))
yuuji@7 173 (concat "\\documentstyle{" YaTeX-default-document-style "}\n"
yuuji@7 174 "\\begin{document}")))
yuuji@7 175 (goto-char opoint)
yuuji@7 176 ;;(set-buffer buffer) ;for clarity
yuuji@16 177 (set-buffer (find-file-noselect YaTeX-texput-file))
yuuji@16 178 ;;(find-file YaTeX-texput-file)
yuuji@7 179 (erase-buffer)
yuuji@7 180 (if YaTeX-need-nonstop
yuuji@7 181 (insert "\\nonstopmode{}\n"))
yuuji@23 182 (insert preamble "\n" subpreamble "\n")
yuuji@16 183 (insert-buffer-substring buffer reg-begin reg-end)
yuuji@7 184 (insert "\\typeout{" typeout end "}\n") ;Notice the selected method.
yuuji@7 185 (insert "\n\\end{document}\n")
yuuji@7 186 (basic-save-buffer)
yuuji@7 187 (kill-buffer (current-buffer))
yuuji@16 188 (set-buffer main) ;return to parent file or itself.
yuuji@7 189 (YaTeX-typeset cmd YaTeX-typeset-buffer)
yuuji@7 190 (put 'dvi2-command 'region t)))
yuuji@7 191 )
yuuji@7 192
yuuji@7 193 (defun YaTeX-typeset-buffer ()
yuuji@7 194 "Typeset whole buffer. If %#! usage says other buffer is main text,
yuuji@7 195 visit main buffer to confirm if its includeonly list contains current
yuuji@7 196 buffer's file. And if it doesn't contain editing text, ask user which
yuuji@13 197 action wants to be done, A:Add list, R:Replace list, %:comment-out list."
yuuji@7 198 (interactive)
yuuji@7 199 (YaTeX-save-buffers)
yuuji@7 200 (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.)))
yuuji@7 201 (mydir (file-name-directory (buffer-file-name)))
yuuji@7 202 (cmd (YaTeX-get-latex-command t)))
yuuji@7 203 (if (YaTeX-main-file-p) nil
yuuji@7 204 (save-excursion
yuuji@7 205 (YaTeX-visit-main t) ;search into main buffer
yuuji@7 206 (save-excursion
yuuji@7 207 (push-mark (point) t)
yuuji@7 208 (goto-char (point-min))
yuuji@7 209 (if (and (re-search-forward "^[ ]*\\\\begin{document}" nil t)
yuuji@7 210 (re-search-backward "^[ ]*\\\\includeonly{" nil t))
yuuji@7 211 (let*
yuuji@7 212 ((b (progn (skip-chars-forward "^{") (point)))
yuuji@7 213 (e (progn (skip-chars-forward "^}") (1+ (point))))
yuuji@7 214 (s (buffer-substring b e)) c
yuuji@7 215 (pardir (file-name-directory (buffer-file-name))))
yuuji@7 216 (if (string-match (concat "[{,/]" me "[,}]") s)
yuuji@7 217 nil ; Nothing to do when it's already in includeonly.
yuuji@7 218 (ding)
yuuji@7 219 (switch-to-buffer (current-buffer));Display this buffer.
yuuji@7 220 (setq
yuuji@7 221 me ;;Rewrite my name(me) to contain sub directory name.
yuuji@7 222 (concat
yuuji@7 223 (if (string-match pardir mydir) ;if mydir is child of main
yuuji@7 224 (substring mydir (length pardir)) ;cut absolute path
yuuji@7 225 mydir) ;else concat absolute path name.
yuuji@7 226 me))
yuuji@7 227 (message
yuuji@7 228 "`%s' is not in \\includeonly. A)dd R)eplace %%)comment? "
yuuji@7 229 me)
yuuji@7 230 (setq c (read-char))
yuuji@7 231 (cond
yuuji@7 232 ((= c ?a)
yuuji@7 233 (goto-char (1+ b))
yuuji@7 234 (insert me (if (string= s "{}") "" ",")))
yuuji@7 235 ((= c ?r)
yuuji@7 236 (delete-region (1+ b) (1- e)) (insert me))
yuuji@7 237 ((= c ?%)
yuuji@7 238 (beginning-of-line) (insert "%"))
yuuji@7 239 (t nil))
yuuji@7 240 (basic-save-buffer))))
yuuji@7 241 (exchange-point-and-mark))
yuuji@7 242 ))
yuuji@7 243 (YaTeX-typeset cmd YaTeX-typeset-buffer)
yuuji@7 244 (put 'dvi2-command 'region nil))
yuuji@7 245 )
yuuji@7 246
yuuji@16 247 (defvar YaTeX-call-command-history nil
yuuji@16 248 "Holds history list of YaTeX-call-command-on-file.")
yuuji@16 249 (put 'YaTeX-call-command-history 'no-default t)
yuuji@11 250 (defun YaTeX-call-command-on-file (base-cmd buffer)
yuuji@11 251 (YaTeX-save-buffers)
yuuji@11 252 (YaTeX-typeset
yuuji@16 253 (let ((minibufer-history-symbol 'YaTeX-call-command-history))
yuuji@16 254 (read-string "Call command: "
yuuji@16 255 (concat base-cmd " " (YaTeX-get-preview-file-name))))
yuuji@11 256 buffer)
yuuji@11 257 )
yuuji@11 258
yuuji@11 259 (defun YaTeX-bibtex-buffer (cmd)
yuuji@7 260 "Pass the bibliography data of editing file to bibtex."
yuuji@7 261 (interactive)
yuuji@7 262 (YaTeX-save-buffers)
yuuji@11 263 (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" )
yuuji@7 264 )
yuuji@7 265
yuuji@7 266 (defun YaTeX-kill-typeset-process (proc)
yuuji@7 267 "Kill process PROC after sending signal to PROC.
yuuji@7 268 PROC should be process identifier."
yuuji@7 269 (cond
yuuji@13 270 (YaTeX-dos
yuuji@7 271 (error "MS-DOS can't have concurrent process."))
yuuji@7 272 ((or (null proc) (not (eq (process-status proc) 'run)))
yuuji@7 273 (error "No typesetting process."))
yuuji@7 274 (t (interrupt-process proc)
yuuji@7 275 (delete-process proc)))
yuuji@7 276 )
yuuji@7 277
yuuji@7 278 (defun YaTeX-system (command buffer)
yuuji@7 279 "Execute some command on buffer. Not a official function."
yuuji@7 280 (save-excursion
yuuji@23 281 (YaTeX-showup-buffer
yuuji@23 282 buffer (function (lambda (x) (nth 3 (window-edges x)))))
yuuji@7 283 (with-output-to-temp-buffer buffer
yuuji@13 284 (if YaTeX-dos
yuuji@7 285 (call-process shell-file-name nil buffer nil "/c " command)
yuuji@13 286 (start-process "system" buffer shell-file-name "-c" command))))
yuuji@7 287 )
yuuji@7 288
yuuji@16 289 (defvar YaTeX-preview-command-history nil
yuuji@16 290 "Holds minibuffer history of preview command.")
yuuji@16 291 (put 'YaTeX-preview-command-history 'no-default t)
yuuji@16 292 (defvar YaTeX-preview-file-history nil
yuuji@16 293 "Holds minibuffer history of file to preview.")
yuuji@16 294 (put 'YaTeX-preview-file-history 'no-default t)
yuuji@7 295 (defun YaTeX-preview (preview-command preview-file)
yuuji@7 296 "Execute xdvi (or other) to tex-preview."
yuuji@7 297 (interactive
yuuji@16 298 (list
yuuji@16 299 (let ((minibuffer-history-symbol 'YaTeX-preview-command-history))
yuuji@16 300 (read-string "Preview command: " dvi2-command))
yuuji@16 301 (let ((minibuffer-history-symbol 'YaTeX-preview-file-history))
yuuji@16 302 (read-string "Preview file[.dvi]: "
yuuji@16 303 (if (get 'dvi2-command 'region)
yuuji@16 304 (substring YaTeX-texput-file
yuuji@16 305 0 (rindex YaTeX-texput-file ?.))
yuuji@16 306 (YaTeX-get-preview-file-name))
yuuji@16 307 ))))
yuuji@23 308 (setq dvi2-command preview-command) ;`dvi2command' is buffer local
yuuji@7 309 (save-excursion
yuuji@7 310 (YaTeX-visit-main t)
yuuji@23 311 (let ((pbuffer "*dvi-preview*"))
yuuji@23 312 (YaTeX-showup-buffer
yuuji@23 313 pbuffer (function (x) (nth 3 (window-edges x))))
yuuji@23 314 (with-output-to-temp-buffer pbuffer
yuuji@23 315 (if YaTeX-dos ;if MS-DOS
yuuji@23 316 (progn (send-string-to-terminal "\e[2J\e[>5h") ;CLS & hide cursor
yuuji@23 317 (call-process shell-file-name "con" "*dvi-preview*" nil
yuuji@23 318 "/c " preview-command preview-file)
yuuji@23 319 (send-string-to-terminal "\e[>5l") ;show cursor
yuuji@23 320 (redraw-display))
yuuji@23 321 (start-process "preview" "*dvi-preview*" shell-file-name "-c"
yuuji@23 322 (concat preview-command " " preview-file)) ;if UNIX
yuuji@23 323 (message
yuuji@23 324 (concat "Starting " preview-command
yuuji@23 325 " to preview " preview-file))))))
yuuji@7 326 )
yuuji@7 327
yuuji@7 328 (defun YaTeX-prev-error ()
yuuji@14 329 "Visit previous typeset error.
yuuji@14 330 To avoid making confliction of line numbers by editing, jump to
yuuji@14 331 error or warning lines in reverse order."
yuuji@7 332 (interactive)
yuuji@11 333 (let ((cur-buf (buffer-name)) (cur-win (selected-window))
yuuji@14 334 error-line typeset-win error-buffer error-win)
yuuji@7 335 (if (null (get-buffer YaTeX-typeset-buffer))
yuuji@14 336 (error "There is no typesetting buffer."))
yuuji@23 337 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
yuuji@14 338 (setq typeset-win (selected-window))
yuuji@14 339 (if (re-search-backward
yuuji@14 340 (concat "\\(" latex-error-regexp "\\)\\|\\("
yuuji@14 341 latex-warning-regexp "\\)")
yuuji@14 342 nil t)
yuuji@14 343 nil
yuuji@11 344 (select-window cur-win)
yuuji@14 345 (error "No more erros on %s" cur-buf))
yuuji@14 346 (goto-char (match-beginning 0))
yuuji@14 347 (skip-chars-forward "^0-9" (match-end 0))
yuuji@14 348 (setq error-line
yuuji@14 349 (string-to-int
yuuji@14 350 (buffer-substring
yuuji@14 351 (point)
yuuji@14 352 (progn (skip-chars-forward "0-9" (match-end 0)) (point))))
yuuji@14 353 error-buffer (YaTeX-get-error-file cur-buf)
yuuji@14 354 error-win (get-buffer-window error-buffer))
yuuji@14 355 (if (or (null error-line) (equal 0 error-line))
yuuji@14 356 (error "Can't detect error position."))
yuuji@14 357 (select-window cur-win)
yuuji@14 358 (cond
yuuji@14 359 (error-win (select-window error-win))
yuuji@14 360 ((eq (get-lru-window) typeset-win)
yuuji@14 361 (YaTeX-switch-to-buffer error-buffer))
yuuji@14 362 (t (select-window (get-lru-window))
yuuji@14 363 (YaTeX-switch-to-buffer error-buffer)))
yuuji@14 364 (setq error-win (selected-window))
yuuji@14 365 (goto-line error-line)
yuuji@14 366 (message "LaTeX %s in `%s' on line: %d."
yuuji@14 367 (if (match-beginning 1) "error" "warning")
yuuji@14 368 error-buffer error-line)
yuuji@14 369 (select-window typeset-win)
yuuji@14 370 (skip-chars-backward "0-9")
yuuji@14 371 (recenter (/ (window-height) 2))
yuuji@14 372 (sit-for 3)
yuuji@14 373 (goto-char (match-beginning 0))
yuuji@14 374 (select-window error-win))
yuuji@7 375 )
yuuji@7 376
yuuji@7 377 (defun YaTeX-jump-error-line ()
yuuji@13 378 "Jump to corresponding line on latex command's error message."
yuuji@7 379 (interactive)
yuuji@14 380 (let (error-line error-file error-buf)
yuuji@14 381 (save-excursion
yuuji@14 382 (beginning-of-line)
yuuji@14 383 (setq error-line (re-search-forward "l[ ines]*\\.\\([1-9][0-9]*\\)"
yuuji@14 384 (point-end-of-line) t)))
yuuji@14 385 (if (null error-line)
yuuji@14 386 (if (eobp) (insert (this-command-keys))
yuuji@14 387 (error "No line number expression."))
yuuji@7 388 (goto-char (match-beginning 0))
yuuji@14 389 (setq error-line (string-to-int
yuuji@14 390 (buffer-substring (match-beginning 1) (match-end 1)))
yuuji@14 391 error-file (YaTeX-get-error-file YaTeX-current-TeX-buffer)
yuuji@14 392 error-buf (YaTeX-switch-to-buffer error-file t))
yuuji@14 393 (if (null error-buf)
yuuji@14 394 (error "`%s' is not found in this directory." error-file))
yuuji@14 395 (YaTeX-showup-buffer error-buf nil t)
yuuji@14 396 (goto-line error-line)))
yuuji@7 397 )
yuuji@7 398
yuuji@7 399 (defun YaTeX-send-string ()
yuuji@7 400 "Send string to current typeset process."
yuuji@7 401 (interactive)
yuuji@7 402 (if (and (eq (process-status YaTeX-typeset-process) 'run)
yuuji@7 403 (>= (point) (process-mark YaTeX-typeset-process)))
yuuji@7 404 (let ((b (process-mark YaTeX-typeset-process))
yuuji@7 405 (e (point-end-of-line)))
yuuji@7 406 (goto-char b)
yuuji@7 407 (skip-chars-forward " \t" e)
yuuji@7 408 (setq b (point))
yuuji@7 409 (process-send-string
yuuji@7 410 YaTeX-typeset-process (concat (buffer-substring b e) "\n"))
yuuji@7 411 (goto-char e)
yuuji@7 412 (insert "\n")
yuuji@7 413 (set-marker (process-mark YaTeX-typeset-process) (point))
yuuji@7 414 (insert " "))
yuuji@7 415 (ding))
yuuji@7 416 )
yuuji@7 417
yuuji@7 418 (defun YaTeX-view-error ()
yuuji@7 419 (interactive)
yuuji@7 420 (if (null (get-buffer YaTeX-typeset-buffer))
yuuji@7 421 (message "No typeset buffer found.")
yuuji@11 422 (let ((win (selected-window)))
yuuji@23 423 (YaTeX-showup-buffer YaTeX-typeset-buffer nil t)
yuuji@11 424 (goto-char (point-max))
yuuji@23 425 (forward-line -1)
yuuji@11 426 (recenter -1)
yuuji@11 427 (select-window win)))
yuuji@7 428 )
yuuji@7 429
yuuji@7 430 (defun YaTeX-get-error-file (default)
yuuji@7 431 "Get current processing file from typesetting log."
yuuji@7 432 (save-excursion
yuuji@7 433 (let(s)
yuuji@7 434 (condition-case () (up-list -1)
yuuji@7 435 (error
yuuji@7 436 (let ((list 0) found)
yuuji@7 437 (while
yuuji@7 438 (and (<= list 0) (not found)
yuuji@7 439 (re-search-backward "\\((\\)\\|\\()\\)" nil t))
yuuji@7 440 (if (equal (match-beginning 0) (match-beginning 2)) ;close paren.
yuuji@7 441 (setq list (1- list)) ;open paren
yuuji@7 442 (setq list (1+ list))
yuuji@7 443 (if (= list 1)
yuuji@7 444 (if (looking-at "\\([^,{}%]+\.\\)tex\\|sty")
yuuji@7 445 (setq found t)
yuuji@7 446 (setq list (1- list)))))))))
yuuji@7 447 (setq s
yuuji@7 448 (buffer-substring
yuuji@7 449 (progn (forward-char 1) (point))
yuuji@7 450 (progn (skip-chars-forward "-A-Za-z0-9_/\.\\" (point-end-of-line))
yuuji@7 451 (point))))
yuuji@7 452 (if (string= "" s) default s)))
yuuji@7 453 )
yuuji@7 454
yuuji@7 455 (defun YaTeX-put-nonstopmode ()
yuuji@7 456 (if YaTeX-need-nonstop
yuuji@14 457 (if (re-search-backward "\\\\nonstopmode{}" (point-min) t)
yuuji@7 458 nil ;if already written in text then do nothing
yuuji@7 459 (save-excursion
yuuji@7 460 (YaTeX-visit-main t)
yuuji@7 461 (goto-char (point-min))
yuuji@7 462 (insert "\\nonstopmode{}%_YaTeX_%\n")))
yuuji@7 463 )
yuuji@7 464 )
yuuji@7 465
yuuji@7 466 (defun YaTeX-remove-nonstopmode ()
yuuji@7 467 (if YaTeX-need-nonstop ;for speed
yuuji@7 468 (save-excursion
yuuji@7 469 (YaTeX-visit-main t)
yuuji@7 470 (goto-char (point-min))
yuuji@7 471 (forward-line 1)
yuuji@7 472 (narrow-to-region (point-min) (point))
yuuji@7 473 (goto-char (point-min))
yuuji@7 474 (delete-matching-lines "^\\\\nonstopmode\\{\\}%_YaTeX_%$")
yuuji@7 475 (widen)))
yuuji@7 476 )
yuuji@7 477
yuuji@7 478 (defun YaTeX-get-preview-file-name ()
yuuji@7 479 "Get file name to preview by inquiring YaTeX-get-latex-command"
yuuji@7 480 (let* ((latex-cmd (YaTeX-get-latex-command t))
yuuji@7 481 (rin (rindex latex-cmd ? ))
yuuji@7 482 (fname (if (> rin -1) (substring latex-cmd (1+ rin)) ""))
yuuji@7 483 (period))
yuuji@7 484 (if (string= fname "")
yuuji@14 485 (setq fname (substring (file-name-nondirectory
yuuji@14 486 (buffer-file-name))
yuuji@14 487 0 -4))
yuuji@7 488 (setq period (rindex fname ?.))
yuuji@7 489 (setq fname (substring fname 0 (if (eq -1 period) nil period)))
yuuji@7 490 ))
yuuji@7 491 )
yuuji@7 492
yuuji@7 493 (defun YaTeX-get-latex-command (&optional switch)
yuuji@7 494 "Specify the latex-command name and its argument.
yuuji@14 495 If there is a line which begins with string: \"%#!\", the following
yuuji@7 496 strings are assumed to be the latex-command and arguments. The
yuuji@7 497 default value of latex-command is:
yuuji@14 498 tex-command FileName
yuuji@7 499 and if you write \"%#!jlatex\" in the beginning of certain line.
yuuji@14 500 \"jlatex \" FileName
yuuji@7 501 will be the latex-command,
yuuji@7 502 and you write \"%#!jlatex main.tex\" on some line and argument SWITCH
yuuji@14 503 is non-nil, then
yuuji@7 504 \"jlatex main.tex\"
yuuji@15 505
yuuji@7 506 will be given to the shell."
yuuji@15 507 (let (magic command target)
yuuji@15 508 (setq parent
yuuji@15 509 (cond
yuuji@15 510 (YaTeX-parent-file YaTeX-parent-file)
yuuji@15 511 (t (save-excursion
yuuji@15 512 (YaTeX-visit-main t)
yuuji@15 513 (file-name-nondirectory (buffer-file-name)))))
yuuji@15 514 magic (YaTeX-get-builtin "!"))
yuuji@15 515 (cond
yuuji@15 516 (magic
yuuji@15 517 (cond
yuuji@15 518 (switch (if (string-match "\\s " magic) magic
yuuji@15 519 (concat magic " " parent)))
yuuji@15 520 (t (concat (substring magic 0 (string-match "\\s " magic)) " "))))
yuuji@16 521 (t (concat tex-command " " (if switch parent)))))
yuuji@7 522 )
yuuji@7 523
yuuji@16 524 (defvar YaTeX-lpr-command-history nil
yuuji@16 525 "Holds command line history of YaTeX-lpr.")
yuuji@16 526 (put 'YaTeX-lpr-command-history 'no-default t)
yuuji@7 527 (defun YaTeX-lpr (arg)
yuuji@7 528 "Print out. If prefix arg ARG is non nil, call print driver without
yuuji@7 529 page range description."
yuuji@7 530 (interactive "P")
yuuji@23 531 (let*((cmd (or (YaTeX-get-builtin "LPR") dviprint-command-format))
yuuji@23 532 from to (lbuffer "*dvi-printing*"))
yuuji@7 533 (setq
yuuji@7 534 cmd
yuuji@7 535 (YaTeX-replace-format
yuuji@7 536 cmd "f"
yuuji@7 537 (if (or arg (not (string-match "%f" cmd)))
yuuji@7 538 ""
yuuji@7 539 (YaTeX-replace-format
yuuji@7 540 dviprint-from-format
yuuji@7 541 "b"
yuuji@7 542 (if (string=
yuuji@7 543 (setq from (read-string "From page(default 1): ")) "")
yuuji@7 544 "1" from))))
yuuji@7 545 )
yuuji@7 546 (setq
yuuji@7 547 cmd
yuuji@7 548 (YaTeX-replace-format
yuuji@7 549 cmd "t"
yuuji@7 550 (if (or arg (not (string-match "%t" cmd))
yuuji@7 551 (string=
yuuji@7 552 (setq to (read-string "To page(default none): ")) ""))
yuuji@7 553 ""
yuuji@7 554 (YaTeX-replace-format dviprint-to-format "e" to)))
yuuji@7 555 )
yuuji@16 556 (setq cmd
yuuji@16 557 (let ((minibuffer-history-symbol 'YaTeX-lpr-command-history))
yuuji@16 558 (read-string "Edit command line: "
yuuji@16 559 (format cmd (YaTeX-get-preview-file-name)))))
yuuji@7 560 (save-excursion
yuuji@7 561 (YaTeX-visit-main t) ;;change execution directory
yuuji@23 562 (YaTeX-showup-buffer
yuuji@23 563 lbuffer (function (lambda (x) (nth 3 (window-edges x)))))
yuuji@23 564 (with-output-to-temp-buffer lbuffer
yuuji@13 565 (if YaTeX-dos
yuuji@7 566 (call-process shell-file-name "con" "*dvi-printing*" nil
yuuji@7 567 "/c " cmd)
yuuji@7 568 (start-process "print" "*dvi-printing*" shell-file-name "-c" cmd)
yuuji@7 569 (message (concat "Starting " cmd " to printing "
yuuji@7 570 (YaTeX-get-preview-file-name))))
yuuji@7 571 )))
yuuji@7 572 )
yuuji@7 573
yuuji@7 574 (defun YaTeX-main-file-p ()
yuuji@7 575 "Return if current buffer is main LaTeX source."
yuuji@14 576 (cond
yuuji@14 577 ((YaTeX-get-builtin "!")
yuuji@15 578 (string-match (YaTeX-guess-parent (YaTeX-get-builtin "!")) (buffer-name)))
yuuji@14 579 (t
yuuji@14 580 (save-excursion
yuuji@14 581 (let ((latex-main-id (concat "^\\s *" YaTeX-ec-regexp "documentstyle")))
yuuji@14 582 (or (re-search-backward latex-main-id nil t)
yuuji@14 583 (re-search-forward latex-main-id nil t))))))
yuuji@7 584 )
yuuji@7 585
yuuji@7 586 (defun YaTeX-visit-main (&optional setbuf)
yuuji@15 587 "Switch buffer to main LaTeX source.
yuuji@15 588 Use set-buffer instead of switch-to-buffer if the optional second argument
yuuji@15 589 SETBUF is t(Use it only from Emacs-Lisp program)."
yuuji@7 590 (interactive)
yuuji@15 591 (let (b-in main-file)
yuuji@15 592 (if (setq b-in (YaTeX-get-builtin "!"))
yuuji@15 593 (setq main-file (YaTeX-guess-parent b-in)))
yuuji@14 594 (if YaTeX-parent-file
yuuji@23 595 (setq main-file ;;(get-file-buffer YaTeX-parent-file)
yuuji@23 596 YaTeX-parent-file))
yuuji@14 597 (if (YaTeX-main-file-p)
yuuji@7 598 (if (interactive-p) (message "I think this is main LaTeX source.") nil)
yuuji@7 599 (cond
yuuji@14 600 ((and (interactive-p) main-file (get-buffer-window main-file))
yuuji@14 601 (select-window (get-buffer-window main-file)))
yuuji@14 602 ((and main-file (YaTeX-switch-to-buffer main-file setbuf)))
yuuji@14 603 ((and main-file
yuuji@14 604 (file-exists-p (setq main-file (concat "../" main-file)))
yuuji@7 605 (y-or-n-p (concat (expand-file-name main-file)
yuuji@7 606 " is main file?:")))
yuuji@7 607 (YaTeX-switch-to-buffer main-file setbuf))
yuuji@14 608 (t (setq main-file (read-file-name "Enter your main text: " nil nil 1))
yuuji@14 609 (setq YaTeX-parent-file main-file)
yuuji@14 610 (find-file main-file))
yuuji@14 611 )))
yuuji@7 612 nil
yuuji@7 613 )
yuuji@7 614
yuuji@15 615
yuuji@15 616 (defun YaTeX-guess-parent (command-line)
yuuji@15 617 (setq command-line
yuuji@15 618 (if (string-match ".*\\s " command-line)
yuuji@15 619 (substring command-line (match-end 0))
yuuji@15 620 (file-name-nondirectory (buffer-file-name)))
yuuji@15 621 command-line
yuuji@15 622 (concat (if (string-match "\\(.*\\)\\." command-line)
yuuji@15 623 (substring command-line (match-beginning 1) (match-end 1))
yuuji@15 624 command-line)
yuuji@15 625 ".tex"))
yuuji@15 626 )
yuuji@15 627
yuuji@7 628 (defun YaTeX-visit-main-other-window ()
yuuji@7 629 "Switch to buffer main LaTeX source in other window."
yuuji@7 630 (interactive)
yuuji@7 631 (if (YaTeX-main-file-p) (message "I think this is main LaTeX source.")
yuuji@7 632 (YaTeX-switch-to-buffer-other-window
yuuji@7 633 (concat (YaTeX-get-preview-file-name) ".tex")))
yuuji@7 634 )
yuuji@7 635
yuuji@7 636 (defun YaTeX-get-builtin (key)
yuuji@7 637 "Read source built-in command of %# usage."
yuuji@7 638 (save-excursion
yuuji@7 639 (goto-char (point-min))
yuuji@15 640 (if (and (re-search-forward
yuuji@15 641 (concat "^" (regexp-quote (concat "%#" key))) nil t)
yuuji@7 642 (not (eolp)))
yuuji@7 643 (buffer-substring
yuuji@7 644 (progn (skip-chars-forward " " (point-end-of-line))(point))
yuuji@7 645 (point-end-of-line))
yuuji@7 646 nil))
yuuji@7 647 )
yuuji@7 648
yuuji@7 649 (defun YaTeX-save-buffers ()
yuuji@7 650 "Save buffers which is in yatex-mode."
yuuji@7 651 (basic-save-buffer)
yuuji@7 652 (save-excursion
yuuji@7 653 (mapcar '(lambda (buf)
yuuji@7 654 (set-buffer buf)
yuuji@7 655 (if (and (buffer-file-name buf)
yuuji@7 656 (eq major-mode 'yatex-mode)
yuuji@7 657 (buffer-modified-p buf)
yuuji@7 658 (y-or-n-p (format "Save %s" (buffer-name buf))))
yuuji@7 659 (save-buffer buf)))
yuuji@7 660 (buffer-list)))
yuuji@7 661 )
yuuji@7 662
yuuji@7 663 (provide 'yatexprc)