I want to run some Elisp when my command executed by
How can I do this? Does it have completion hooks?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.Sign up to join this community
You can specify the output buffer for
The shell runs as a process of the output buffer.
You can get that process with
Define your own process sentinel for the shell and set it with
It is wise to run
shell-command-sentinel from your sentinel
since that is the sentinel actually set by
Note that the output buffer may not be associated with any other process when you call
async-shell-command. Otherwise an other buffer could be used as process buffer for the shell command (see the documentation of the variable
There follows an example:
(defun do-something (process signal) (when (memq (process-status process) '(exit signal)) (message "Do something!") (shell-command-sentinel process signal))) (let* ((output-buffer (generate-new-buffer "*Async shell command*")) (proc (progn (async-shell-command "sleep 10; echo Finished" output-buffer) (get-buffer-process output-buffer)))) (if (process-live-p proc) (set-process-sentinel proc #'do-something) (message "No process running.")))