如果命令终止,则杀死 Emacs 的 Async Shell 命令缓冲区
Kill Emacs's Async Shell Command buffer if command is terminated
如果异步命令终止,Emacs 不会终止 *Async Shell Command*
缓冲区。我如何强制执行此行为?
您要找的是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 用户。
如果异步命令终止,Emacs 不会终止 *Async Shell Command*
缓冲区。我如何强制执行此行为?
您要找的是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 用户。