Elisp哨兵进程等待输入 [英] Elisp sentinel on process waiting for input

查看:164
本文介绍了Elisp哨兵进程等待输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个函数,编译当前的乳胶文件:

 ;关闭* async pdflatex *窗口,当pdflatex完成
(defun latex-sentinel(process event)
(message event)
(cond((string-match-pfinishedevent)
(progn
kill-buffer* async pdflatex *)
(消息pdflatex done)
(delete-other-windows)))))

(defun latex-compile )
在当前文件上运行pdflatex
(interactive)
(let *((file-name(shell-quote-argument(buffer-file-name)))
(process(start-process-shell-command
pdflatex
* async pdflatex *
(concatpdflatexfile-name))))
(set- process-sentinel process'latex-sentinel)
(setq new-window(split-window-below 40))
( set-window-buffer new window* async pdflatex *)
(other-window 1)))

(add-hook'LaTeX-mode-hook(lambda()
(定义键LaTeX-mode-map(kbd< f2>)'latex-compile)))

当有错误,编译时,pdflatex冻结,我看到这样:





  1. 向上滚动查看错误

  2. kill-this-buffer - 杀死pdflatex进程

  3. delete-窗口 - 关闭* async pdflatex *窗口并返回到编辑。

是否可以跟踪进程已停止,正在等待用户输入?我现在的哨兵仅在完成事件上激活。所以我可以自动化我目前的工作流程。

解决方案

[@Thomas:你不需要AUCTeX。内置 latex-mode 还为该任务提供了一个 C-c C-c 绑定。 ]



一般来说,检测进程是否等待我是困难/不可能的(最多只能监视进程的CPU使用情况,如果是0%一段时间,您可以决定它可能正在等待您,但即使这样做是棘手的,因为您需要找到正确的操作系统进程来监视,然后使用依赖于系统的操作来获取CPU使用情况)。乳胶模式通常在pdflatex的命令行上传递 \\\
onstopmode\input
来解决这个问题。


I made a function, compiling the current latex file:

;close the *async pdflatex* window, when pdflatex finishes
(defun latex-sentinel (process event)
      (message event)
      (cond ((string-match-p "finished" event)
                  (progn
                        (kill-buffer "*async pdflatex*")
                        (message "pdflatex done")
                        (delete-other-windows)))))

(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)
            (setq new-window (split-window-below 40))
            (set-window-buffer new-window "*async pdflatex*")
            (other-window 1)))

(add-hook 'LaTeX-mode-hook (lambda () 
    (define-key LaTeX-mode-map (kbd "<f2>") 'latex-compile)))

When there is an error, while compiling, pdflatex freezes, and I see this:

My current workflow:

  1. Scroll up to see the error
  2. kill-this-buffer - to kill pdflatex process
  3. delete-window - to close *async pdflatex* window and get back to editing.

Is it possible to track, that the process has stopped and is waiting for user input? My current sentinel activates only on "finished" event. So I could automate my current workflow.

解决方案

[ @Thomas: you don't need AUCTeX for that. The builtin latex-mode also provides a C-c C-c binding for that task. ]

In general, detecting that a process is "waiting for me" is difficult/impossible (at best you might monitor the process's CPU usage and if it's been 0% for a while you can decide that it's probably waiting for you, but even doing that is tricky since you need to find the proper OS-process to monitor and then use system-dependent operations to get the CPU usage). latex-modes usually "solve" this by passing \nonstopmode\input on pdflatex's command line.

这篇关于Elisp哨兵进程等待输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆