2013-04-20 106 views
0

我做了一個功能,運行pdflatex編譯器產生的當前編輯TEX文件的PDF文件elisp的接近*異步Shell命令*命令後窗口完成

(defun latex-compile() 
    "Runs pdflatex on current file" 
    (interactive) 
    (let ((file-name (shell-quote-argument (buffer-file-name)))) 
    (async-shell-command (concat "pdflatex " file-name)))) 

是否有可能關閉窗口如果退出成功,該進程退出後是否退出*Async Shell Command*

回答

2

這裏是工作代碼:

(defun latex-sentinel (process event) 
     (message event) 
     (cond ((string-match-p "finished" event) 
        (progn 
         (kill-buffer "*async pdflatex*") 
         (message "pdflatex done"))))) 

(defun latex-compile() 
     "Runs pdflatex on current file" 
     (interactive) 
     (let* ((file-name (shell-quote-argument (buffer-file-name))) 
      (process (start-process-shell-command 
          "pdflatex" 
          "*async pdflatex*" 
          (concat "pdflatex " file-name)))) 
      (set-process-sentinel process 'latex-sentinel))) 
+0

這非常有幫助。非常感謝。 – plok 2013-07-18 17:13:08

+2

@plok我做了一個更好的版本,可以在底部顯示錯誤,並在查看錯誤後單擊任何按鈕時關閉編譯窗口:http://pastebin.com/VGpEjCTG – user4035 2013-07-18 17:17:45

3

如果要以編程方式運行異步進程,請執行此操作。 也就是說,使用較低級別的功能。

(set-process-sentinel (start-process "pdflatex" 
            "*async pdflatex*" 
            "pdflatex" filename) 
         (lambda (process event) 
         (cond ((string-match-p "finished" event) 
           (kill-buffer "*async pdflatex*")) 
           ((string-match-p "\\(exited\\|dumped\\)" event) 
           (message "Something wrong happened while running pdflatex") 
           (when (yes-or-no-p "Something wrong happened while running pdflatex, see the errors?") 
           (switch-to-buffer "*async pdflatex*")))))) 

start-process異步啓動一個過程,set-process-sentinel定義功能觸發該過程的狀態發生變化時。

+0

我做了一個工作代碼,根據您的建議。但錯誤分支不起作用,因爲pdflatex不會作爲進程崩潰。它停止輸入一條消息,說輸入文件有問題。當它停止並等待用戶輸入時,是否有任何方法切換到* async pdflatex *緩衝區? – user4035 2013-04-21 17:46:56