yatex

diff yatexprc.el @ 123:590fc51462c7

New typeset menu `latex+p(D)f' added. Call dvipdfmx when typesetting succeeded.
author yuuji@gentei.org
date Thu, 27 May 2010 10:16:56 +0900
parents 57d3d9abd661
children 40b29f7ba3e2
line diff
     1.1 --- a/yatexprc.el	Mon May 24 14:55:07 2010 +0900
     1.2 +++ b/yatexprc.el	Thu May 27 10:16:56 2010 +0900
     1.3 @@ -1,8 +1,8 @@
     1.4  ;;; -*- Emacs-Lisp -*-
     1.5  ;;; YaTeX process handler.
     1.6  ;;; yatexprc.el
     1.7 -;;; (c)1993-2009 by HIROSE Yuuji.[yuuji@yatex.org]
     1.8 -;;; Last modified Mon May 24 14:50:24 2010 on firestorm
     1.9 +;;; (c)1993-2010 by HIROSE Yuuji.[yuuji@yatex.org]
    1.10 +;;; Last modified Thu May 27 09:58:17 2010 on firestorm
    1.11  ;;; $Id$
    1.12  
    1.13  ;(require 'yatex)
    1.14 @@ -55,7 +55,7 @@
    1.15    (modify-syntax-entry ?\[ "w" YaTeX-typeset-buffer-syntax)
    1.16    (modify-syntax-entry ?\] "w" YaTeX-typeset-buffer-syntax))
    1.17  
    1.18 -(defun YaTeX-typeset (command buffer &optional prcname modename)
    1.19 +(defun YaTeX-typeset (command buffer &optional prcname modename ppcmd)
    1.20    "Execute jlatex (or other) to LaTeX typeset."
    1.21    (interactive)
    1.22    (save-excursion
    1.23 @@ -91,7 +91,12 @@
    1.24  	       (start-process prcname buffer shell-file-name
    1.25  			      YaTeX-shell-command-option command))
    1.26  	 (get-buffer buffer))
    1.27 -	(set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)))
    1.28 +	(set-process-sentinel YaTeX-typeset-process 'YaTeX-typeset-sentinel)
    1.29 +	(let ((ppprop (get 'YaTeX-typeset-process 'ppcmd)))
    1.30 +	  (setq ppprop (delq (assq YaTeX-typeset-process ppprop) ppprop))
    1.31 +	  (if ppcmd
    1.32 +	      (setq ppprop (cons (cons YaTeX-typeset-process ppcmd) ppprop)))
    1.33 +	  (put 'YaTeX-typeset-process 'ppcmd ppprop))))
    1.34        (message (format "Calling `%s'..." command))
    1.35        (setq YaTeX-current-TeX-buffer (buffer-name))
    1.36        (use-local-map map)		;map may be localized
    1.37 @@ -150,7 +155,6 @@
    1.38                   (insert ?\n mode-name " " mes)
    1.39                   (forward-char -1)
    1.40                   (insert " at " (substring (current-time-string) 0 -5) "\n")
    1.41 -                 (forward-char 1)
    1.42                   (setq mode-line-process
    1.43                         (concat ": "
    1.44                                 (symbol-name (process-status proc))))
    1.45 @@ -161,8 +165,27 @@
    1.46                   ;; is dead, we can delete it now.  Otherwise it
    1.47                   ;; will stay around until M-x list-processes.
    1.48                   (delete-process proc)
    1.49 -		 )
    1.50 -             (setq YaTeX-typeset-process nil)
    1.51 +		 ;; If ppcmd is active, call it.
    1.52 +		 (let* ((ppprop (get 'YaTeX-typeset-process 'ppcmd))
    1.53 +			(ppcmd (cdr (assq proc ppprop))))
    1.54 +		   (put 'YaTeX-typeset-process 'ppcmd ;erase ppcmd
    1.55 +			(delq (assq proc ppprop) ppprop))
    1.56 +		   (cond
    1.57 +		    ((and ppcmd (string-match "finish" mes))
    1.58 +		     (insert (format "=======> Success! Calling %s\n" ppcmd))
    1.59 +		     (setq mode-name	; set process name
    1.60 +			   (substring ppcmd 0 (string-match " " ppcmd)))
    1.61 +		     ; to reach here, 'start-process exists on this emacsen
    1.62 +		     (set-process-sentinel
    1.63 +		      (start-process
    1.64 +		       mode-name
    1.65 +		       pbuf		; Use this buffer twice.
    1.66 +		       shell-file-name YaTeX-shell-command-option
    1.67 +		       ppcmd)
    1.68 +		      'YaTeX-typeset-sentinel))))
    1.69 +		 
    1.70 +		 (forward-char 1))
    1.71 +	     (setq YaTeX-typeset-process nil)
    1.72               ;; Force mode line redisplay soon
    1.73               (set-buffer-modified-p (buffer-modified-p))
    1.74  	     )
    1.75 @@ -256,17 +279,30 @@
    1.76        (put 'dvi2-command 'file buffer)
    1.77        (put 'dvi2-command 'offset lineinfo))))
    1.78  
    1.79 -(defun YaTeX-typeset-buffer ()
    1.80 +(defun YaTeX-typeset-buffer (&optional pp)
    1.81    "Typeset whole buffer.
    1.82  If %#! usage says other buffer is main text,
    1.83  visit main buffer to confirm if its includeonly list contains current
    1.84  buffer's file.  And if it doesn't contain editing text, ask user which
    1.85 -action wants to be done, A:Add list, R:Replace list, %:comment-out list."
    1.86 +action wants to be done, A:Add list, R:Replace list, %:comment-out list.
    1.87 +If optional argument PP given as string, PP is considered as post-process
    1.88 +command and call it with the same command argument as typesetter without
    1.89 +last extension.
    1.90 +eg. if PP is \"dvipdfmx\", called commands as follows.
    1.91 +  platex foo.tex
    1.92 +  dvipdfmx foo
    1.93 +PP command will be called iff typeset command exit successfully"
    1.94    (interactive)
    1.95    (YaTeX-save-buffers)
    1.96    (let*((me (substring (buffer-name) 0 (rindex (buffer-name) ?.)))
    1.97  	(mydir (file-name-directory (buffer-file-name)))
    1.98 -	(cmd (YaTeX-get-latex-command t)) (cb (current-buffer)))
    1.99 +	(cmd (YaTeX-get-latex-command t)) ppcmd
   1.100 +	(cb (current-buffer)))
   1.101 +    (and pp
   1.102 +	 (stringp pp)
   1.103 +	 (let ((tex-command pp))
   1.104 +	   (setq ppcmd (YaTeX-get-latex-command t)
   1.105 +		 ppcmd (substring ppcmd 0 (rindex ppcmd ?.)))))
   1.106      (if (YaTeX-main-file-p) nil
   1.107        (save-excursion
   1.108  	(YaTeX-visit-main t)	;search into main buffer
   1.109 @@ -307,9 +343,17 @@
   1.110  		  (basic-save-buffer))))
   1.111  	  (exchange-point-and-mark)))
   1.112        (switch-to-buffer cb))		;for 19
   1.113 -    (YaTeX-typeset cmd YaTeX-typeset-buffer)
   1.114 +    (YaTeX-typeset cmd YaTeX-typeset-buffer nil nil ppcmd)
   1.115      (put 'dvi2-command 'region nil)))
   1.116  
   1.117 +(defun YaTeX-typeset+pp-buffer (cmd)
   1.118 +  "Call typeset buffer and if it exits successfully, call the next JOB."
   1.119 +  (let ((x))
   1.120 +	  
   1.121 +  (unwind-protect
   1.122 +      (put 'YaTeX-typeset-buffer 'foo nil)
   1.123 +    nil)))
   1.124 +
   1.125  (defvar YaTeX-call-command-history nil
   1.126    "Holds history list of YaTeX-call-command-on-file.")
   1.127  (put 'YaTeX-call-command-history 'no-default t)