*** empty log message ***
[bpt/emacs.git] / lispref / processes.texi
index 8e32962..2db9cd0 100644 (file)
@@ -77,11 +77,12 @@ cannot be executed.  If the file name is relative, the variable
 @code{exec-path} contains a list of directories to search.  Emacs
 initializes @code{exec-path} when it starts up, based on the value of
 the environment variable @code{PATH}.  The standard file name
-constructs, @samp{~}, @samp{.}, and @samp{..}, are interpreted as usual
-in @code{exec-path}, but environment variable substitutions
+constructs, @samp{~}, @samp{.}, and @samp{..}, are interpreted as
+usual in @code{exec-path}, but environment variable substitutions
 (@samp{$HOME}, etc.) are not recognized; use
 @code{substitute-in-file-name} to perform them (@pxref{File Name
-Expansion}).
+Expansion}).  @code{nil} in this list refers to
+@code{default-directory}.
 
   Executing a program can also try adding suffixes to the specified
 name:
@@ -93,6 +94,10 @@ want the name to be tried exactly as specified.  The default value is
 system-dependent.
 @end defvar
 
+  @strong{Please note:} The argument @var{program} contains only the
+name of the program; it may not contain any command-line arguments.  You
+must use @var{args} to provide those.
+
   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; if it is a buffer name,
@@ -107,12 +112,7 @@ same buffer because their output would be intermixed randomly.
 argument, @var{args}.  The @var{args} must all be strings, and they are
 supplied to @var{program} as separate command line arguments.  Wildcard
 characters and other shell constructs have no special meanings in these
-strings, since the whole strings are passed directly to the specified
-program.
-
-  @strong{Please note:} The argument @var{program} contains only the
-name of the program; it may not contain any command-line arguments.  You
-must use @var{args} to provide those.
+strings, since the strings are passed directly to the specified program.
 
   The subprocess gets its current directory from the value of
 @code{default-directory} (@pxref{File Name Expansion}).
@@ -317,6 +317,47 @@ be found in the definition of @code{insert-directory}:
 @end smallexample
 @end defun
 
+@defun process-file program &optional infile buffer display &rest args
+This function processes files synchronously in a separate process.  It
+is similar to @code{call-process} but may invoke a file handler based
+on the value of the variable @code{default-directory}.  The current
+working directory of the subprocess is @code{default-directory}.
+
+The arguments are handled in almost the same way as for
+@code{call-process}, with the following differences:
+
+Some file handlers may not support all combinations and forms of the
+arguments @var{infile}, @var{buffer}, and @var{display}.  For example,
+some file handlers might behave as if @var{display} were @code{nil},
+regardless of the value actually passed.  As another example, some
+file handlers might not support separating standard output and error
+output by way of the @var{buffer} argument.
+
+If a file handler is invoked, it determines the program to run based
+on the first argument @var{program}.  For instance, consider that a
+handler for remote files is invoked.  Then the path that is used for
+searching the program might be different than @code{exec-path}.
+
+The second argument @var{infile} may invoke a file handler.  The file
+handler could be different from the handler chosen for the
+@code{process-file} function itself.  (For example,
+@code{default-directory} could be on a remote host, whereas
+@var{infile} is on another remote host.  Or @code{default-directory}
+could be non-special, whereas @var{infile} is on a remote host.)
+
+If @var{buffer} has the form @code{(@var{real-destination}
+@var{error-destination})}, and @var{error-destination} names a file,
+then the same remarks as for @var{infile} apply.
+
+The remaining arguments (@var{args}) will be passed to the process
+verbatim.  Emacs is not involved in processing file names that are
+present in @var{args}.  To avoid confusion, it may be best to avoid
+absolute file names in @var{args}, but rather to specify all file
+names as relative to @code{default-directory}.  The function
+@code{file-relative-name} is useful for constructing such relative
+file names.
+@end defun
+
 @defun call-process-region start end program &optional delete destination display &rest args
 This function sends the text from @var{start} to @var{end} as
 standard input to a process running @var{program}.  It deletes the text
@@ -382,7 +423,7 @@ inputinput@point{}
 
 @defun call-process-shell-command command &optional infile destination display &rest args
 This function executes the shell command @var{command} synchronously
-in separate process.  The final arguments @var{args} are additional
+in separate process.  The final arguments @var{args} are additional
 arguments to add at the end of @var{command}.  The other arguments
 are handled as in @code{call-process}.
 @end defun
@@ -506,17 +547,16 @@ Information}).
 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
+is deleted automatically, no harm results.  Deleting a running
 process sends a signal to terminate it (and its child processes if
-any), and calls the process sentinel if it has one.
+any), and calls the process sentinel if it has one.  @xref{Sentinels}.
 
-  @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.
+  When a process is deleted, 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
@@ -526,15 +566,16 @@ terminated (due to calling @code{exit} or to a signal).  If it is
 they exit.
 @end defopt
 
-@defun delete-process name
-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).
+@defun delete-process process
+This function deletes a process, killing it with a @code{SIGKILL}
+signal.  The argument may be a process, the name of a process, a
+buffer, or the name of a buffer.  (A buffer or buffer-name stands for
+the process that @code{get-buffer-process} returns.)  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
@@ -676,8 +717,8 @@ instead of a terminal (see @code{process-connection-type} in
 @ref{Asynchronous Processes}).
 @end defun
 
-@anchor{Coding systems for a subprocess}
 @defun process-coding-system process
+@anchor{Coding systems for a subprocess}
 This function returns a cons cell describing the coding systems in use
 for decoding output from @var{process} and for encoding input to
 @var{process} (@pxref{Coding Systems}).  The value has this form:
@@ -687,7 +728,7 @@ for decoding output from @var{process} and for encoding input to
 @end example
 @end defun
 
-@defun set-process-coding-system process decoding-system encoding-system
+@defun set-process-coding-system process &optional 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
 decode subprocess output, and @var{encoding-system} to encode subprocess
@@ -743,11 +784,14 @@ 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
-standard input.  The argument @var{process-name} must be a process or
-the name of a process.  If it is @code{nil}, the current buffer's
-process is used.
+  In these functions, the @var{process} argument can be a process or
+the name of a process, or a buffer or buffer name (which stands
+for a process via @code{get-buffer-process}).  @code{nil} means
+the current buffer's process.
+
+@defun process-send-string process string
+This function sends @var{process} the contents of @var{string} as
+standard input.  If it is @code{nil}, the current buffer's process is used.
 
   The function returns @code{nil}.
 
@@ -770,26 +814,20 @@ introduction.txt                text.texi~
 @end smallexample
 @end defun
 
-@defun process-send-region process-name start end
+@defun process-send-region process 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
-used.)
+@var{end} as standard input to @var{process}.
 
 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 defun
 
-@defun process-send-eof &optional process-name
-  This function makes @var{process-name} see an end-of-file in its
+@defun process-send-eof &optional process
+This function makes @var{process} see an end-of-file in its
 input.  The @acronym{EOF} comes after any text already sent to it.
 
-  If @var{process-name} is not supplied, or if it is @code{nil}, then
-this function sends the @acronym{EOF} to the current buffer's process.  An
-error is signaled if the current buffer has no process.
-
-  The function returns @var{process-name}.
+The function returns @var{process}.
 
 @smallexample
 @group
@@ -834,10 +872,11 @@ user hung up the phone.)
   Each of the signal-sending functions takes two optional arguments:
 @var{process-name} and @var{current-group}.
 
-  The argument @var{process-name} must be either a process, the name of
-one, or @code{nil}.  If it is @code{nil}, the process defaults to the
-process associated with the current buffer.  An error is signaled if
-@var{process-name} does not identify a process.
+  The argument @var{process} must be either a process, a process
+name, a buffer, a buffer name, or @code{nil}.  A buffer or buffer name
+stands for a process through @code{get-buffer-process}.  @code{nil}
+stands for the process associated with the current buffer.  An error
+is signaled if @var{process} does not identify a process.
 
   The argument @var{current-group} is a flag that makes a difference
 when you are running a job-control shell as an Emacs subprocess.  If it
@@ -854,8 +893,8 @@ support the distinction in the case of pipes.  For the same reason,
 job-control shells won't work when a pipe is used.  See
 @code{process-connection-type} in @ref{Asynchronous Processes}.
 
-@defun interrupt-process &optional process-name current-group
-This function interrupts the process @var{process-name} by sending the
+@defun interrupt-process &optional process current-group
+This function interrupts the process @var{process} by sending the
 signal @code{SIGINT}.  Outside of Emacs, typing the ``interrupt
 character'' (normally @kbd{C-c} on some systems, and @code{DEL} on
 others) sends this signal.  When the argument @var{current-group} is
@@ -863,21 +902,21 @@ non-@code{nil}, you can think of this function as ``typing @kbd{C-c}''
 on the terminal by which Emacs talks to the subprocess.
 @end defun
 
-@defun kill-process &optional process-name current-group
-This function kills the process @var{process-name} by sending the
+@defun kill-process &optional process current-group
+This function kills the process @var{process} by sending the
 signal @code{SIGKILL}.  This signal kills the subprocess immediately,
 and cannot be handled by the subprocess.
 @end defun
 
-@defun quit-process &optional process-name current-group
+@defun quit-process &optional process current-group
 This function sends the signal @code{SIGQUIT} to the process
-@var{process-name}.  This signal is the one sent by the ``quit
+@var{process}.  This signal is the one sent by the ``quit
 character'' (usually @kbd{C-b} or @kbd{C-\}) when you are not inside
 Emacs.
 @end defun
 
-@defun stop-process &optional process-name current-group
-This function stops the process @var{process-name} by sending the
+@defun stop-process &optional process current-group
+This function stops the process @var{process} by sending the
 signal @code{SIGTSTP}.  Use @code{continue-process} to resume its
 execution.
 
@@ -888,9 +927,9 @@ Outside of Emacs, on systems with job control, the ``stop character''
 subprocess.
 @end defun
 
-@defun continue-process &optional process-name current-group
+@defun continue-process &optional process current-group
 This function resumes execution of the process @var{process} by sending
-it the signal @code{SIGCONT}.  This presumes that @var{process-name} was
+it the signal @code{SIGCONT}.  This presumes that @var{process} was
 stopped previously.
 @end defun
 
@@ -899,8 +938,9 @@ stopped previously.
 This function sends a signal to process @var{process}.  The argument
 @var{signal} specifies which signal to send; it should be an integer.
 
-You can specify the target process by its process @acronym{ID}; that allows
-you to send signals to processes that are not children of Emacs.
+The @var{process} argument can be a system process @acronym{ID}; that
+allows you to send signals to processes that are not children of
+Emacs.
 @end defun
 
 @node Output from Processes
@@ -929,11 +969,21 @@ 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.
 
+@defvar process-adaptive-read-buffering
+On some systems, when Emacs reads the output from a subprocess, the
+output data is read in very small blocks, potentially resulting in
+very poor performance.  This behaviour can be remedied to some extent
+by setting the variable @var{process-adaptive-read-buffering} to a
+non-@code{nil} value (the default), as it will automatically delay reading
+from such processes, thus allowing them to produce more output before
+Emacs tries to read it.
+@end defvar
+
   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
+redirect one of them to a file---for example, by using an appropriate
 shell command.
 
 @menu
@@ -1189,7 +1239,7 @@ there is no filter function:
 it decodes the output according to the process output coding system.
 If the coding system is @code{raw-text} or @code{no-conversion}, Emacs
 converts the unibyte output to multibyte using
-@code{string-to-multibyte}, inserts the resulting multibyte text.
+@code{string-to-multibyte}, and inserts the resulting multibyte text.
 
   You can use @code{set-process-coding-system} to specify which coding
 system to use (@pxref{Process Information}).  Otherwise, the coding
@@ -1240,7 +1290,7 @@ or terminal input.  Occasionally it is useful in a Lisp program to
 explicitly permit output to arrive at a specific point, or even to wait
 until output arrives from a process.
 
-@defun accept-process-output &optional process seconds millisec
+@defun accept-process-output &optional process seconds millisec just-this-one
 This function allows Emacs to read pending output from processes.  The
 output is inserted in the associated buffers or given to their filter
 functions.  If @var{process} is non-@code{nil} then this function does
@@ -1263,6 +1313,15 @@ 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
 nonzero @var{millisec}.
 
+@c Emacs 22.1 feature
+If @var{process} is a process, and the argument @var{just-this-one} is
+non-@code{nil}, only output from that process is handled, suspending output
+from other processes until some output has been received from that
+process or the timeout expires.  If @var{just-this-one} is an integer,
+also inhibit running timers.  This feature is generally not
+recommended, but may be necessary for specific applications, such as
+speech synthesis.
+
 The function @code{accept-process-output} returns non-@code{nil} if it
 did get some output, or @code{nil} if the timeout expired before output
 arrived.
@@ -1383,7 +1442,7 @@ was not.
 @section Querying Before Exit
 
   When Emacs exits, it terminates all its subprocesses by sending them
-the @code{SIGHUP} signal.  Because some subprocesses are doing
+the @code{SIGHUP} signal.  Because subprocesses may be 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
@@ -1512,7 +1571,7 @@ and @code{failed}.  For a network server, the status is always
 @code{listen}.  None of those values is possible for a real
 subprocess.  @xref{Process Information}.
 
-  You can stop and resume operation of a network processes by calling
+  You can stop and resume operation of a network process by calling
 @code{stop-process} and @code{continue-process}.  For a server
 process, being stopped means not accepting new connections.  (Up to 5
 connection requests will be queued for when you resume the server; you
@@ -1647,7 +1706,7 @@ The client process' plist is initialized from the server's plist.
 
 @defun open-network-stream-server name buffer-or-name service &optional sentinel filter
 Create a network server process for a TCP service.
-It returns nil if server processes are not supported; otherwise,
+It returns @code{nil} if server processes are not supported; otherwise,
 it returns a subprocess-object to represent the server.
 
 When a client connects to the specified service, Emacs creates a new
@@ -1664,13 +1723,13 @@ meaning ask the system to allocate an unused port to listen on.
 @end defun
 
 @node Datagrams
-@section Datagrams 
+@section Datagrams
 @cindex datagrams
 
-  A datagram connection communicates with individual packets
-rather than streams of data.  Each call to @code{process-send}
-sends one datagram packet, and each datagram received results
-in one call to the filter function.
+  A datagram connection communicates with individual packets rather
+than streams of data.  Each call to @code{process-send} sends one
+datagram packet (@pxref{Input to Processes}), and each datagram
+received results in one call to the filter function.
 
   The datagram connection doesn't have to talk with the same remote
 peer all the time.  It has a @dfn{remote peer address} which specifies
@@ -1771,10 +1830,10 @@ in the local address space.
 @item
 An ``unsupported family'' address is represented by a cons
 @code{(@var{f} . @var{av})}, where @var{f} is the family number and
-@var{av} is a vector specifying the socket address using with one
-element per address data byte.  Do not rely on this format in portable
-code, as it may depend on implementation defined constants, data
-sizes, and data structure alignment.
+@var{av} is a vector specifying the socket address using one element
+per address data byte.  Do not rely on this format in portable code,
+as it may depend on implementation defined constants, data sizes, and
+data structure alignment.
 @end itemize
 
 @item :nowait @var{bool}
@@ -1843,8 +1902,8 @@ child connection as they are created.
 @item :bindtodevice @var{device-name}
 If @var{device-name} is a non-empty string identifying a network
 interface name (see @code{network-interface-list}), only handle
-packets received on that interface.  If @var{device-name} is nil (the
-default), handle packets received on any interface.
+packets received on that interface.  If @var{device-name} is @code{nil}
+(the default), handle packets received on any interface.
 
 Using this option may require special privileges on some systems.
 
@@ -1860,7 +1919,7 @@ to hosts on the same network as the local host.
 
 @item :keepalive @var{keepalive-flag}
 If @var{keepalive-flag} is non-@code{nil} for a stream connection,
-enable exchange of low-level keep-alive messa
+enable exchange of low-level keep-alive messages.
 
 @item :linger @var{linger-arg}
 If @var{linger-arg} is non-@code{nil}, wait for successful
@@ -1896,7 +1955,7 @@ that port.
 @end table
 
 The original argument list, modified with the actual connection
-information, is available via the `process-contact' function.
+information, is available via the @code{process-contact} function.
 @end defun
 
 @defun set-network-process-option process option value
@@ -1905,7 +1964,7 @@ This function sets or modifies a network option for network process
 @var{option} and their corresponding values @var{value}.
 
 The current setting of an option is available via the
-`process-contact' function.
+@code{process-contact} function.
 @end defun
 
 @defun network-interface-list
@@ -1951,7 +2010,7 @@ the port number.
 
 @example
 (featurep 'make-network-process '(@var{keyword} @var{value}))
-@end example 
+@end example
 
 @noindent
 The result of the first form is @code{t} if it works to specify
@@ -1977,7 +2036,7 @@ Non-@code{nil} if the system can select the port for a server.
 
 @example
 (featurep 'make-network-process '@var{keyword})
-@end example 
+@end example
 
 Here are some of the option @var{keyword}s you can test in
 this way.