Mercurial > hgrepos > hgweb.cgi > yatex
comparison yatexprc.el @ 262:15ec86ff549c dev
Call always bibtex after first typesetting when document needs bibtex.
Display total ellapsed time of all processing for impatients :).
Use value of `%BIBTEX ...' line, if any, to automatic (re)run of bibtex.
author | HIROSE Yuuji <yuuji@gentei.org> |
---|---|
date | Fri, 17 Feb 2012 17:42:27 +0900 |
parents | 8c555014f933 |
children | 808f532d68d3 |
comparison
equal
deleted
inserted
replaced
261:8c555014f933 | 262:15ec86ff549c |
---|---|
1 ;;; -*- Emacs-Lisp -*- | 1 ;;; -*- Emacs-Lisp -*- |
2 ;;; YaTeX process handler. | 2 ;;; YaTeX process handler. |
3 ;;; yatexprc.el | 3 ;;; yatexprc.el |
4 ;;; (c)1993-2012 by HIROSE Yuuji.[yuuji@yatex.org] | 4 ;;; (c)1993-2012 by HIROSE Yuuji.[yuuji@yatex.org] |
5 ;;; Last modified Mon Feb 13 21:58:24 2012 on firestorm | 5 ;;; Last modified Fri Feb 17 17:38:32 2012 on firestorm |
6 ;;; $Id$ | 6 ;;; $Id$ |
7 | 7 |
8 ;(require 'yatex) | 8 ;(require 'yatex) |
9 (require 'yatexlib) | 9 (require 'yatexlib) |
10 | 10 |
54 (modify-syntax-entry ?\} "w" YaTeX-typeset-buffer-syntax) | 54 (modify-syntax-entry ?\} "w" YaTeX-typeset-buffer-syntax) |
55 (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax) | 55 (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax) |
56 (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax)) | 56 (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax)) |
57 | 57 |
58 (defvar YaTeX-typeset-marker nil) | 58 (defvar YaTeX-typeset-marker nil) |
59 (defvar YaTeX-typeset-consumption nil) | |
60 (make-variable-buffer-local 'YaTeX-typeset-consumption) | |
59 (defun YaTeX-typeset (command buffer &optional prcname modename ppcmd) | 61 (defun YaTeX-typeset (command buffer &optional prcname modename ppcmd) |
60 "Execute jlatex (or other) to LaTeX typeset." | 62 "Execute jlatex (or other) to LaTeX typeset." |
61 (interactive) | 63 (interactive) |
62 (save-excursion | 64 (save-excursion |
63 (let ((p (point)) (window (selected-window)) execdir (cb (current-buffer)) | 65 (let ((p (point)) (window (selected-window)) execdir (cb (current-buffer)) |
93 YaTeX-shell-command-option command)) | 95 YaTeX-shell-command-option command)) |
94 (get-buffer buffer)) | 96 (get-buffer buffer)) |
95 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel) | 97 (set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel) |
96 (put 'YaTeX-typeset-process 'thiscmd command) | 98 (put 'YaTeX-typeset-process 'thiscmd command) |
97 (put 'YaTeX-typeset-process 'name prcname) | 99 (put 'YaTeX-typeset-process 'name prcname) |
100 (if (fboundp 'current-time) | |
101 (setq YaTeX-typeset-consumption | |
102 (cons (cons 'time (current-time)) | |
103 (delq 'time YaTeX-typeset-consumption)))) | |
98 (let ((ppprop (get 'YaTeX-typeset-process 'ppcmd))) | 104 (let ((ppprop (get 'YaTeX-typeset-process 'ppcmd))) |
99 (setq ppprop (delq (assq YaTeX-typeset-process ppprop) ppprop)) | 105 (setq ppprop (delq (assq YaTeX-typeset-process ppprop) ppprop)) |
100 (if ppcmd | 106 (if ppcmd |
101 (setq ppprop (cons (cons YaTeX-typeset-process ppcmd) ppprop))) | 107 (setq ppprop (cons (cons YaTeX-typeset-process ppcmd) ppprop))) |
102 (put 'YaTeX-typeset-process 'ppcmd ppprop)) | 108 (put 'YaTeX-typeset-process 'ppcmd ppprop)) |
144 (recenter -1)) | 150 (recenter -1)) |
145 (select-window window) | 151 (select-window window) |
146 (switch-to-buffer cb) | 152 (switch-to-buffer cb) |
147 (YaTeX-remove-nonstopmode)))) | 153 (YaTeX-remove-nonstopmode)))) |
148 | 154 |
155 (defvar YaTeX-typeset-auto-rerun t | |
156 "*Non-nil automatically reruns typesetter when cross-refs update found. | |
157 This is a toy mechanism. DO NOT RELY ON THIS MECHANISM. | |
158 You SHOULD check the integrity of cross-references with your eyes!! | |
159 Supplying an integer to this variable inhibit compulsory call of bibtex, | |
160 thus, it call bibtex only if warning messages about citation are seen.") | |
149 (defvar YaTeX-typeset-rerun-msg "Rerun to get cross-references right.") | 161 (defvar YaTeX-typeset-rerun-msg "Rerun to get cross-references right.") |
150 (defvar YaTeX-typeset-citation-msg | 162 (defvar YaTeX-typeset-citation-msg |
151 "Warning: Citation \`") | 163 "Warning: Citation \`") |
152 (defvar YaTeX-typeset-auto-rerun t | |
153 "*Non-nil automatically reruns typesetter when cross-refs update found. | |
154 This is mechanism is ") | |
155 (defun YaTeX-typeset-sentinel (proc mes) | 164 (defun YaTeX-typeset-sentinel (proc mes) |
156 (cond ((null (buffer-name (process-buffer proc))) | 165 (cond ((null (buffer-name (process-buffer proc))) |
157 ;; buffer killed | 166 ;; buffer killed |
158 (set-process-buffer proc nil)) | 167 (set-process-buffer proc nil)) |
159 ((memq (process-status proc) '(signal exit)) | 168 ((memq (process-status proc) '(signal exit)) |
181 ;;(YaTeX-showup-buffer pbuf nil t) | 190 ;;(YaTeX-showup-buffer pbuf nil t) |
182 (goto-char (point-max)) | 191 (goto-char (point-max)) |
183 (if pwin (recenter -3)) | 192 (if pwin (recenter -3)) |
184 (insert ?\n mode-name " " mes) | 193 (insert ?\n mode-name " " mes) |
185 (forward-char -1) | 194 (forward-char -1) |
186 (insert " at " (substring (current-time-string) 0 -5) "\n") | 195 (insert |
196 (format " at %s%s\n" | |
197 (substring (current-time-string) 0 -5) | |
198 (if (and (fboundp 'current-time) (fboundp 'float) | |
199 (assq 'time YaTeX-typeset-consumption)) | |
200 (format | |
201 " (%.2f secs)" | |
202 (YaTeX-elapsed-time | |
203 (cdr (assq 'time YaTeX-typeset-consumption)) | |
204 (current-time)))))) | |
187 (setq mode-line-process | 205 (setq mode-line-process |
188 (concat ": " | 206 (concat ": " |
189 (symbol-name (process-status proc)))) | 207 (symbol-name (process-status proc)))) |
190 (message "%s %s" mode-name | 208 (message "%s %s" mode-name |
191 (if (eq (process-status proc) 'exit) | 209 (if (eq (process-status proc) 'exit) |
193 ;; If buffer and mode line shows that the process | 211 ;; If buffer and mode line shows that the process |
194 ;; is dead, we can delete it now. Otherwise it | 212 ;; is dead, we can delete it now. Otherwise it |
195 ;; will stay around until M-x list-processes. | 213 ;; will stay around until M-x list-processes. |
196 (delete-process proc) | 214 (delete-process proc) |
197 (if (cond | 215 (if (cond |
198 ((null YaTeX-typeset-auto-rerun) nil) | 216 ((not YaTeX-typeset-auto-rerun) nil) |
199 ((and bibcmd | 217 ((and bibcmd ;Call bibtex if bibcmd defined && |
200 (save-excursion | 218 (or ; (1st call || warning found) |
201 (re-search-backward | 219 (and (not (numberp YaTeX-typeset-auto-rerun)) |
202 YaTeX-typeset-citation-msg | 220 ; cancel call at 1st, if value is a number. |
203 YaTeX-typeset-marker t)) | 221 (not (string-match "bibtex" mode-name))) |
204 (save-excursion | 222 (re-search-backward |
223 YaTeX-typeset-citation-msg | |
224 YaTeX-typeset-marker t)) | |
225 (save-excursion ; && using .bbl files. | |
205 (search-backward | 226 (search-backward |
206 ".bbl" YaTeX-typeset-marker t))) | 227 ".bbl" YaTeX-typeset-marker t))) |
228 ;; Always call bibtex after the first typesetting, | |
229 ;; because bibtex doesn't warn disappeared \cite. | |
230 ;; (Suggested by ryseto. 2012) | |
231 ;; It is more efficient to call bibtex directly than | |
232 ;; to call it after deep inspection on the balance | |
233 ;; of \cite vs. \bib*'s referring all *.aux files. | |
207 (insert "\n" YaTeX-typeset-rerun-msg "\n") | 234 (insert "\n" YaTeX-typeset-rerun-msg "\n") |
208 (setq tobecalled bibcmd shortname "+bibtex")) | 235 (setq tobecalled bibcmd shortname "+bibtex")) |
209 ((or | 236 ((or |
210 (save-excursion | 237 (save-excursion |
211 (search-backward | 238 (search-backward |
255 mode-name | 282 mode-name |
256 pbuf ; Use this buffer twice. | 283 pbuf ; Use this buffer twice. |
257 shell-file-name YaTeX-shell-command-option | 284 shell-file-name YaTeX-shell-command-option |
258 ppcmd) | 285 ppcmd) |
259 'YaTeX-typeset-sentinel)) | 286 'YaTeX-typeset-sentinel)) |
260 (t ;pull back original name | 287 (t ;pull back original mode-name |
261 (setq mode-name "typeset")))) | 288 (setq mode-name "typeset")))) |
262 (forward-char 1)) | 289 (forward-char 1)) |
263 (setq YaTeX-typeset-process nil) | 290 (setq YaTeX-typeset-process nil) |
264 ;; Force mode line redisplay soon | 291 ;; Force mode line redisplay soon |
265 (set-buffer-modified-p (buffer-modified-p)) | 292 (set-buffer-modified-p (buffer-modified-p)) |
382 (cmd (YaTeX-get-latex-command t)) pparg ppcmd bibcmd | 409 (cmd (YaTeX-get-latex-command t)) pparg ppcmd bibcmd |
383 (cb (current-buffer))) | 410 (cb (current-buffer))) |
384 (setq pparg (substring cmd 0 (string-match "[;&]" cmd)) ;rm multistmt | 411 (setq pparg (substring cmd 0 (string-match "[;&]" cmd)) ;rm multistmt |
385 pparg (substring pparg (rindex pparg ? )) ;get last arg | 412 pparg (substring pparg (rindex pparg ? )) ;get last arg |
386 pparg (substring pparg 0 (rindex pparg ?.)) ;rm ext | 413 pparg (substring pparg 0 (rindex pparg ?.)) ;rm ext |
387 bibcmd (concat bibtex-command pparg)) | 414 bibcmd (or (YaTeX-get-builtin "BIBTEX") bibtex-command)) |
415 (or (string-match "\\s " bibcmd) ;if bibcmd has no spaces, | |
416 (setq bibcmd (concat bibcmd pparg))) ;append argument(== %#!) | |
388 (and pp | 417 (and pp |
389 (stringp pp) | 418 (stringp pp) |
390 (setq ppcmd (concat pp pparg))) | 419 (setq ppcmd (concat pp pparg))) |
391 (if (YaTeX-main-file-p) nil | 420 (if (YaTeX-main-file-p) nil |
392 (save-excursion | 421 (save-excursion |