如果命令终止,请终止Emacs的异步Shell命令缓冲区

时间:2016-01-18 15:04:27

标签: emacs elisp

如果async命令终止,Emacs不会终止*Async Shell Command*缓冲区。我该怎么强迫这种行为?

1 个答案:

答案 0 :(得分:4)

您要找的是Process Sentinels

*Async Shell Command*的哨兵是shell-command-sentinel

你可以advise

(defun my-kill-buffer-when-done (process signal)
  (when (and (process-buffer process)
             (memq (process-status process) '(exit signal)))
    (kill-buffer (process-buffer process))))

(defun my-kill-async-buffer-when-done ()
  (let ((process (get-buffer-process "*Async Shell Command*")))
    (add-function :after (process-sentinel process) #'kill-buffer-when-done)))

(add-function :after #'async-shell-command #'my-kill-async-buffer-when-done)

PS。我没有测试上面的代码,主要是因为我认为这是一个可怕的想法:你想要在杀死它之前检查*Async Shell Command*的内容。 但是,我希望阅读上面的代码和链接可以帮助您成为更熟练的Emacs用户。