(notice_overwritten_cursor): Fix an off by 1 error.
[bpt/emacs.git] / lispref / processes.texi
index 94b8e61..0b5786f 100644 (file)
@@ -1,6 +1,7 @@
 @c -*-texinfo-*-
 @c This is part of the GNU Emacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998 Free Software Foundation, Inc. 
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999
+@c   Free Software Foundation, Inc. 
 @c See the file elisp.texi for copying conditions.
 @setfilename ../info/processes
 @node Processes, Display, Abbrevs, Top
@@ -34,6 +35,7 @@ This function returns @code{t} if @var{object} is a process,
 
 @menu
 * Subprocess Creation::      Functions that start subprocesses.
+* Shell Arguments::          Quoting an argument to pass it to a shell.
 * Synchronous Processes::    Details of using synchronous subprocesses.
 * Asynchronous Processes::   Starting up an asynchronous subprocess.
 * Deleting Processes::       Eliminating an asynchronous subprocess.
@@ -41,6 +43,7 @@ This function returns @code{t} if @var{object} is a process,
 * Input to Processes::       Sending input to an asynchronous subprocess.
 * Signals to Processes::     Stopping, continuing or interrupting
                                an asynchronous subprocess.
+* Query Before Exit::        Whether to query if exiting will kill a process.
 * Output from Processes::    Collecting output from an asynchronous subprocess.
 * Sentinels::                Sentinels run when process run-status changes.
 * Transaction Queues::      Transaction-based communication with subprocesses.
@@ -57,7 +60,7 @@ The other two, @code{call-process} and @code{call-process-region},
 create a synchronous process and do not return a process object
 (@pxref{Synchronous Processes}).
 
-  Synchronous and asynchronous processes are explained in following
+  Synchronous and asynchronous processes are explained in the following
 sections.  Since the three functions are all called in a similar
 fashion, their common arguments are described here.
 
@@ -78,12 +81,12 @@ Expansion}).
 
   Each of the subprocess-creating functions has a @var{buffer-or-name}
 argument which specifies where the standard output from the program will
-go.  It should be a buffer or a buffer name (which will create the
-buffer if it does not already exist).  It can also be @code{nil}, which
-says to discard the output unless a filter function handles it.
-(@xref{Filter Functions}, and @ref{Read and Print}.)  Normally, you
-should avoid having multiple processes send output to the same buffer
-because their output would be intermixed randomly.
+go.  It should be a buffer or a buffer name; if it is a buffer name,
+that will create the buffer if it does not already exist.  It can also
+be @code{nil}, which says to discard the output unless a filter function
+handles it.  (@xref{Filter Functions}, and @ref{Read and Print}.)
+Normally, you should avoid having multiple processes send output to the
+same buffer because their output would be intermixed randomly.
 
 @cindex program arguments
   All three of the subprocess-creating functions have a @code{&rest}
@@ -101,14 +104,14 @@ must use @var{args} to provide those.
 @code{default-directory} (@pxref{File Name Expansion}).
 
 @cindex environment variables, subprocesses
-  The subprocess inherits its environment from Emacs; but you can
+  The subprocess inherits its environment from Emacs, but you can
 specify overrides for it with @code{process-environment}.  @xref{System
 Environment}.
 
 @defvar exec-directory 
 @pindex movemail
-The value of this variable is the name of a directory (a string) that
-contains programs that come with GNU Emacs, that are intended for Emacs
+The value of this variable is a string, the name of a directory that
+contains programs that come with GNU Emacs, programs intended for Emacs
 to invoke.  The program @code{movemail} is an example of such a program;
 Rmail uses it to fetch new mail from an inbox.
 @end defvar
@@ -129,7 +132,7 @@ file name.
 @section Shell Arguments
 
   Lisp programs sometimes need to run a shell and give it a command
-which contains file names that were specified by the user.  These
+that contains file names that were specified by the user.  These
 programs ought to be able to support any valid file name.  But the shell
 gives special treatment to certain characters, and if these characters
 occur in the file name, they will confuse the shell.  To handle these
@@ -142,16 +145,18 @@ work reliably to concatenate the return value into a shell command
 and then pass it to a shell for execution.
 
 Precisely what this function does depends on your operating system.  The
-function is designed to work with the usual shell syntax; if you use an
-unusual shell, you will need to redefine this function.  On MS-DOS, the
-function returns @var{argument} unchanged; while this is not really
-correct, it is the best one can do, since the MS-DOS shell has no
-quoting features.
+function is designed to work with the syntax of your system's standard
+shell; if you use an unusual shell, you will need to redefine this
+function.
 
 @example
 ;; @r{This example shows the behavior on GNU and Unix systems.}
 (shell-quote-argument "foo > bar")
      @result{} "foo\\ \\>\\ bar"
+
+;; @r{This example shows the behavior on MS-DOS and MS-Windows systems.}
+(shell-quote-argument "foo > bar")
+     @result{} "\"foo > bar\""
 @end example
 
 Here's an example of using @code{shell-quote-argument} to construct
@@ -170,18 +175,20 @@ a shell command:
 @cindex synchronous subprocess
 
   After a @dfn{synchronous process} is created, Emacs waits for the
-process to terminate before continuing.  Starting Dired is an example of
-this: it runs @code{ls} in a synchronous process, then modifies the
-output slightly.  Because the process is synchronous, the entire
-directory listing arrives in the buffer before Emacs tries to do
-anything with it.
+process to terminate before continuing.  Starting Dired on GNU or
+Unix@footnote{On other systems, Emacs uses a Lisp emulation of
+@code{ls}; see @ref{Contents of Directories}.} is an example of this: it
+runs @code{ls} in a synchronous process, then modifies the output
+slightly.  Because the process is synchronous, the entire directory
+listing arrives in the buffer before Emacs tries to do anything with it.
 
   While Emacs waits for the synchronous subprocess to terminate, the
 user can quit by typing @kbd{C-g}.  The first @kbd{C-g} tries to kill
 the subprocess with a @code{SIGINT} signal; but it waits until the
 subprocess actually terminates before quitting.  If during that time the
 user types another @kbd{C-g}, that kills the subprocess instantly with
-@code{SIGKILL} and quits immediately.  @xref{Quitting}.
+@code{SIGKILL} and quits immediately (except on MS-DOS, where killing
+other processes doesn't work).  @xref{Quitting}.
 
   The synchronous subprocess functions return an indication of how the
 process terminated.
@@ -190,15 +197,13 @@ process terminated.
 coding system, much like text read from a file.  The input sent to a
 subprocess by @code{call-process-region} is encoded using a coding
 system, much like text written into a file.  @xref{Coding Systems}.
-On Microsoft operating systems, additional variables control
-the conversion for end-of-line (@pxref{MS-DOS Subprocesses}).
 
 @defun call-process program &optional infile destination display &rest args
 This function calls @var{program} in a separate process and waits for
 it to finish.
 
 The standard input for the process comes from file @var{infile} if
-@var{infile} is not @code{nil}, and from @file{/dev/null} otherwise.
+@var{infile} is not @code{nil}, and from the null device otherwise.
 The argument @var{destination} says where to put the process output.
 Here are the possibilities:
 
@@ -217,7 +222,7 @@ Insert the output in the current buffer, before point.
 Discard the output.
 
 @item 0
-Discard the output, and return immediately without waiting
+Discard the output, and return @code{nil} immediately without waiting
 for the subprocess to finish.
 
 In this case, the process is not truly synchronous, since it can run in
@@ -225,7 +230,10 @@ parallel with Emacs; but you can think of it as synchronous in that
 Emacs is essentially finished with the subprocess as soon as this
 function returns.
 
-@item (@var{real-destination} @var{error-destination})
+MS-DOS doesn't support asynchronous subprocesses, so this option doesn't
+work there.
+
+@item @code{(@var{real-destination} @var{error-destination})}
 Keep the standard output stream separate from the standard error stream;
 deal with the ordinary output as specified by @var{real-destination},
 and dispose of the error output according to @var{error-destination}.
@@ -240,9 +248,15 @@ buffer.
 @end table
 
 If @var{display} is non-@code{nil}, then @code{call-process} redisplays
-the buffer as output is inserted.  Otherwise the function does no
-redisplay, and the results become visible on the screen only when Emacs
-redisplays that buffer in the normal course of events.
+the buffer as output is inserted.  (However, if the coding system chosen
+for decoding output is @code{undecided}, meaning deduce the encoding
+from the actual data, then redisplay sometimes cannot continue once
+non-@sc{ascii} characters are encountered.  There are fundamental
+reasons why it is hard to fix this; see @ref{Output from Processes}.)
+
+Otherwise the function @code{call-process} does no redisplay, and the
+results become visible on the screen only when Emacs redisplays that
+buffer in the normal course of events.
 
 The remaining arguments, @var{args}, are strings that specify command
 line arguments for the program.
@@ -258,7 +272,7 @@ In the examples below, the buffer @samp{foo} is current.
 @smallexample
 @group
 (call-process "pwd" nil t)
-     @result{} nil
+     @result{} 0
 
 ---------- Buffer: foo ----------
 /usr/user/lewis/manual
@@ -267,7 +281,7 @@ In the examples below, the buffer @samp{foo} is current.
 
 @group
 (call-process "grep" nil "bar" nil "lewis" "/etc/passwd")
-     @result{} nil
+     @result{} 0
 
 ---------- Buffer: bar ----------
 lewis:5LTsHm66CSWKg:398:21:Bil Lewis:/user/lewis:/bin/csh
@@ -290,7 +304,7 @@ be found in the definition of @code{insert-directory}:
 @end defun
 
 @defun call-process-region start end program &optional delete destination display &rest args
-This function sends the text between @var{start} to @var{end} as
+This function sends the text from @var{start} to @var{end} as
 standard input to a process running @var{program}.  It deletes the text
 sent if @var{delete} is non-@code{nil}; this is useful when
 @var{destination} is @code{t}, to insert the output in the current
@@ -301,7 +315,8 @@ with the output from the subprocess, and whether to update the display
 as it comes in.  For details, see the description of
 @code{call-process}, above.  If @var{destination} is the integer 0,
 @code{call-process-region} discards the output and returns @code{nil}
-immediately, without waiting for the subprocess to finish.
+immediately, without waiting for the subprocess to finish (this only
+works if asynchronous subprocesses are supported).
 
 The remaining arguments, @var{args}, are strings that specify command
 line arguments for the program.
@@ -327,7 +342,7 @@ input@point{}
 
 @group
 (call-process-region 1 6 "cat" nil t)
-     @result{} nil
+     @result{} 0
 
 ---------- Buffer: foo ----------
 inputinput@point{}
@@ -351,7 +366,6 @@ inputinput@point{}
 @end smallexample
 @end defun
 
-@tindex shell-command-to-string
 @defun shell-command-to-string command
 This function executes @var{command} (a string) as a shell command,
 then returns the command's output as a string.
@@ -361,11 +375,16 @@ then returns the command's output as a string.
 @section Creating an Asynchronous Process
 @cindex asynchronous subprocess
 
-  After an @dfn{asynchronous process} is created, Emacs and the Lisp
-program both continue running immediately.  The process may thereafter
-run in parallel with Emacs, and the two may communicate with each other
-using the functions described in following sections.  Here we describe
-how to create an asynchronous process with @code{start-process}.
+  After an @dfn{asynchronous process} is created, Emacs and the subprocess
+both continue running immediately.  The process thereafter runs
+in parallel with Emacs, and the two can communicate with each other
+using the functions described in the following sections.  However,
+communication is only partially asynchronous: Emacs sends data to the
+process only when certain functions are called, and Emacs accepts data
+from the process only when Emacs is waiting for input or for a time
+delay.
+
+  Here we describe how to create an asynchronous process.
 
 @defun start-process name buffer-or-name program &rest args
 This function creates a new asynchronous subprocess and starts the
@@ -420,10 +439,10 @@ use.
 The point of running a program through the shell, rather than directly
 with @code{start-process}, is so that you can employ shell features such
 as wildcards in the arguments.  It follows that if you include an
-arbitrary user-specified filename in the command, you should quote it
+arbitrary user-specified arguments in the command, you should quote it
 with @code{shell-quote-argument} first, so that any special shell
-characters in the file name do @emph{not} have their special shell
-meanings.  @xref{Shell Arguments}.
+characters do @emph{not} have their special shell meanings.  @xref{Shell
+Arguments}.
 @end defun
 
 @defvar process-connection-type
@@ -441,7 +460,7 @@ often better to use a pipe, because they are more efficient.  In
 addition, the total number of @sc{pty}s is limited on many systems and
 it is good not to waste them.
 
-The value @code{process-connection-type} is used when
+The value of @code{process-connection-type} is used when
 @code{start-process} is called.  So you can specify how to communicate
 with one subprocess by binding the variable around the call to
 @code{start-process}.
@@ -463,30 +482,38 @@ Information}).
 @cindex deleting processes
 
   @dfn{Deleting a process} disconnects Emacs immediately from the
-subprocess, and removes it from the list of active processes.  It sends
-a signal to the subprocess to make the subprocess terminate, but this is
-not guaranteed to happen immediately.  The process object itself
-continues to exist as long as other Lisp objects point to it.  The
-process mark continues to point to the same place as before (usually
-into a buffer where output from the process was being inserted).
-
-  You can delete a process explicitly at any time.  Processes are
-deleted automatically after they terminate, but not necessarily right
-away.  If you delete a terminated process explicitly before it is
-deleted automatically, no harm results.
-
-@defvar delete-exited-processes
+subprocess.  Processes are deleted automatically after they terminate,
+but not necessarily right away.  You can delete a process explicitly
+at any time.  If you delete a terminated process explicitly before it
+is deleted automatically, no harm results.  Deletion of a running
+process sends a signal to terminate it and calls the process sentinel
+if it has one.
+
+  @code{get-buffer-process} and @code{process-list} do not remember a
+deleted process, but the process object itself continues to exist as
+long as other Lisp objects point to it.  All the Lisp primitives that
+work on process objects accept deleted processes, but those that do
+I/O or send signals will report an error.  The process mark continues
+to point to the same place as before, usually into a buffer where
+output from the process was being inserted.
+
+@defopt delete-exited-processes
 This variable controls automatic deletion of processes that have
 terminated (due to calling @code{exit} or to a signal).  If it is
 @code{nil}, then they continue to exist until the user runs
 @code{list-processes}.  Otherwise, they are deleted immediately after
 they exit.
-@end defvar
+@end defopt
 
 @defun delete-process name
-This function deletes the process associated with @var{name}, killing it
-with a @code{SIGHUP} signal.  The argument @var{name} may be a process,
-the name of a process, a buffer, or the name of a buffer.
+This function deletes the process associated with @var{name}, killing
+it with a @code{SIGKILL} signal.  The argument @var{name} may be a
+process, the name of a process, a buffer, or the name of a buffer.
+Calling @code{delete-process} on a running process terminates it,
+updates the process status, and runs the sentinel (if any) immediately.
+If the process has already terminated, calling @code{delete-process}
+has no effect on its status, or on the running of its sentinel (which
+will happen sooner or later).
 
 @smallexample
 @group
@@ -496,19 +523,6 @@ the name of a process, a buffer, or the name of a buffer.
 @end smallexample
 @end defun
 
-@defun process-kill-without-query process
-This function declares that Emacs need not query the user if
-@var{process} is still running when Emacs is exited.  The process will
-be deleted silently.  The value is @code{t}.
-
-@smallexample
-@group
-(process-kill-without-query (get-process "shell"))
-     @result{} t
-@end group
-@end smallexample
-@end defun
-
 @node Process Information
 @section Process Information
 
@@ -570,7 +584,6 @@ process is started and remains constant as long as the process exists.
 This function returns the name of @var{process}.
 @end defun
 
-@tindex process-contact
 @defun process-contact process
 This function returns @code{t} for an ordinary child process, and
 @code{(@var{hostname} @var{service})} for a net connection
@@ -639,7 +652,6 @@ instead of a terminal (see @code{process-connection-type} in
 @ref{Asynchronous Processes}).
 @end defun
 
-@tindex process-coding-system
 @defun process-coding-system process
 This function returns a cons cell describing the coding systems in use
 for decoding output from @var{process} and for encoding input to
@@ -650,7 +662,6 @@ for decoding output from @var{process} and for encoding input to
 @end example
 @end defun
 
-@tindex set-process-coding-system
 @defun set-process-coding-system process decoding-system encoding-system
 This function specifies the coding systems to use for subsequent output
 from and input to @var{process}.  It will use @var{decoding-system} to
@@ -673,8 +684,18 @@ the other characters, to force them through.  For most programs,
 these @sc{eof}s do no harm.
 
   Subprocess input is normally encoded using a coding system before the
-subprocess receives it, much like text written into a file.
-@xref{Coding Systems}.
+subprocess receives it, much like text written into a file.  You can use
+@code{set-process-coding-system} to specify which coding system to use
+(@pxref{Process Information}).  Otherwise, the coding system comes from
+@code{coding-system-for-write}, if that is non-@code{nil}; or else from
+the defaulting mechanism (@pxref{Default Coding Systems}).
+
+  Sometimes the system is unable to accept input for that process,
+because the input buffer is full.  When this happens, the send functions
+wait a short while, accepting output from subprocesses, and then try
+again.  This gives the subprocess a chance to read more of its pending
+input and make space in the buffer.  It also allows filters, sentinels
+and timers to run---so take account of that in writing your code.
 
 @defun process-send-string process-name string
 This function sends @var{process-name} the contents of @var{string} as
@@ -703,7 +724,7 @@ introduction.txt                text.texi~
 @end smallexample
 @end defun
 
-@deffn Command process-send-region process-name start end
+@defun process-send-region process-name start end
 This function sends the text in the region defined by @var{start} and
 @var{end} as standard input to @var{process-name}, which is a process or
 a process name.  (If it is @code{nil}, the current buffer's process is
@@ -712,7 +733,7 @@ used.)
 An error is signaled unless both @var{start} and @var{end} are
 integers or markers that indicate positions in the current buffer.  (It
 is unimportant which number is larger.)
-@end deffn
+@end defun
 
 @defun process-send-eof &optional process-name
   This function makes @var{process-name} see an end-of-file in its
@@ -732,6 +753,14 @@ error is signaled if the current buffer has no process.
 @end smallexample
 @end defun
 
+@defun process-running-child-p process
+@tindex process-running-child-p process
+This function will tell you whether a subprocess has given control of
+its terminal to its own child process.  The value is @code{t} if this is
+true, or if Emacs cannot tell; it is @code{nil} if Emacs can be certain
+that this is not so.
+@end defun
+
 @node Signals to Processes
 @section Sending Signals to Processes
 @cindex process signals
@@ -826,6 +855,56 @@ a child of Emacs.  The argument @var{signal} specifies which signal
 to send; it should be an integer.
 @end defun
 
+@node Query Before Exit
+@section Querying Before Exit 
+
+  When Emacs exits, it terminates all its subprocesses by sending them
+the @code{SIGHUP} signal.  Because some subprocesses are doing
+valuable work, Emacs normally asks the user to confirm that it is ok
+to terminate them.  Each process has a query flag which, if
+non-@code{nil}, says that Emacs should ask for confirmation before
+exiting and thus killing that process.  The default for the query flag
+is @code{t}, meaning @emph{do} query.
+
+@tindex process-query-on-exit-flag
+@defun process-query-on-exit-flag process
+This returns the query flag of @var{process}.
+@end defun
+
+@tindex set-process-query-on-exit-flag
+@defun set-process-query-on-exit-flag process flag
+This function sets the query flag of @var{process} to @var{flag}.  It
+returns @var{flag}.
+
+@smallexample
+@group
+;; @r{Don't query about the shell process}
+(set-process-query-on-exit-flag (get-process "shell") nil)
+     @result{} t
+@end group
+@end smallexample
+@end defun
+
+@defun process-kill-without-query process &optional do-query
+This function clears the query flag of @var{process}, so that
+Emacs will not query the user on account of that process.
+
+Actually, the function does more than that: it returns the old value of
+the process's query flag, and sets the query flag to @var{do-query}.
+Please don't use this function to do those things any more---please
+use the newer, cleaner functions @code{process-query-on-exit-flag} and
+@code{set-process-query-on-exit-flag} in all but the simplest cases.
+The only way you should use @code{process-kill-without-query} nowadays
+is like this:
+
+@smallexample
+@group
+;; @r{Don't query about the shell process}
+(process-kill-without-query (get-process "shell"))
+@end group
+@end smallexample
+@end defun
+
 @node Output from Processes
 @section Receiving Output from Processes
 @cindex process output
@@ -837,10 +916,40 @@ which is called the associated buffer of the process, or a function
 called the @dfn{filter function} can be called to act on the output.  If
 the process has no buffer and no filter function, its output is
 discarded.
+  Output from a subprocess can arrive only while Emacs is waiting: when
+reading terminal input, in @code{sit-for} and @code{sleep-for}
+(@pxref{Waiting}), and in @code{accept-process-output} (@pxref{Accepting
+Output}).  This minimizes the problem of timing errors that usually
+plague parallel programming.  For example, you can safely create a
+process and only then specify its buffer or filter function; no output
+can arrive before you finish, if the code in between does not call any
+primitive that waits.
+
+  It is impossible to separate the standard output and standard error
+streams of the subprocess, because Emacs normally spawns the subprocess
+inside a pseudo-TTY, and a pseudo-TTY has only one output channel.  If
+you want to keep the output to those streams separate, you should
+redirect one of them to a file--for example, by using an appropriate
+shell command.
 
   Subprocess output is normally decoded using a coding system before the
 buffer or filter function receives it, much like text read from a file.
-@xref{Coding Systems}.
+You can use @code{set-process-coding-system} to specify which coding
+system to use (@pxref{Process Information}).  Otherwise, the coding
+system comes from @code{coding-system-for-read}, if that is
+non-@code{nil}; or else from the defaulting mechanism (@pxref{Default
+Coding Systems}).
+
+  @strong{Warning:} Coding systems such as @code{undecided} which
+determine the coding system from the data do not work entirely reliably
+with asynchronous subprocess output.  This is because Emacs has to
+process asynchronous subprocess output in batches, as it arrives.  Emacs
+must try to detect the proper coding system from one batch at a time,
+and this does not always work.  Therefore, if at all possible, use a
+coding system which determines both the character code conversion and
+the end of line conversion---that is, one like @code{latin-1-unix},
+rather than @code{undecided} or @code{latin-1}.
 
 @menu
 * Process Buffers::       If no filter, output is put in a buffer.
@@ -906,11 +1015,15 @@ associated with no buffer.
 @end defun
 
 @defun get-buffer-process buffer-or-name
-This function returns the process associated with @var{buffer-or-name}.
-If there are several processes associated with it, then one is chosen.
-(Currently, the one chosen is the one most recently created.)  It is
-usually a bad idea to have more than one process associated with the
-same buffer.
+This function returns a nondeleted process associated with the buffer
+specified by @var{buffer-or-name}.  If there are several processes
+associated with it, this function chooses one (currently, the one most
+recently created, but don't count on that).  Deletion of a process
+(see @code{delete-process}) makes it ineligible for this function to
+return.
+
+It is usually a bad idea to have more than one process associated with
+the same buffer.
 
 @smallexample
 @group
@@ -934,19 +1047,16 @@ then @emph{all} output from that process is passed to the filter.  The
 process buffer is used directly for output from the process only when
 there is no filter.
 
+  The filter function can only be called when Emacs is waiting for
+something, because process output arrives only at such times.  Emacs
+waits when reading terminal input, in @code{sit-for} and
+@code{sleep-for} (@pxref{Waiting}), and in @code{accept-process-output}
+(@pxref{Accepting Output}).
+
   A filter function must accept two arguments: the associated process
 and a string, which is output just received from it.  The function is
 then free to do whatever it chooses with the output.
 
-  A filter function 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 filters at random places in
-the middle of other Lisp programs.  You may explicitly cause Emacs to
-wait, so that filter functions will run, by calling @code{sit-for} or
-@code{sleep-for} (@pxref{Waiting}), or @code{accept-process-output}
-(@pxref{Accepting Output}).  Emacs is also waiting when the command loop
-is reading input.
-
   Quitting is normally inhibited within a filter function---otherwise,
 the effect of typing @kbd{C-g} at command level or to quit a user
 command would be unpredictable.  If you want to permit quitting inside a
@@ -1113,9 +1223,7 @@ subprocess output.
 The argument @var{seconds} need not be an integer.  If it is a floating
 point number, this function waits for a fractional number of seconds.
 Some systems support only a whole number of seconds; on these systems,
-@var{seconds} is rounded down.  If the system doesn't support waiting
-fractions of a second, you get an error if you specify nonzero
-@var{millisec}.
+@var{seconds} is rounded down.
 
 Not all operating systems support waiting periods other than multiples
 of a second; on those that do not, you get an error if you specify
@@ -1134,10 +1242,10 @@ arrived.
   A @dfn{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.
+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:
 
@@ -1155,13 +1263,22 @@ of event.
 @code{"@var{name-of-signal} (core dumped)\n"}.
 @end itemize
 
-  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 @code{sit-for} or @code{sleep-for}
+  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 @code{sit-for} or @code{sleep-for}
 (@pxref{Waiting}), or @code{accept-process-output} (@pxref{Accepting
-Output}).  Emacs is also waiting when the command loop is reading input.
+Output}).  Emacs also allows sentinels to run when the command loop is
+reading input.  @code{delete-process} calls the sentinel when it
+terminates a running process.
+
+  Emacs does not keep a queue of multiple reasons to call the sentinel
+of one process; it records just the current status and the fact that
+there has been a change.  Therefore two changes in status, coming in
+quick succession, can call the sentinel just once.  However, process
+termination will always run the sentinel exactly once.  This is
+because the process status can't change again after termination.
 
   Quitting is normally inhibited within a sentinel---otherwise, the
 effect of typing @kbd{C-g} at command level or to quit a user command
@@ -1180,6 +1297,11 @@ programs was running when the sentinel was started.  However, if
 off.  This makes it possible to use the Lisp debugger to debug the
 sentinel.  @xref{Debugger}.
 
+  While a sentinel is running, the process sentinel is temporarily
+set to @code{nil} so that the sentinel won't run recursively.
+For this reason it is not possible for a sentinel to specify
+a new sentinel.
+
   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
@@ -1191,6 +1313,10 @@ This function associates @var{sentinel} with @var{process}.  If
 The default behavior when there is no sentinel is to insert a message in
 the process's buffer when the process status changes.
 
+Changes in process sentinel take effect immediately---if the sentinel
+is slated to be run but has not been called yet, and you specify a new
+sentinel, the eventual call to the sentinel will use the new one.
+
 @smallexample
 @group
 (defun msg-me (process event)
@@ -1245,9 +1371,9 @@ transaction.  The argument @var{fn} is the function to call when the
 corresponding answer comes back; it is called with two arguments:
 @var{closure}, and the answer received.
 
-The argument @var{regexp} is a regular expression that should match the
-entire answer, but nothing less; that's how @code{tq-enqueue} determines
-where the answer ends.
+The argument @var{regexp} is a regular expression that should match
+text at the end of the entire answer, but nothing before; that's how
+@code{tq-enqueue} determines where the answer ends.
 
 The return value of @code{tq-enqueue} itself is not meaningful.
 @end defun