0

我做了一个函数,运行 pdflatex 编译器为当前编辑的 tex 文件生成一个 pdf 文件:

(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*如果成功退出,是否可以在进程退出后关闭窗口?

4

2 回答 2

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定义进程状态变化时触发的函数。

于 2013-04-20T16:31:27.720 回答
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)))
于 2013-04-21T17:44:22.900 回答