1 This is ../info/lispref.info, produced by makeinfo version 4.0 from
4 INFO-DIR-SECTION XEmacs Editor
6 * Lispref: (lispref). XEmacs Lisp Reference Manual.
11 GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
12 Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
13 Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
14 XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
15 GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
16 Programmer's Manual (for 19.13) Third Edition, July 1995 XEmacs Lisp
17 Reference Manual (for 19.14 and 20.0) v3.1, March 1996 XEmacs Lisp
18 Reference Manual (for 19.15 and 20.1, 20.2, 20.3) v3.2, April, May,
19 November 1997 XEmacs Lisp Reference Manual (for 21.0) v3.3, April 1998
21 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
22 Foundation, Inc. Copyright (C) 1994, 1995 Sun Microsystems, Inc.
23 Copyright (C) 1995, 1996 Ben Wing.
25 Permission is granted to make and distribute verbatim copies of this
26 manual provided the copyright notice and this permission notice are
27 preserved on all copies.
29 Permission is granted to copy and distribute modified versions of
30 this manual under the conditions for verbatim copying, provided that the
31 entire resulting derived work is distributed under the terms of a
32 permission notice identical to this one.
34 Permission is granted to copy and distribute translations of this
35 manual into another language, under the above conditions for modified
36 versions, except that this permission notice may be stated in a
37 translation approved by the Foundation.
39 Permission is granted to copy and distribute modified versions of
40 this manual under the conditions for verbatim copying, provided also
41 that the section entitled "GNU General Public License" is included
42 exactly as in the original, and provided that the entire resulting
43 derived work is distributed under the terms of a permission notice
44 identical to this one.
46 Permission is granted to copy and distribute translations of this
47 manual into another language, under the above conditions for modified
48 versions, except that the section entitled "GNU General Public License"
49 may be included in a translation approved by the Free Software
50 Foundation instead of in the original English.
53 File: lispref.info, Node: Working With Hash Tables, Next: Weak Hash Tables, Prev: Introduction to Hash Tables, Up: Hash Tables
55 Working With Hash Tables
56 ========================
58 - Function: puthash key value hash-table
59 This function hashes KEY to VALUE in HASH-TABLE.
61 - Function: gethash key hash-table &optional default
62 This function finds the hash value for KEY in HASH-TABLE. If
63 there is no entry for KEY in HASH-TABLE, DEFAULT is returned
64 (which in turn defaults to `nil').
66 - Function: remhash key hash-table
67 This function removes the entry for KEY from HASH-TABLE. Does
68 nothing if there is no entry for KEY in HASH-TABLE.
70 - Function: clrhash hash-table
71 This function removes all entries from HASH-TABLE, leaving it
74 - Function: maphash function hash-table
75 This function maps FUNCTION over entries in HASH-TABLE, calling it
76 with two args, each key and value in the hash table.
78 FUNCTION may not modify HASH-TABLE, with the one exception that
79 FUNCTION may remhash or puthash the entry currently being
80 processed by FUNCTION.
83 File: lispref.info, Node: Weak Hash Tables, Prev: Working With Hash Tables, Up: Hash Tables
88 A "weak hash table" is a special variety of hash table whose
89 elements do not count as GC referents. For any key-value pair in such a
90 hash table, if either the key or value (or in some cases, if one
91 particular one of the two) has no references to it outside of weak hash
92 tables (and similar structures such as weak lists), the pair will be
93 removed from the table, and the key and value collected. A non-weak
94 hash table (or any other pointer) would prevent the objects from being
97 Weak hash tables are useful for keeping track of information in a
98 non-obtrusive way, for example to implement caching. If the cache
99 contains objects such as buffers, markers, image instances, etc. that
100 will eventually disappear and get garbage-collected, using a weak hash
101 table ensures that these objects are collected normally rather than
102 remaining around forever, long past their actual period of use.
103 (Otherwise, you'd have to explicitly map over the hash table every so
104 often and remove unnecessary elements.)
106 There are four types of weak hash tables:
108 key-and-value-weak hash tables
109 In these hash tables, also known as fully weak or simply as weak
110 hash tables, a pair disappears if either the key or the value is
111 unreferenced outside of the table.
114 In these hash tables, a pair disappears if the key is unreferenced
115 outside of the table, regardless of how the value is referenced.
117 value-weak hash tables
118 In these hash tables, a pair disappears if the value is
119 unreferenced outside of the table, regardless of how the key is
122 key-or-value-weak hash tables
123 In these hash tables, a pair disappears if both the key and the
124 value are unreferenced outside of the table.
126 Also see *Note Weak Lists::.
128 Weak hash tables are created by specifying the `:weakness' keyword to
132 File: lispref.info, Node: Range Tables, Next: Databases, Prev: Hash Tables, Up: Top
137 A range table is a table that efficiently associated values with
140 Note that range tables have a read syntax, like this:
142 #s(range-table data ((-3 2) foo (5 20) bar))
144 This maps integers in the range (-3, 2) to `foo' and integers in the
145 range (5, 20) to `bar'.
147 - Function: range-table-p object
148 Return non-`nil' if OBJECT is a range table.
152 * Introduction to Range Tables:: Range tables efficiently map ranges of
154 * Working With Range Tables:: Range table functions.
157 File: lispref.info, Node: Introduction to Range Tables, Next: Working With Range Tables, Up: Range Tables
159 Introduction to Range Tables
160 ============================
162 - Function: make-range-table
163 Make a new, empty range table.
165 - Function: copy-range-table old-table
166 Make a new range table which contains the same values for the same
167 ranges as the given table. The values will not themselves be
171 File: lispref.info, Node: Working With Range Tables, Prev: Introduction to Range Tables, Up: Range Tables
173 Working With Range Tables
174 =========================
176 - Function: get-range-table pos table &optional default
177 This function finds value for position POS in TABLE. If there is
178 no corresponding value, return DEFAULT (defaults to `nil').
180 - Function: put-range-table start end val table
181 This function sets the value for range (START, END) to be VAL in
184 - Function: remove-range-table start end table
185 This function removes the value for range (START, END) in TABLE.
187 - Function: clear-range-table table
188 This function flushes TABLE.
190 - Function: map-range-table function table
191 This function maps FUNCTION over entries in TABLE, calling it with
192 three args, the beginning and end of the range and the
196 File: lispref.info, Node: Databases, Next: Processes, Prev: Range Tables, Up: Top
201 - Function: databasep object
202 This function returns non-`nil' if OBJECT is a database.
206 * Connecting to a Database::
207 * Working With a Database::
208 * Other Database Functions::
211 File: lispref.info, Node: Connecting to a Database, Next: Working With a Database, Up: Databases
213 Connecting to a Database
214 ========================
216 - Function: open-database file &optional type subtype access mode
217 This function opens database FILE, using database method TYPE and
218 SUBTYPE, with access rights ACCESS and permissions MODE. ACCESS
219 can be any combination of `r' `w' and `+', for read, write, and
222 TYPE can have the value `'dbm' or `'berkeley-db' to select the
223 type of database file to use. (Note: XEmacs may not support both
226 For a TYPE of `'dbm', there are no subtypes, so SUBTYPE should be
229 For a TYPE of `'berkeley-db', the following subtypes are
230 available: `'hash', `'btree', and `'recno'. See the manpages for
231 the Berkeley DB functions for more information about these types.
233 - Function: close-database obj
234 This function closes database OBJ.
236 - Function: database-live-p obj
237 This function returns `t' iff OBJ is an active database, else
241 File: lispref.info, Node: Working With a Database, Next: Other Database Functions, Prev: Connecting to a Database, Up: Databases
243 Working With a Database
244 =======================
246 - Function: get-database key dbase &optional default
247 This function finds the value for KEY in DATABASE. If there is no
248 corresponding value, DEFAULT is returned (`nil' if DEFAULT is
251 - Function: map-database function dbase
252 This function maps FUNCTION over entries in DATABASE, calling it
253 with two args, each key and value in the database.
255 - Function: put-database key val dbase &optional replace
256 This function stores KEY and VAL in DATABASE. If optional fourth
257 arg REPLACE is non-`nil', replace any existing entry in the
260 - Function: remove-database key dbase
261 This function removes KEY from DATABASE.
264 File: lispref.info, Node: Other Database Functions, Prev: Working With a Database, Up: Databases
266 Other Database Functions
267 ========================
269 - Function: database-file-name obj
270 This function returns the filename associated with the database
273 - Function: database-last-error &optional obj
274 This function returns the last error associated with database OBJ.
276 - Function: database-subtype obj
277 This function returns the subtype of database OBJ, if any.
279 - Function: database-type obj
280 This function returns the type of database OBJ.
283 File: lispref.info, Node: Processes, Next: System Interface, Prev: Databases, Up: Top
288 In the terminology of operating systems, a "process" is a space in
289 which a program can execute. XEmacs runs in a process. XEmacs Lisp
290 programs can invoke other programs in processes of their own. These are
291 called "subprocesses" or "child processes" of the XEmacs process, which
292 is their "parent process".
294 A subprocess of XEmacs may be "synchronous" or "asynchronous",
295 depending on how it is created. When you create a synchronous
296 subprocess, the Lisp program waits for the subprocess to terminate
297 before continuing execution. When you create an asynchronous
298 subprocess, it can run in parallel with the Lisp program. This kind of
299 subprocess is represented within XEmacs by a Lisp object which is also
300 called a "process". Lisp programs can use this object to communicate
301 with the subprocess or to control it. For example, you can send
302 signals, obtain status information, receive output from the process, or
305 - Function: processp object
306 This function returns `t' if OBJECT is a process, `nil' otherwise.
310 * Subprocess Creation:: Functions that start subprocesses.
311 * Synchronous Processes:: Details of using synchronous subprocesses.
312 * MS-DOS Subprocesses:: On MS-DOS, you must indicate text vs binary
313 for data sent to and from a subprocess.
314 * Asynchronous Processes:: Starting up an asynchronous subprocess.
315 * Deleting Processes:: Eliminating an asynchronous subprocess.
316 * Process Information:: Accessing run-status and other attributes.
317 * Input to Processes:: Sending input to an asynchronous subprocess.
318 * Signals to Processes:: Stopping, continuing or interrupting
319 an asynchronous subprocess.
320 * Output from Processes:: Collecting output from an asynchronous subprocess.
321 * Sentinels:: Sentinels run when process run-status changes.
322 * Process Window Size:: Changing the logical window size of a process.
323 * Transaction Queues:: Transaction-based communication with subprocesses.
324 * Network:: Opening network connections.
327 File: lispref.info, Node: Subprocess Creation, Next: Synchronous Processes, Up: Processes
329 Functions that Create Subprocesses
330 ==================================
332 There are three functions that create a new subprocess in which to
333 run a program. One of them, `start-process', creates an asynchronous
334 process and returns a process object (*note Asynchronous Processes::).
335 The other two, `call-process' and `call-process-region', create a
336 synchronous process and do not return a process object (*note
337 Synchronous Processes::).
339 Synchronous and asynchronous processes are explained in following
340 sections. Since the three functions are all called in a similar
341 fashion, their common arguments are described here.
343 In all cases, the function's PROGRAM argument specifies the program
344 to be run. An error is signaled if the file is not found or cannot be
345 executed. If the file name is relative, the variable `exec-path'
346 contains a list of directories to search. Emacs initializes
347 `exec-path' when it starts up, based on the value of the environment
348 variable `PATH'. The standard file name constructs, `~', `.', and
349 `..', are interpreted as usual in `exec-path', but environment variable
350 substitutions (`$HOME', etc.) are not recognized; use
351 `substitute-in-file-name' to perform them (*note File Name Expansion::).
353 Each of the subprocess-creating functions has a BUFFER-OR-NAME
354 argument which specifies where the standard output from the program will
355 go. If BUFFER-OR-NAME is `nil', that says to discard the output unless
356 a filter function handles it. (*Note Filter Functions::, and *Note
357 Read and Print::.) Normally, you should avoid having multiple
358 processes send output to the same buffer because their output would be
361 All three of the subprocess-creating functions have a `&rest'
362 argument, ARGS. The ARGS must all be strings, and they are supplied to
363 PROGRAM as separate command line arguments. Wildcard characters and
364 other shell constructs are not allowed in these strings, since they are
365 passed directly to the specified program.
367 *Please note:* The argument PROGRAM contains only the name of the
368 program; it may not contain any command-line arguments. You must use
369 ARGS to provide those.
371 The subprocess gets its current directory from the value of
372 `default-directory' (*note File Name Expansion::).
374 The subprocess inherits its environment from XEmacs; but you can
375 specify overrides for it with `process-environment'. *Note System
378 - Variable: exec-directory
379 The value of this variable is the name of a directory (a string)
380 that contains programs that come with XEmacs, that are intended
381 for XEmacs to invoke. The program `wakeup' is an example of such
382 a program; the `display-time' command uses it to get a reminder
385 - User Option: exec-path
386 The value of this variable is a list of directories to search for
387 programs to run in subprocesses. Each element is either the name
388 of a directory (i.e., a string), or `nil', which stands for the
389 default directory (which is the value of `default-directory').
391 The value of `exec-path' is used by `call-process' and
392 `start-process' when the PROGRAM argument is not an absolute file
396 File: lispref.info, Node: Synchronous Processes, Next: MS-DOS Subprocesses, Prev: Subprocess Creation, Up: Processes
398 Creating a Synchronous Process
399 ==============================
401 After a "synchronous process" is created, XEmacs waits for the
402 process to terminate before continuing. Starting Dired is an example of
403 this: it runs `ls' in a synchronous process, then modifies the output
404 slightly. Because the process is synchronous, the entire directory
405 listing arrives in the buffer before XEmacs tries to do anything with
408 While Emacs waits for the synchronous subprocess to terminate, the
409 user can quit by typing `C-g'. The first `C-g' tries to kill the
410 subprocess with a `SIGINT' signal; but it waits until the subprocess
411 actually terminates before quitting. If during that time the user
412 types another `C-g', that kills the subprocess instantly with `SIGKILL'
413 and quits immediately. *Note Quitting::.
415 The synchronous subprocess functions returned `nil' in version 18.
416 In version 19, they return an indication of how the process terminated.
418 - Function: call-process program &optional infile destination display
420 This function calls PROGRAM in a separate process and waits for it
423 The standard input for the process comes from file INFILE if
424 INFILE is not `nil' and from `/dev/null' otherwise. The argument
425 DESTINATION says where to put the process output. Here are the
429 Insert the output in that buffer, before point. This
430 includes both the standard output stream and the standard
431 error stream of the process.
434 Find or create a buffer with that name, then insert the
435 output in that buffer, before point.
438 Insert the output in the current buffer, before point.
444 Discard the output, and return immediately without waiting
445 for the subprocess to finish.
447 In this case, the process is not truly synchronous, since it
448 can run in parallel with Emacs; but you can think of it as
449 synchronous in that Emacs is essentially finished with the
450 subprocess as soon as this function returns.
452 (REAL-DESTINATION ERROR-DESTINATION)
453 Keep the standard output stream separate from the standard
454 error stream; deal with the ordinary output as specified by
455 REAL-DESTINATION, and dispose of the error output according
456 to ERROR-DESTINATION. The value `nil' means discard it, `t'
457 means mix it with the ordinary output, and a string specifies
458 a file name to redirect error output into.
460 You can't directly specify a buffer to put the error output
461 in; that is too difficult to implement. But you can achieve
462 this result by sending the error output to a temporary file
463 and then inserting the file into a buffer.
465 If DISPLAY is non-`nil', then `call-process' redisplays the buffer
466 as output is inserted. Otherwise the function does no redisplay,
467 and the results become visible on the screen only when XEmacs
468 redisplays that buffer in the normal course of events.
470 The remaining arguments, ARGS, are strings that specify command
471 line arguments for the program.
473 The value returned by `call-process' (unless you told it not to
474 wait) indicates the reason for process termination. A number
475 gives the exit status of the subprocess; 0 means success, and any
476 other value means failure. If the process terminated with a
477 signal, `call-process' returns a string describing the signal.
479 In the examples below, the buffer `foo' is current.
481 (call-process "pwd" nil t)
484 ---------- Buffer: foo ----------
485 /usr/user/lewis/manual
486 ---------- Buffer: foo ----------
488 (call-process "grep" nil "bar" nil "lewis" "/etc/passwd")
491 ---------- Buffer: bar ----------
492 lewis:5LTsHm66CSWKg:398:21:Bil Lewis:/user/lewis:/bin/csh
494 ---------- Buffer: bar ----------
496 The `insert-directory' function contains a good example of the use
499 (call-process insert-directory-program nil t nil switches
501 (concat (file-name-as-directory file) ".")
504 - Function: call-process-region start end program &optional delete
505 destination display &rest args
506 This function sends the text between START to END as standard
507 input to a process running PROGRAM. It deletes the text sent if
508 DELETE is non-`nil'; this is useful when BUFFER is `t', to insert
509 the output in the current buffer.
511 The arguments DESTINATION and DISPLAY control what to do with the
512 output from the subprocess, and whether to update the display as
513 it comes in. For details, see the description of `call-process',
514 above. If DESTINATION is the integer 0, `call-process-region'
515 discards the output and returns `nil' immediately, without waiting
516 for the subprocess to finish.
518 The remaining arguments, ARGS, are strings that specify command
519 line arguments for the program.
521 The return value of `call-process-region' is just like that of
522 `call-process': `nil' if you told it to return without waiting;
523 otherwise, a number or string which indicates how the subprocess
526 In the following example, we use `call-process-region' to run the
527 `cat' utility, with standard input being the first five characters
528 in buffer `foo' (the word `input'). `cat' copies its standard
529 input into its standard output. Since the argument DESTINATION is
530 `t', this output is inserted in the current buffer.
532 ---------- Buffer: foo ----------
534 ---------- Buffer: foo ----------
536 (call-process-region 1 6 "cat" nil t)
539 ---------- Buffer: foo ----------
541 ---------- Buffer: foo ----------
543 The `shell-command-on-region' command uses `call-process-region'
548 shell-file-name ; Name of program.
549 nil ; Do not delete region.
550 buffer ; Send output to `buffer'.
551 nil ; No redisplay during output.
552 "-c" command) ; Arguments for the shell.
555 File: lispref.info, Node: MS-DOS Subprocesses, Next: Asynchronous Processes, Prev: Synchronous Processes, Up: Processes
560 On MS-DOS, you must indicate whether the data going to and from a
561 synchronous subprocess are text or binary. Text data requires
562 translation between the end-of-line convention used within Emacs (a
563 single newline character) and the convention used outside Emacs (the
564 two-character sequence, CRLF).
566 The variable `binary-process-input' applies to input sent to the
567 subprocess, and `binary-process-output' applies to output received from
568 it. A non-`nil' value means the data is non-text; `nil' means the data
569 is text, and calls for conversion.
571 - Variable: binary-process-input
572 If this variable is `nil', convert newlines to CRLF sequences in
573 the input to a synchronous subprocess.
575 - Variable: binary-process-output
576 If this variable is `nil', convert CRLF sequences to newlines in
577 the output from a synchronous subprocess.
579 *Note Files and MS-DOS::, for related information.
582 File: lispref.info, Node: Asynchronous Processes, Next: Deleting Processes, Prev: MS-DOS Subprocesses, Up: Processes
584 Creating an Asynchronous Process
585 ================================
587 After an "asynchronous process" is created, Emacs and the Lisp
588 program both continue running immediately. The process may thereafter
589 run in parallel with Emacs, and the two may communicate with each other
590 using the functions described in following sections. Here we describe
591 how to create an asynchronous process with `start-process'.
593 - Function: start-process name buffer-or-name program &rest args
594 This function creates a new asynchronous subprocess and starts the
595 program PROGRAM running in it. It returns a process object that
596 stands for the new subprocess in Lisp. The argument NAME
597 specifies the name for the process object; if a process with this
598 name already exists, then NAME is modified (by adding `<1>', etc.)
599 to be unique. The buffer BUFFER-OR-NAME is the buffer to
600 associate with the process.
602 The remaining arguments, ARGS, are strings that specify command
603 line arguments for the program.
605 In the example below, the first process is started and runs
606 (rather, sleeps) for 100 seconds. Meanwhile, the second process
607 is started, and given the name `my-process<1>' for the sake of
608 uniqueness. It inserts the directory listing at the end of the
609 buffer `foo', before the first process finishes. Then it
610 finishes, and a message to that effect is inserted in the buffer.
611 Much later, the first process finishes, and another message is
612 inserted in the buffer for it.
614 (start-process "my-process" "foo" "sleep" "100")
615 => #<process my-process>
617 (start-process "my-process" "foo" "ls" "-l" "/user/lewis/bin")
618 => #<process my-process<1>>
620 ---------- Buffer: foo ----------
622 lrwxrwxrwx 1 lewis 14 Jul 22 10:12 gnuemacs --> /emacs
623 -rwxrwxrwx 1 lewis 19 Jul 30 21:02 lemon
625 Process my-process<1> finished
627 Process my-process finished
628 ---------- Buffer: foo ----------
630 - Function: start-process-shell-command name buffer-or-name command
632 This function is like `start-process' except that it uses a shell
633 to execute the specified command. The argument COMMAND is a shell
634 command name, and COMMAND-ARGS are the arguments for the shell
637 - Variable: process-connection-type
638 This variable controls the type of device used to communicate with
639 asynchronous subprocesses. If it is non-`nil', then PTYs are
640 used, when available. Otherwise, pipes are used.
642 PTYs are usually preferable for processes visible to the user, as
643 in Shell mode, because they allow job control (`C-c', `C-z', etc.)
644 to work between the process and its children whereas pipes do not.
645 For subprocesses used for internal purposes by programs, it is
646 often better to use a pipe, because they are more efficient. In
647 addition, the total number of PTYs is limited on many systems and
648 it is good not to waste them.
650 The value `process-connection-type' is used when `start-process'
651 is called. So you can specify how to communicate with one
652 subprocess by binding the variable around the call to
655 (let ((process-connection-type nil)) ; Use a pipe.
658 To determine whether a given subprocess actually got a pipe or a
659 PTY, use the function `process-tty-name' (*note Process
663 File: lispref.info, Node: Deleting Processes, Next: Process Information, Prev: Asynchronous Processes, Up: Processes
668 "Deleting a process" disconnects XEmacs immediately from the
669 subprocess, and removes it from the list of active processes. It sends
670 a signal to the subprocess to make the subprocess terminate, but this is
671 not guaranteed to happen immediately. The process object itself
672 continues to exist as long as other Lisp objects point to it.
674 You can delete a process explicitly at any time. Processes are
675 deleted automatically after they terminate, but not necessarily right
676 away. If you delete a terminated process explicitly before it is
677 deleted automatically, no harm results.
679 - Variable: delete-exited-processes
680 This variable controls automatic deletion of processes that have
681 terminated (due to calling `exit' or to a signal). If it is
682 `nil', then they continue to exist until the user runs
683 `list-processes'. Otherwise, they are deleted immediately after
686 - Function: delete-process name
687 This function deletes the process associated with NAME, killing it
688 with a `SIGHUP' signal. The argument NAME may be a process, the
689 name of a process, a buffer, or the name of a buffer.
691 (delete-process "*shell*")
694 - Function: process-kill-without-query process &optional
696 This function declares that XEmacs need not query the user if
697 PROCESS is still running when XEmacs is exited. The process will
698 be deleted silently. If REQUIRE-QUERY-P is non-`nil', then XEmacs
699 _will_ query the user (this is the default). The return value is
700 `t' if a query was formerly required, and `nil' otherwise.
702 (process-kill-without-query (get-process "shell"))
706 File: lispref.info, Node: Process Information, Next: Input to Processes, Prev: Deleting Processes, Up: Processes
711 Several functions return information about processes.
712 `list-processes' is provided for interactive use.
714 - Command: list-processes
715 This command displays a listing of all living processes. In
716 addition, it finally deletes any process whose status was `Exited'
717 or `Signaled'. It returns `nil'.
719 - Function: process-list
720 This function returns a list of all processes that have not been
724 => (#<process display-time> #<process shell>)
726 - Function: get-process name
727 This function returns the process named NAME, or `nil' if there is
728 none. An error is signaled if NAME is not a string.
730 (get-process "shell")
733 - Function: process-command process
734 This function returns the command that was executed to start
735 PROCESS. This is a list of strings, the first string being the
736 program executed and the rest of the strings being the arguments
737 that were given to the program.
739 (process-command (get-process "shell"))
742 - Function: process-id process
743 This function returns the PID of PROCESS. This is an integer that
744 distinguishes the process PROCESS from all other processes running
745 on the same computer at the current time. The PID of a process is
746 chosen by the operating system kernel when the process is started
747 and remains constant as long as the process exists.
749 - Function: process-name process
750 This function returns the name of PROCESS.
752 - Function: process-status process-name
753 This function returns the status of PROCESS-NAME as a symbol. The
754 argument PROCESS-NAME must be a process, a buffer, a process name
755 (string) or a buffer name (string).
757 The possible values for an actual subprocess are:
760 for a process that is running.
763 for a process that is stopped but continuable.
766 for a process that has exited.
769 for a process that has received a fatal signal.
772 for a network connection that is open.
775 for a network connection that is closed. Once a connection
776 is closed, you cannot reopen it, though you might be able to
777 open a new connection to the same place.
780 if PROCESS-NAME is not the name of an existing process.
782 (process-status "shell")
784 (process-status (get-buffer "*shell*"))
791 For a network connection, `process-status' returns one of the
792 symbols `open' or `closed'. The latter means that the other side
793 closed the connection, or XEmacs did `delete-process'.
795 In earlier Emacs versions (prior to version 19), the status of a
796 network connection was `run' if open, and `exit' if closed.
798 - Function: process-kill-without-query-p process
799 This function returns whether PROCESS will be killed without
800 querying the user, if it is running when XEmacs is exited. The
801 default value is `nil'.
803 - Function: process-exit-status process
804 This function returns the exit status of PROCESS or the signal
805 number that killed it. (Use the result of `process-status' to
806 determine which of those it is.) If PROCESS has not yet
807 terminated, the value is 0.
809 - Function: process-tty-name process
810 This function returns the terminal name that PROCESS is using for
811 its communication with Emacs--or `nil' if it is using pipes
812 instead of a terminal (see `process-connection-type' in *Note
813 Asynchronous Processes::).
816 File: lispref.info, Node: Input to Processes, Next: Signals to Processes, Prev: Process Information, Up: Processes
818 Sending Input to Processes
819 ==========================
821 Asynchronous subprocesses receive input when it is sent to them by
822 XEmacs, which is done with the functions in this section. You must
823 specify the process to send input to, and the input data to send. The
824 data appears on the "standard input" of the subprocess.
826 Some operating systems have limited space for buffered input in a
827 PTY. On these systems, Emacs sends an EOF periodically amidst the
828 other characters, to force them through. For most programs, these EOFs
831 - Function: process-send-string process-name string
832 This function sends PROCESS-NAME the contents of STRING as
833 standard input. The argument PROCESS-NAME must be a process or
834 the name of a process. If it is `nil', the current buffer's
837 The function returns `nil'.
839 (process-send-string "shell<1>" "ls\n")
843 ---------- Buffer: *shell* ----------
845 introduction.texi syntax-tables.texi~
846 introduction.texi~ text.texi
847 introduction.txt text.texi~
849 ---------- Buffer: *shell* ----------
851 - Command: process-send-region process-name start end
852 This function sends the text in the region defined by START and
853 END as standard input to PROCESS-NAME, which is a process or a
854 process name. (If it is `nil', the current buffer's process is
857 An error is signaled unless both START and END are integers or
858 markers that indicate positions in the current buffer. (It is
859 unimportant which number is larger.)
861 - Function: process-send-eof &optional process-name
862 This function makes PROCESS-NAME see an end-of-file in its input.
863 The EOF comes after any text already sent to it.
865 If PROCESS-NAME is not supplied, or if it is `nil', then this
866 function sends the EOF to the current buffer's process. An error
867 is signaled if the current buffer has no process.
869 The function returns PROCESS-NAME.
871 (process-send-eof "shell")
875 File: lispref.info, Node: Signals to Processes, Next: Output from Processes, Prev: Input to Processes, Up: Processes
877 Sending Signals to Processes
878 ============================
880 "Sending a signal" to a subprocess is a way of interrupting its
881 activities. There are several different signals, each with its own
882 meaning. The set of signals and their names is defined by the operating
883 system. For example, the signal `SIGINT' means that the user has typed
884 `C-c', or that some analogous thing has happened.
886 Each signal has a standard effect on the subprocess. Most signals
887 kill the subprocess, but some stop or resume execution instead. Most
888 signals can optionally be handled by programs; if the program handles
889 the signal, then we can say nothing in general about its effects.
891 The set of signals and their names is defined by the operating
892 system; XEmacs has facilities for sending only a few of the signals
893 that are defined. XEmacs can send signals only to its own subprocesses.
895 You can send signals explicitly by calling the functions in this
896 section. XEmacs also sends signals automatically at certain times:
897 killing a buffer sends a `SIGHUP' signal to all its associated
898 processes; killing XEmacs sends a `SIGHUP' signal to all remaining
899 processes. (`SIGHUP' is a signal that indicates that the connection
900 between the user and the process is broken, for example if a connection
901 via a telephone line is hung up.)
903 Each of the signal-sending functions takes two optional arguments:
904 PROCESS and CURRENT-GROUP.
906 The argument PROCESS must be either a process or a buffer, the name
907 of one, or `nil'. If it is `nil', the process defaults to the process
908 associated with the current buffer. An error is signaled if PROCESS
909 does not identify a process.
911 The argument CURRENT-GROUP is a flag that makes a difference when
912 you are running a job-control shell as an XEmacs subprocess. If it is
913 non-`nil', then the signal is sent to the current foreground process
914 group of the terminal that XEmacs uses to communicate with the
915 subprocess. If the process is a job-control shell, this means the
916 shell's current subjob. If it is `nil', the signal is sent to the
917 process group of the immediate subprocess of XEmacs. If the subprocess
918 is a job-control shell, this is the shell itself.
920 The flag CURRENT-GROUP has no effect when a pipe is used to
921 communicate with the subprocess, because the operating system does not
922 support the distinction in the case of pipes. For the same reason,
923 job-control shells won't work when a pipe is used. See
924 `process-connection-type' in *Note Asynchronous Processes::.
926 Some of the functions below take a SIGNAL argument, which identifies
927 a signal to be sent. It must be either an integer or a symbol which
928 names the signal, like `SIGSEGV'.
930 - Function: process-send-signal signal &optional process current-group
931 This function sends the signal SIGNAL to the process PROCESS. The
932 following functions can be implemented in terms of
933 `process-send-signal'.
935 - Function: interrupt-process &optional process current-group
936 This function interrupts the process PROCESS by sending the signal
937 `SIGINT'. Outside of XEmacs, typing the "interrupt character"
938 (normally `C-c') sends this signal. When the argument
939 CURRENT-GROUP is non-`nil', you can think of this function as
940 "typing `C-c'" on the terminal by which XEmacs talks to the
943 - Function: kill-process &optional process current-group
944 This function kills the process PROCESS by sending the signal
945 `SIGKILL'. This signal kills the subprocess immediately, and
946 cannot be handled by the subprocess.
948 - Function: quit-process &optional process current-group
949 This function sends the signal `SIGQUIT' to the process PROCESS.
950 This signal is the one sent by the "quit character" (usually
951 `C-\') when you are not inside XEmacs.
953 - Function: stop-process &optional process current-group
954 This function stops the process PROCESS by sending the signal
955 `SIGTSTP'. Use `continue-process' to resume its execution.
957 On systems with job control, the "stop character" (usually `C-z')
958 sends this signal (outside of XEmacs). When CURRENT-GROUP is
959 non-`nil', you can think of this function as "typing `C-z'" on the
960 terminal XEmacs uses to communicate with the subprocess.
962 - Function: continue-process &optional process current-group
963 This function resumes execution of the process PROCESS by sending
964 it the signal `SIGCONT'. This presumes that PROCESS was stopped
967 - Function: signal-process pid signal
968 This function sends a signal to the process with process id PID,
969 which need not be a child of XEmacs. The argument SIGNAL
970 specifies which signal to send.
973 File: lispref.info, Node: Output from Processes, Next: Sentinels, Prev: Signals to Processes, Up: Processes
975 Receiving Output from Processes
976 ===============================
978 There are two ways to receive the output that a subprocess writes to
979 its standard output stream. The output can be inserted in a buffer,
980 which is called the associated buffer of the process, or a function
981 called the "filter function" can be called to act on the output. If
982 the process has no buffer and no filter function, its output is
987 * Process Buffers:: If no filter, output is put in a buffer.
988 * Filter Functions:: Filter functions accept output from the process.
989 * Accepting Output:: Explicitly permitting subprocess output.
990 Waiting for subprocess output.
993 File: lispref.info, Node: Process Buffers, Next: Filter Functions, Up: Output from Processes
998 A process can (and usually does) have an "associated buffer", which
999 is an ordinary Emacs buffer that is used for two purposes: storing the
1000 output from the process, and deciding when to kill the process. You
1001 can also use the buffer to identify a process to operate on, since in
1002 normal practice only one process is associated with any given buffer.
1003 Many applications of processes also use the buffer for editing input to
1004 be sent to the process, but this is not built into XEmacs Lisp.
1006 Unless the process has a filter function (*note Filter Functions::),
1007 its output is inserted in the associated buffer. The position to insert
1008 the output is determined by the `process-mark', which is then updated
1009 to point to the end of the text just inserted. Usually, but not
1010 always, the `process-mark' is at the end of the buffer.
1012 - Function: process-buffer process
1013 This function returns the associated buffer of the process PROCESS.
1015 (process-buffer (get-process "shell"))
1016 => #<buffer *shell*>
1018 - Function: process-mark process
1019 This function returns the process marker for PROCESS, which is the
1020 marker that says where to insert output from the process.
1022 If PROCESS does not have a buffer, `process-mark' returns a marker
1023 that points nowhere.
1025 Insertion of process output in a buffer uses this marker to decide
1026 where to insert, and updates it to point after the inserted text.
1027 That is why successive batches of output are inserted
1030 Filter functions normally should use this marker in the same
1031 fashion as is done by direct insertion of output in the buffer. A
1032 good example of a filter function that uses `process-mark' is
1033 found at the end of the following section.
1035 When the user is expected to enter input in the process buffer for
1036 transmission to the process, the process marker is useful for
1037 distinguishing the new input from previous output.
1039 - Function: set-process-buffer process buffer
1040 This function sets the buffer associated with PROCESS to BUFFER.
1041 If BUFFER is `nil', the process becomes associated with no buffer.
1043 - Function: get-buffer-process buffer-or-name
1044 This function returns the process associated with BUFFER-OR-NAME.
1045 If there are several processes associated with it, then one is
1046 chosen. (Presently, the one chosen is the one most recently
1047 created.) It is usually a bad idea to have more than one process
1048 associated with the same buffer.
1050 (get-buffer-process "*shell*")
1053 Killing the process's buffer deletes the process, which kills the
1054 subprocess with a `SIGHUP' signal (*note Signals to Processes::).
1057 File: lispref.info, Node: Filter Functions, Next: Accepting Output, Prev: Process Buffers, Up: Output from Processes
1059 Process Filter Functions
1060 ------------------------
1062 A process "filter function" is a function that receives the standard
1063 output from the associated process. If a process has a filter, then
1064 _all_ output from that process is passed to the filter. The process
1065 buffer is used directly for output from the process only when there is
1068 A filter function must accept two arguments: the associated process
1069 and a string, which is the output. The function is then free to do
1070 whatever it chooses with the output.
1072 A filter function runs only while XEmacs is waiting (e.g., for
1073 terminal input, or for time to elapse, or for process output). This
1074 avoids the timing errors that could result from running filters at
1075 random places in the middle of other Lisp programs. You may explicitly
1076 cause Emacs to wait, so that filter functions will run, by calling
1077 `sit-for' or `sleep-for' (*note Waiting::), or `accept-process-output'
1078 (*note Accepting Output::). Emacs is also waiting when the command loop
1081 Quitting is normally inhibited within a filter function--otherwise,
1082 the effect of typing `C-g' at command level or to quit a user command
1083 would be unpredictable. If you want to permit quitting inside a filter
1084 function, bind `inhibit-quit' to `nil'. *Note Quitting::.
1086 If an error happens during execution of a filter function, it is
1087 caught automatically, so that it doesn't stop the execution of whatever
1088 program was running when the filter function was started. However, if
1089 `debug-on-error' is non-`nil', the error-catching is turned off. This
1090 makes it possible to use the Lisp debugger to debug the filter
1091 function. *Note Debugger::.
1093 Many filter functions sometimes or always insert the text in the
1094 process's buffer, mimicking the actions of XEmacs when there is no
1095 filter. Such filter functions need to use `set-buffer' in order to be
1096 sure to insert in that buffer. To avoid setting the current buffer
1097 semipermanently, these filter functions must use `unwind-protect' to
1098 make sure to restore the previous current buffer. They should also
1099 update the process marker, and in some cases update the value of point.
1100 Here is how to do these things:
1102 (defun ordinary-insertion-filter (proc string)
1103 (let ((old-buffer (current-buffer)))
1106 (set-buffer (process-buffer proc))
1107 (setq moving (= (point) (process-mark proc)))
1109 ;; Insert the text, moving the process-marker.
1110 (goto-char (process-mark proc))
1112 (set-marker (process-mark proc) (point)))
1113 (if moving (goto-char (process-mark proc))))
1114 (set-buffer old-buffer))))
1116 The reason to use an explicit `unwind-protect' rather than letting
1117 `save-excursion' restore the current buffer is so as to preserve the
1118 change in point made by `goto-char'.
1120 To make the filter force the process buffer to be visible whenever
1121 new text arrives, insert the following line just before the
1124 (display-buffer (process-buffer proc))
1126 To force point to move to the end of the new output no matter where
1127 it was previously, eliminate the variable `moving' and call `goto-char'
1130 In earlier Emacs versions, every filter function that did regexp
1131 searching or matching had to explicitly save and restore the match data.
1132 Now Emacs does this automatically; filter functions never need to do it
1133 explicitly. *Note Match Data::.
1135 A filter function that writes the output into the buffer of the
1136 process should check whether the buffer is still alive. If it tries to
1137 insert into a dead buffer, it will get an error. If the buffer is dead,
1138 `(buffer-name (process-buffer PROCESS))' returns `nil'.
1140 The output to the function may come in chunks of any size. A program
1141 that produces the same output twice in a row may send it as one batch
1142 of 200 characters one time, and five batches of 40 characters the next.
1144 - Function: set-process-filter process filter
1145 This function gives PROCESS the filter function FILTER. If FILTER
1146 is `nil', then the process will have no filter. If FILTER is `t',
1147 then no output from the process will be accepted until the filter
1148 is changed. (Output received during this time is not discarded,
1149 but is queued, and will be processed as soon as the filter is
1152 - Function: process-filter process
1153 This function returns the filter function of PROCESS, or `nil' if
1154 it has none. `t' means that output processing has been stopped.
1156 Here is an example of use of a filter function:
1158 (defun keep-output (process output)
1159 (setq kept (cons output kept)))
1163 (set-process-filter (get-process "shell") 'keep-output)
1165 (process-send-string "shell" "ls ~/other\n")
1168 => ("lewis@slug[8] % "
1169 "FINAL-W87-SHORT.MSS backup.otl kolstad.mss~
1170 address.txt backup.psf kolstad.psf
1171 backup.bib~ david.mss resume-Dec-86.mss~
1172 backup.err david.psf resume-Dec.psf
1173 backup.mss dland syllabus.mss
1175 "#backups.mss# backup.mss~ kolstad.mss
1179 File: lispref.info, Node: Accepting Output, Prev: Filter Functions, Up: Output from Processes
1181 Accepting Output from Processes
1182 -------------------------------
1184 Output from asynchronous subprocesses normally arrives only while
1185 XEmacs is waiting for some sort of external event, such as elapsed time
1186 or terminal input. Occasionally it is useful in a Lisp program to
1187 explicitly permit output to arrive at a specific point, or even to wait
1188 until output arrives from a process.
1190 - Function: accept-process-output &optional process seconds millisec
1191 This function allows XEmacs to read pending output from processes.
1192 The output is inserted in the associated buffers or given to
1193 their filter functions. If PROCESS is non-`nil' then this
1194 function does not return until some output has been received from
1197 The arguments SECONDS and MILLISEC let you specify timeout
1198 periods. The former specifies a period measured in seconds and the
1199 latter specifies one measured in milliseconds. The two time
1200 periods thus specified are added together, and
1201 `accept-process-output' returns after that much time whether or
1202 not there has been any subprocess output. Note that SECONDS is
1203 allowed to be a floating-point number; thus, there is no need to
1204 ever use MILLISEC. (It is retained for compatibility purposes.)
1206 The function `accept-process-output' returns non-`nil' if it did
1207 get some output, or `nil' if the timeout expired before output