Function: vc-exec-after
vc-exec-after is a byte-compiled function defined in
vc-dispatcher.el.gz.
Signature
(vc-exec-after CODE &optional SUCCESS)
Documentation
Eval CODE when the current buffer's process is done.
If the current buffer has no process, just evaluate CODE. Else, add CODE to the process' sentinel. CODE should be a function of no arguments.
If SUCCESS, it should be a process object. Only run CODE if the SUCCESS process has a zero exit code.
Source Code
;; Defined in /usr/src/emacs/lisp/vc/vc-dispatcher.el.gz
(defun vc-exec-after (code &optional success)
"Eval CODE when the current buffer's process is done.
If the current buffer has no process, just evaluate CODE.
Else, add CODE to the process' sentinel.
CODE should be a function of no arguments.
If SUCCESS, it should be a process object. Only run CODE if the
SUCCESS process has a zero exit code."
(let ((proc (get-buffer-process (current-buffer))))
(cond
;; If there's no background process, just execute the code.
;; We used to explicitly call delete-process on exited processes,
;; but this led to timing problems causing process output to be
;; lost. Terminated processes get deleted automatically
;; anyway. -- cyd
((or (null proc) (eq (process-status proc) 'exit))
;; Make sure we've read the process's output before going further.
(when proc (accept-process-output proc))
(when (or (not success)
(zerop (process-exit-status success)))
(if (functionp code) (funcall code) (eval code t))))
;; If a process is running, add CODE to the sentinel
((eq (process-status proc) 'run)
(vc-set-mode-line-busy-indicator)
(letrec ((fun (lambda (p _msg)
(remove-function (process-sentinel p) fun)
(vc--process-sentinel p code success))))
(add-function :after (process-sentinel proc) fun)))
(t (error "Unexpected process state"))))
nil)