谁能帮我把第一个start-process和第二个start-process之间的步骤。显示pdf文件的第二个start-process应该运行only if,第一个start-process完成时没有错误。可能有一些成功的退出代码可以被发现,但我需要一些帮助,请在这方面。
关于如何最好地确定第一个start-process是否在没有错误的情况下结束,我愿意听取一些建议。一种方法是查看output缓冲区,以确定最后一行是否等于"Process process finished“。即使没有错误,生成*.pdf文件也需要几秒钟的时间,如果开始得太早,第二个start-process就会失败。搁置不是最好的选择,因为如果第一个start-process没有正确完成,则应该中止第二个start-process。生成output缓冲区也需要几秒钟的时间,所以检查缓冲区中的最后一行也需要等到第一个start-process完成。但是,发现一个成功的退出代码(如果存在这样的东西)将比搜索字符串等于的输出缓冲区更好。。。。
FYI:.latexmkrc $pdflatex代码行将*.pdf的副本放回工作目录,.latexmkrc $out_dir代码行将所有辅助文件放入/tmp文件夹。这是必要的,因为OSX的This不支持$aux_dir。结果是一个干净的工作目录,只包含*.tex和*.pdf文件。
(defun latexmk ()
".latexmkrc should contain the following entries -- without the backslashes:
$pdflatex .= ' && (cp \"%D\" \"%R.pdf\")';
$force_mode = 1;
$pdf_mode = 1;
$out_dir = '/tmp';"
(interactive)
(let* (
(process (file-name-nondirectory buffer-file-name))
(output (concat "*" (file-name-nondirectory buffer-file-name) "*") )
(latexmk "/usr/local/texlive/2012/texmf-dist/scripts/latexmk/latexmk.pl")
(arg-1 "-interaction=nonstopmode")
(arg-2 "-file-line-error")
(arg-3 "-synctex=1")
(arg-4 "-r")
(arg-5 "/Users/HOME/.0.data/.0.emacs/.latexmkrc")
(pdf-file (concat "/tmp/" (car (split-string
(file-name-nondirectory buffer-file-name) "\\.")) ".pdf"))
(line (format "%d" (line-number-at-pos)))
(skim "/Applications/Skim.app/Contents/SharedSupport/displayline") )
(if (buffer-modified-p)
(save-buffer))
(start-process process output latexmk arg-1 arg-2 arg-3 arg-4 arg-5 buffer-file-name)
;; (if (last line of output buffer is "Process 'process' finished")
(start-process "displayline" nil skim "-b" line pdf-file buffer-file-name)
(switch-to-buffer output)
;; )
))编辑:一个基于Francesco在下面的答案中概述的概念的工作解决方案可以在一个相关的线程中获得:https://tex.stackexchange.com/a/156617/26911
发布于 2013-09-09 21:17:56
这个答案提供了一种链接异步命令的方法,使用哨兵在运行以下命令之前等待每个命令终止。
您需要调整哨兵,以便使用process-exit-status检查进程退出状态。对您来说,一个最低限度的工作示例应该是这样的:
(defun run-latexmk ()
"Asynchronously run `latexmk' and attach a sentinel to it"
(let ((process (start-process "latexmk" "*output*"
"/bin/sh" "-c" "echo KO; false")))
(set-process-sentinel process 'latexmk-sentinel)))
(defun latexmk-sentinel (p e)
"Display the pdf if `latexmk' was successful"
(when (= 0 (process-exit-status p))
(start-process "displaypdf" "*output*"
"/bin/echo" "DISPLAY PDF")))
;; Example use
(with-current-buffer (get-buffer-create "*output*") (erase-buffer))
(run-latexmk)https://stackoverflow.com/questions/18705774
复制相似问题