Next: Process Window Size, Previous: Output from Processes, Up: Processes [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 SXEmacs 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 SXEmacs 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 Waiting), or accept-process-output
(see Accepting Output). SXEmacs is also waiting 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 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 Debugger.
In earlier Emacs versions, every sentinel that did regexp searching or matching had to explicitly save and restore the match data. SXEmacs does this automatically; sentinels never need to do it explicitly. See Match Data.
This function associates sentinel with process. If
sentinel is 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>
This function returns the sentinel of process, or nil
if it
has none.
While a sentinel or filter function is running, this function returns
non-nil
if SXEmacs was waiting for keyboard input from the user at
the time the sentinel or filter function was called, nil
if it
was not.
Next: Process Window Size, Previous: Output from Processes, Up: Processes [Contents][Index]