[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A process sentinel is a function that is called whenever the associated process changes status for any reason, including signals (whether sent by Emacs or caused by the process's own actions) that terminate, stop, or continue the process. The process sentinel is also called if the process exits. The sentinel receives two arguments: the process for which the event occurred, and a string describing the type of event.
The string describing the event looks like one of the following:
"finished\n"
.
"exited abnormally with code exitcode\n"
.
"name-of-signal\n"
.
"name-of-signal (core dumped)\n"
.
A sentinel runs only while Emacs is waiting (e.g., for terminal input,
or for time to elapse, or for process output). This avoids the timing
errors that could result from running them at random places in the
middle of other Lisp programs. A program can wait, so that sentinels
will run, by calling sit-for
or sleep-for
(see section 21.9 Waiting for Elapsed Time or Input), or accept-process-output
(see section 37.9.3 Accepting Output from Processes). Emacs also allows sentinels to run when the command loop is
reading input.
Quitting is normally inhibited within a sentinel--otherwise, the
effect of typing C-g at command level or to quit a user command
would be unpredictable. If you want to permit quitting inside a
sentinel, bind inhibit-quit
to nil
. See section 21.10 Quitting.
A sentinel that writes the output into the buffer of the process
should check whether the buffer is still alive. If it tries to insert
into a dead buffer, it will get an error. If the buffer is dead,
(buffer-name (process-buffer process))
returns nil
.
If an error happens during execution of a sentinel, it is caught
automatically, so that it doesn't stop the execution of whatever
programs was running when the sentinel was started. However, if
debug-on-error
is non-nil
, the error-catching is turned
off. This makes it possible to use the Lisp debugger to debug the
sentinel. See section 18.1 The Lisp Debugger.
In earlier Emacs versions, every sentinel that did regular expression searching or matching had to explicitly save and restore the match data. Now Emacs does this automatically for sentinels; they never need to do it explicitly. See section 34.6 The Match Data.
nil
, then the process will have no sentinel.
The default behavior when there is no sentinel is to insert a message in
the process's buffer when the process status changes.
(defun msg-me (process event) (princ (format "Process: %s had the event `%s'" process event))) (set-process-sentinel (get-process "shell") 'msg-me) => msg-me (kill-process (get-process "shell")) -| Process: #<process shell> had the event `killed' => #<process shell> |
nil
if it
has none.
nil
if Emacs was waiting for keyboard input from the user at
the time the sentinel or filter function was called, nil
if it
was not.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |