yatex

changeset 224:9705855793ca dev

YaTeX-typeset-auto-rerun for labels and bibitems reference resolution.
author yuuji@gentei.org
date Sun, 22 Jan 2012 21:37:09 +0900
parents 265da12ff3b6
children bd9dc9d53a3a
files yatex.el yatexprc.el
diffstat 2 files changed, 74 insertions(+), 25 deletions(-) [+]
line diff
     1.1 --- a/yatex.el	Wed Jan 18 11:45:02 2012 +0900
     1.2 +++ b/yatex.el	Sun Jan 22 21:37:09 2012 +0900
     1.3 @@ -2,7 +2,7 @@
     1.4  ;;; Yet Another tex-mode for emacs - //–ì’¹//
     1.5  ;;; yatex.el rev. 1.75.1
     1.6  ;;; (c)1991-2012 by HIROSE Yuuji.[yuuji@yatex.org]
     1.7 -;;; Last modified Sun Jan 15 09:06:00 2012 on fusion
     1.8 +;;; Last modified Sun Jan 22 15:48:09 2012 on firestorm
     1.9  ;;; $Id$
    1.10  ;;; The latest version of this software is always available at;
    1.11  ;;; http://www.yatex.org/
    1.12 @@ -1617,10 +1617,10 @@
    1.13       ((= c ?j) (YaTeX-typeset-buffer))
    1.14       ((= c ?r) (YaTeX-typeset-region))
    1.15       ((= c ?e) (YaTeX-typeset-environment))
    1.16 -     ((= c ?b) (YaTeX-call-command-on-file
    1.17 -		bibtex-command "*YaTeX-bibtex*" YaTeX-parent-file))
    1.18 -     ((= c ?i) (YaTeX-call-command-on-file
    1.19 -		makeindex-command "*YaTeX-makeindex*" YaTeX-parent-file))
    1.20 +     ((= c ?b) (YaTeX-call-builtin-on-file
    1.21 +		"BIBTEX" bibtex-command))
    1.22 +     ((= c ?i) (YaTeX-call-builtin-on-file
    1.23 +		"MAKEINDEX" makeindex-command))
    1.24       ((= c ?k) (YaTeX-kill-typeset-process YaTeX-typeset-process))
    1.25       ((= c ?p) (call-interactively 'YaTeX-preview))
    1.26       ((= c ?q) (YaTeX-system "lpq" "*Printer queue*"))
     2.1 --- a/yatexprc.el	Wed Jan 18 11:45:02 2012 +0900
     2.2 +++ b/yatexprc.el	Sun Jan 22 21:37:09 2012 +0900
     2.3 @@ -2,7 +2,7 @@
     2.4  ;;; YaTeX process handler.
     2.5  ;;; yatexprc.el
     2.6  ;;; (c)1993-2012 by HIROSE Yuuji.[yuuji@yatex.org]
     2.7 -;;; Last modified Thu Jan 12 21:17:08 2012 on firestorm
     2.8 +;;; Last modified Sun Jan 22 15:47:53 2012 on firestorm
     2.9  ;;; $Id$
    2.10  
    2.11  ;(require 'yatex)
    2.12 @@ -99,7 +99,13 @@
    2.13  	  (setq ppprop (delq (assq YaTeX-typeset-process ppprop) ppprop))
    2.14  	  (if ppcmd
    2.15  	      (setq ppprop (cons (cons YaTeX-typeset-process ppcmd) ppprop)))
    2.16 -	  (put 'YaTeX-typeset-process 'ppcmd ppprop))))
    2.17 +	  (put 'YaTeX-typeset-process 'ppcmd ppprop))
    2.18 +	(if (and (boundp 'bibcmd) bibcmd)
    2.19 +	    (let ((bcprop (get 'YaTeX-typeset-process 'bibcmd)))
    2.20 +	      (setq bcprop (cons
    2.21 +			    (cons YaTeX-typeset-process bibcmd)
    2.22 +			    (delq (assq YaTeX-typeset-process bcprop) bcprop)))
    2.23 +	      (put 'YaTeX-typeset-process 'bibcmd bcprop)))))
    2.24        (message (format "Calling `%s'..." command))
    2.25        (setq YaTeX-current-TeX-buffer (buffer-name))
    2.26        (use-local-map map)		;map may be localized
    2.27 @@ -141,6 +147,11 @@
    2.28        (YaTeX-remove-nonstopmode))))
    2.29  
    2.30  (defvar YaTeX-typeset-rerun-msg "Rerun to get cross-references right.")
    2.31 +(defvar YaTeX-typeset-citation-msg
    2.32 +  "LaTeX Warning: Citation .* on page [0-9]+ undefined on input line")
    2.33 +(defvar YaTeX-typeset-auto-rerun t
    2.34 +  "*Non-nil automatically reruns typesetter when cross-refs update found.
    2.35 +This is mechanism is ")
    2.36  (defun YaTeX-typeset-sentinel (proc mes)
    2.37    (cond ((null (buffer-name (process-buffer proc)))
    2.38           ;; buffer killed
    2.39 @@ -149,11 +160,16 @@
    2.40           (let* ((obuf (current-buffer)) (pbuf (process-buffer proc))
    2.41  		(pwin (get-buffer-window pbuf))
    2.42  		(owin (selected-window)) win
    2.43 +		tobecalled
    2.44  		(thiscmd (get 'YaTeX-typeset-process 'thiscmd))
    2.45  		(ppprop (get 'YaTeX-typeset-process 'ppcmd))
    2.46 -		(ppcmd (cdr (assq proc ppprop))))
    2.47 +		(ppcmd (cdr (assq proc ppprop)))
    2.48 +		(bcprop (get 'YaTeX-typeset-process 'bibcmd))
    2.49 +		(bibcmd (cdr (assq proc bcprop))))
    2.50  	   (put 'YaTeX-typeset-process 'ppcmd ;erase ppcmd
    2.51  		(delq (assq proc ppprop) ppprop))
    2.52 +	   (put 'YaTeX-typeset-process 'bibcmd ;erase bibcmd
    2.53 +		(delq (assq proc bcprop) bcprop))
    2.54             ;; save-excursion isn't the right thing if
    2.55             ;;  process-buffer is current-buffer
    2.56             (unwind-protect
    2.57 @@ -178,26 +194,47 @@
    2.58                   ;; is dead, we can delete it now.  Otherwise it
    2.59                   ;; will stay around until M-x list-processes.
    2.60                   (delete-process proc)
    2.61 -		 (if (save-excursion
    2.62 -		       (search-backward
    2.63 -			YaTeX-typeset-rerun-msg YaTeX-typeset-marker t))
    2.64 +		 (if (cond
    2.65 +		      ((null YaTeX-typeset-auto-rerun) nil)
    2.66 +		      ((and bibcmd
    2.67 +			    (save-excursion
    2.68 +			      (re-search-backward
    2.69 +			       YaTeX-typeset-citation-msg
    2.70 +			       YaTeX-typeset-marker t))
    2.71 +			    (save-excursion
    2.72 +			      (search-backward
    2.73 +			       ".bbl" YaTeX-typeset-marker t)))
    2.74 +		       (insert "\n" YaTeX-typeset-rerun-msg "\n")
    2.75 +		       (setq tobecalled bibcmd))
    2.76 +		      ((save-excursion
    2.77 +			 (search-backward
    2.78 +			  YaTeX-typeset-rerun-msg YaTeX-typeset-marker t))
    2.79 +		       (if bibcmd
    2.80 +			   (put 'YaTeX-typeset-process 'bibcmd
    2.81 +				(cons (cons (get-buffer-process pbuf) bibcmd)
    2.82 +				      bcprop)))
    2.83 +		       (setq tobecalled thiscmd))
    2.84 +		      (t nil))
    2.85  		     (progn
    2.86  		       (insert
    2.87  			(format
    2.88  			 "===!!! %s !!!===\n"
    2.89  			 (message "Rerun `%s' to get cross-references right"
    2.90 -				  thiscmd)))
    2.91 -		       (set-marker YaTeX-typeset-marker (point))
    2.92 +				  tobecalled)))
    2.93 +		       (if (equal tobecalled thiscmd)
    2.94 +			   (set-marker YaTeX-typeset-marker (point)))
    2.95  		       (save-excursion (sit-for 2))
    2.96  		       (set-process-sentinel
    2.97  			(start-process
    2.98  			 mode-name pbuf
    2.99 -			 shell-file-name YaTeX-shell-command-option thiscmd)
   2.100 +			 shell-file-name YaTeX-shell-command-option tobecalled)
   2.101  			'YaTeX-typeset-sentinel)
   2.102  		       (if ppcmd
   2.103  			   (put 'YaTeX-typeset-process 'ppcmd
   2.104  				(cons (cons (get-buffer-process pbuf) ppcmd)
   2.105 -				      ppprop))))
   2.106 +				      ppprop)))
   2.107 +		       (if thiscmd
   2.108 +			   (put 'YaTeX-typeset-process 'thiscmd thiscmd)))
   2.109  		   ;; If ppcmd is active, call it.
   2.110  		   (cond
   2.111  		    ((and ppcmd (string-match "finish" mes))
   2.112 @@ -212,7 +249,6 @@
   2.113  		       shell-file-name YaTeX-shell-command-option
   2.114  		       ppcmd)
   2.115  		      'YaTeX-typeset-sentinel))))
   2.116 -		 
   2.117  		 (forward-char 1))
   2.118  	     (setq YaTeX-typeset-process nil)
   2.119               ;; Force mode line redisplay soon
   2.120 @@ -333,13 +369,15 @@
   2.121    (YaTeX-save-buffers)
   2.122    (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.)))
   2.123  	(mydir (file-name-directory (buffer-file-name)))
   2.124 -	(cmd (YaTeX-get-latex-command t)) pparg ppcmd
   2.125 +	(cmd (YaTeX-get-latex-command t)) pparg ppcmd bibcmd
   2.126  	(cb (current-buffer)))
   2.127 +    (setq pparg (substring cmd 0 (string-match "[;&]" cmd)) ;rm multistmt
   2.128 +	  pparg (substring pparg (rindex pparg ? ))	 ;get last arg
   2.129 +	  pparg (substring pparg 0 (rindex pparg ?.))	 ;rm ext
   2.130 +	  bibcmd (concat bibtex-command pparg))
   2.131      (and pp
   2.132  	 (stringp pp)
   2.133 -	 (setq pparg (substring cmd 0 (string-match "[;&]" cmd)) ;rm multistmt
   2.134 -	       pparg (substring pparg (rindex pparg ? ))	 ;get last arg
   2.135 -	       ppcmd (concat pp (substring pparg 0 (rindex pparg ?.)))));rm ext
   2.136 +	 (setq ppcmd (concat pp pparg)))
   2.137      (if (YaTeX-main-file-p) nil
   2.138        (save-excursion
   2.139  	(YaTeX-visit-main t)	;search into main buffer
   2.140 @@ -406,13 +444,24 @@
   2.141        'YaTeX-call-command-history)
   2.142       buffer)))
   2.143  
   2.144 -(defun YaTeX-bibtex-buffer (cmd)
   2.145 -  "Pass the bibliography data of editing file to bibtex."
   2.146 +(defun YaTeX-call-builtin-on-file (builtin-type &optional default)
   2.147 +  "Call command on file specified by BUILTIN-TYPE."
   2.148    (interactive)
   2.149    (YaTeX-save-buffers)
   2.150 -  (let ((main (or YaTeX-parent-file
   2.151 -		  (progn (YaTeX-visit-main t) buffer-file-name))))
   2.152 -    (YaTeX-call-command-on-file cmd "*YaTeX-bibtex*" main)))
   2.153 +  (let*((main (or YaTeX-parent-file
   2.154 +		  (progn (YaTeX-visit-main t) buffer-file-name)))
   2.155 +	(mainroot (file-name-nondirectory (substring main 0 (rindex main ?.))))
   2.156 +	(b-in (YaTeX-get-builtin builtin-type)))
   2.157 +    (cond
   2.158 +     ((null b-in) (setq b-in (format "%s %s" default mainroot)))
   2.159 +     ((string-match (regexp-quote mainroot) b-in) nil)
   2.160 +     (t (setq b-in (concat b-in " " mainroot))))
   2.161 +    (YaTeX-typeset
   2.162 +     (read-string-with-history
   2.163 +      "Call command: "
   2.164 +      b-in
   2.165 +      'YaTeX-call-command-history)
   2.166 +     (format " *YaTeX-%s*" (downcase builtin-type)))))
   2.167  
   2.168  (defun YaTeX-kill-typeset-process (proc)
   2.169    "Kill process PROC after sending signal to PROC.