Mercurial > hg > xemacs-beta
comparison lisp/process.el @ 853:2b6fa2618f76
[xemacs-hg @ 2002-05-28 08:44:22 by ben]
merge my stderr-proc ws
make-docfile.c: Fix places where we forget to check for EOF.
code-init.el: Don't use CRLF conversion by default on process output. CMD.EXE and
friends work both ways but Cygwin programs don't like the CRs.
code-process.el, multicast.el, process.el: Removed.
Improvements to call-process-internal:
-- allows a buffer to be specified for input and stderr output
-- use it on all systems
-- implement C-g as documented
-- clean up and comment
call-process-region uses new call-process facilities; no temp file.
remove duplicate funs in process.el.
comment exactly how coding systems work and fix various problems.
open-multicast-group now does similar coding-system frobbing to
open-network-stream.
dumped-lisp.el, faces.el, msw-faces.el: Fix some hidden errors due to code not being defined at the right time.
xemacs.mak: Add -DSTRICT.
================================================================
ALLOW SEPARATION OF STDOUT AND STDERR IN PROCESSES
================================================================
Standard output and standard error can be processed separately in
a process. Each can have its own buffer, its own mark in that buffer,
and its filter function. You can specify a separate buffer for stderr
in `start-process' to get things started, or use the new primitives:
set-process-stderr-buffer
process-stderr-buffer
process-stderr-mark
set-process-stderr-filter
process-stderr-filter
Also, process-send-region takes a 4th optional arg, a buffer.
Currently always uses a pipe() under Unix to read the error output.
(#### Would a PTY be better?)
sysdep.h, sysproc.h, unexfreebsd.c, unexsunos4.c, nt.c, emacs.c, callproc.c, symsinit.h, sysdep.c, Makefile.in.in, process-unix.c: Delete callproc.c. Move child_setup() to process-unix.c.
wait_for_termination() now only needed on a few really old systems.
console-msw.h, event-Xt.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.h, process-nt.c, process-unix.c, process.c, process.h, procimpl.h: Rewrite the process methods to handle a separate channel for
error input. Create Lstreams for reading in the error channel.
Many process methods need change. In general the changes are
fairly clear as they involve duplicating what's used for reading
the normal stdout and changing for stderr -- although tedious,
as such changes are required throughout the entire process code.
Rewrote the code that reads process output to do two loops, one
for stdout and one for stderr.
gpmevent.c, tooltalk.c: set_process_filter takes an argument for stderr.
================================================================
NEW ERROR-TRAPPING MECHANISM
================================================================
Totally rewrite error trapping code to be unified and support more
features. Basic function is call_trapping_problems(), which lets
you specify, by means of flags, what sorts of problems you want
trapped. these can include
-- quit
-- errors
-- throws past the function
-- creation of "display objects" (e.g. buffers)
-- deletion of already-existing "display objects" (e.g. buffers)
-- modification of already-existing buffers
-- entering the debugger
-- gc
-- errors->warnings (ala suspended errors)
etc. All other error funs rewritten in terms of this one.
Various older mechanisms removed or rewritten.
window.c, insdel.c, console.c, buffer.c, device.c, frame.c: When creating a display object, added call to
note_object_created(), for use with trapping_problems mechanism.
When deleting, call check_allowed_operation() and note_object
deleted().
The trapping-problems code records the objects created since the
call-trapping-problems began. Those objects can be deleted, but
none others (i.e. previously existing ones).
bytecode.c, cmdloop.c: internal_catch takes another arg.
eval.c: Add long comments describing the "five lists" used to maintain
state (backtrace, gcpro, specbind, etc.) in the Lisp engine.
backtrace.h, eval.c: Implement trapping-problems mechanism, eliminate old mechanisms or
redo in terms of new one.
frame.c, gutter.c: Flush out the concept of "critical display section", defined by
the in_display() var. Use an internal_bind() to get it reset,
rather than just doing it at end, because there may be a non-local
exit.
event-msw.c, event-stream.c, console-msw.h, device.c, dialog-msw.c, frame.c, frame.h, intl.c, toolbar.c, menubar-msw.c, redisplay.c, alloc.c, menubar-x.c: Make use of new trapping-errors stuff and rewrite code based on
old mechanisms.
glyphs-widget.c, redisplay.h: Protect calling Lisp in redisplay.
insdel.c: Protect hooks against deleting existing buffers.
frame-msw.c: Use EQ, not EQUAL in hash tables whose keys are just numbers.
Otherwise we run into stickiness in redisplay because
internal_equal() can QUIT.
================================================================
SIGNAL, C-G CHANGES
================================================================
Here we change the way that C-g interacts with event reading. The
idea is that a C-g occurring while we're reading a user event
should be read as C-g, but elsewhere should be a QUIT. The former
code did all sorts of bizarreness -- requiring that no QUIT occurs
anywhere in event-reading code (impossible to enforce given the
stuff called or Lisp code invoked), and having some weird system
involving enqueue/dequeue of a C-g and interaction with Vquit_flag
-- and it didn't work.
Now, we simply enclose all code where we want C-g read as an event
with {begin/end}_dont_check_for_quit(). This completely turns off
the mechanism that checks (and may remove or alter) C-g in the
read-ahead queues, so we just get the C-g normal.
Signal.c documents this very carefully.
cmdloop.c: Correct use of dont_check_for_quit to new scheme, remove old
out-of-date comments.
event-stream.c: Fix C-g handling to actually work.
device-x.c: Disable quit checking when err out.
signal.c: Cleanup. Add large descriptive comment.
process-unix.c, process-nt.c, sysdep.c: Use QUIT instead of REALLY_QUIT.
It's not necessary to use REALLY_QUIT and just confuses the issue.
lisp.h: Comment quit handlers.
================================================================
CONS CHANGES
================================================================
free_cons() now takes a Lisp_Object not the result of XCONS().
car and cdr have been renamed so that they don't get used directly;
go through XCAR(), XCDR() instead.
alloc.c, dired.c, editfns.c, emodules.c, fns.c, glyphs-msw.c, glyphs-x.c, glyphs.c, keymap.c, minibuf.c, search.c, eval.c, lread.c, lisp.h: Correct free_cons calling convention: now takes Lisp_Object,
not Lisp_Cons
chartab.c: Eliminate direct use of ->car, ->cdr, should be black box.
callint.c: Rewrote using EXTERNAL_LIST_LOOP to avoid use of Lisp_Cons.
================================================================
USE INTERNAL-BIND-*
================================================================
eval.c: Cleanups of these funs.
alloc.c, fileio.c, undo.c, specifier.c, text.c, profile.c, lread.c, redisplay.c, menubar-x.c, macros.c: Rewrote to use internal_bind_int() and internal_bind_lisp_object()
in place of whatever varied and cumbersome mechanisms were
formerly there.
================================================================
SPECBIND SANITY
================================================================
backtrace.h: - Improved comments
backtrace.h, bytecode.c, eval.c: Add new mechanism check_specbind_stack_sanity() for sanity
checking code each time the catchlist or specbind stack change.
Removed older prototype of same mechanism.
================================================================
MISC
================================================================
lisp.h, insdel.c, window.c, device.c, console.c, buffer.c: Fleshed out authorship.
device-msw.c: Correct bad Unicode-ization.
print.c: Be more careful when not initialized or in fatal error handling.
search.c: Eliminate running_asynch_code, an FSF holdover.
alloc.c: Added comments about gc-cons-threshold.
dialog-x.c: Use begin_gc_forbidden() around code to build up a widget value
tree, like in menubar-x.c.
gui.c: Use Qunbound not Qnil as the default for
gethash.
lisp-disunion.h, lisp-union.h: Added warnings on use of VOID_TO_LISP().
lisp.h: Use ERROR_CHECK_STRUCTURES to turn on
ERROR_CHECK_TRAPPING_PROBLEMS and ERROR_CHECK_TYPECHECK
lisp.h: Add assert_with_message.
lisp.h: Add macros for gcproing entire arrays. (You could do this before
but it required manual twiddling the gcpro structure.)
lisp.h: Add prototypes for new functions defined elsewhere.
author | ben |
---|---|
date | Tue, 28 May 2002 08:45:36 +0000 |
parents | a634e3b7acc8 |
children | 84762348c6f9 |
comparison
equal
deleted
inserted
replaced
852:d83885ef293b | 853:2b6fa2618f76 |
---|---|
1 ;;; process.el --- commands for subprocesses; split out of simple.el | 1 ;;; process.el --- commands for subprocesses; split out of simple.el |
2 | 2 |
3 ;; Copyright (C) 1985-7, 1993,4, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985-7, 1993,4, 1997 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995, 2000, 2001 Ben Wing. | 4 ;; Copyright (C) 1995, 2000, 2001, 2002 Ben Wing. |
5 | 5 |
6 ;; Author: Ben Wing | 6 ;; Author: Ben Wing |
7 ;; Maintainer: XEmacs Development Team | 7 ;; Maintainer: XEmacs Development Team |
8 ;; Keywords: internal, processes, dumped | 8 ;; Keywords: internal, processes, dumped |
9 | 9 |
59 (defvar shell-command-switch "-c" | 59 (defvar shell-command-switch "-c" |
60 "Switch used to have the shell execute its command line argument.") | 60 "Switch used to have the shell execute its command line argument.") |
61 | 61 |
62 (defun start-process-shell-command (name buffer &rest args) | 62 (defun start-process-shell-command (name buffer &rest args) |
63 "Start a program in a subprocess. Return the process object for it. | 63 "Start a program in a subprocess. Return the process object for it. |
64 Args are NAME BUFFER COMMAND &rest COMMAND-ARGS. | |
65 NAME is name for process. It is modified if necessary to make it unique. | 64 NAME is name for process. It is modified if necessary to make it unique. |
66 BUFFER is the buffer or (buffer-name) to associate with the process. | 65 BUFFER is the buffer or (buffer-name) to associate with the process. |
67 Process output goes at end of that buffer, unless you specify | 66 Process output goes at end of that buffer, unless you specify |
68 an output stream or filter function to handle the output. | 67 an output stream or filter function to handle the output. |
69 BUFFER may be also nil, meaning that this process is not associated | 68 BUFFER may be also nil, meaning that this process is not associated |
74 ;; We used to use `exec' to replace the shell with the command, | 73 ;; We used to use `exec' to replace the shell with the command, |
75 ;; but that failed to handle (...) and semicolon, etc. | 74 ;; but that failed to handle (...) and semicolon, etc. |
76 (start-process name buffer shell-file-name shell-command-switch | 75 (start-process name buffer shell-file-name shell-command-switch |
77 (mapconcat #'identity args " "))) | 76 (mapconcat #'identity args " "))) |
78 | 77 |
79 (defun call-process-internal (program &optional infile buffer display &rest args) | 78 (defun call-process-internal (program &optional infile buffer display |
80 "Call PROGRAM synchronously in separate process, with coding-system specified. | 79 &rest args) |
81 Arguments are | 80 "Internal function to call PROGRAM synchronously in separate process. |
82 (PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS). | 81 Lisp callers should use `call-process' or `call-process-region'. |
82 | |
83 The program's input comes from file INFILE (nil means `/dev/null'). | 83 The program's input comes from file INFILE (nil means `/dev/null'). |
84 XEmacs feature: INFILE can also be a list of (BUFFER [START [END]]), i.e. | |
85 a list of one to three elements, consisting of a buffer and optionally | |
86 a start position or start and end position. In this case, input comes | |
87 from the buffer, starting from START (defaults to the beginning of the | |
88 buffer) and ending at END (defaults to the end of the buffer). | |
89 | |
84 Insert output in BUFFER before point; t means current buffer; | 90 Insert output in BUFFER before point; t means current buffer; |
85 nil for BUFFER means discard it; 0 means discard and don't wait. | 91 nil for BUFFER means discard it; 0 means discard and don't wait. |
92 If BUFFER is a string, then find or create a buffer with that name, | |
93 then insert the output in that buffer, before point. | |
86 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, | 94 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, |
87 REAL-BUFFER says what to do with standard output, as above, | 95 REAL-BUFFER says what to do with standard output, as above, |
88 while STDERR-FILE says what to do with standard error in the child. | 96 while STDERR-FILE says what to do with standard error in the child. |
89 STDERR-FILE may be nil (discard standard error output), | 97 STDERR-FILE may be nil (discard standard error output), |
90 t (mix it with ordinary output), or a file name string. | 98 t (mix it with ordinary output), a file name string, or (XEmacs feature) |
99 a buffer object. If STDERR-FILE is a buffer object (but not the name of | |
100 a buffer, since that would be interpreted as a file), the standard error | |
101 output will be inserted into the buffer before point. | |
91 | 102 |
92 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted. | 103 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted. |
93 Remaining arguments are strings passed as command arguments to PROGRAM. | 104 Remaining arguments are strings passed as command arguments to PROGRAM. |
94 | 105 |
95 If BUFFER is 0, `call-process' returns immediately with value nil. | 106 If BUFFER is 0, returns immediately with value nil. |
96 Otherwise it waits for PROGRAM to terminate and returns a numeric exit status | 107 Otherwise waits for PROGRAM to terminate and returns a numeric exit status |
97 or a signal description string. | 108 or a signal description string. If you quit, the process is first killed |
98 If you quit, the process is killed with SIGINT, or SIGKILL if you | 109 with SIGINT, then with SIGKILL if you quit again before the process exits. |
99 quit again." | 110 |
100 ;; #### remove windows-nt check when this is ready for prime time. | 111 Coding systems for the process are the same as for `start-process-internal'." |
101 (if (not (eq 'windows-nt system-type)) | 112 (let (proc inbuf errbuf kill-inbuf kill-errbuf no-wait start end) |
102 (apply 'old-call-process-internal program infile buffer display args) | 113 ;; first set up an unwind-protect to clean everything up. this will: |
103 (let (proc inbuf errbuf discard) | 114 ;; |
104 (unwind-protect | 115 ;; -- kill the process. (when we're not waiting for it to finish, we |
105 (progn | 116 ;; set PROC to nil when we're ready to exit so this doesn't happen -- |
106 (when infile | 117 ;; if we're interrupted before we're ready to exit, we should still |
107 (setq infile (expand-file-name infile)) | 118 ;; kill the process) |
108 (setq inbuf (generate-new-buffer "*call-process*")) | 119 ;; -- kill temporary buffers created to handle I/O to or from a file. |
109 (with-current-buffer inbuf | 120 ;; KILL-INBUF/KILL-ERRBUF tell us if we should do so. |
110 ;; Make sure this works with jka-compr | 121 ;; |
111 (let ((file-name-handler-alist nil)) | 122 ;; note that we need to be *very* careful in this code to handle C-g |
112 (insert-file-contents-internal infile nil nil nil nil | 123 ;; at any point. |
113 'binary)))) | 124 (unwind-protect |
114 (let ((stderr (if (consp buffer) (second buffer) t))) | 125 (progn |
115 (if (consp buffer) (setq buffer (car buffer))) | 126 ;; first handle INFILE. |
116 (setq buffer | 127 (cond ((stringp infile) |
117 (cond ((null buffer) nil) | 128 (setq infile (expand-file-name infile)) |
118 ((eq buffer t) (current-buffer)) | 129 (setq kill-inbuf t) |
119 ;; use integerp for compatibility with existing | 130 (setq inbuf (generate-new-buffer "*call-process*")) |
120 ;; call-process rmsism. | 131 ;; transfer the exact contents of the file to the process. |
121 ((integerp buffer) (setq discard t) nil) | 132 ;; we do that by reading in and writing out in |
122 (t (get-buffer-create buffer)))) | 133 ;; binary. #### is this even correct? should we be doing |
123 (when (and stderr (not (eq t stderr))) | 134 ;; the same thing with stderr? if so we'd need a way of |
135 ;; controlling the stderr coding system separate from | |
136 ;; everything else. | |
137 (with-current-buffer inbuf | |
138 ;; Make sure this works with jka-compr | |
139 (let ((file-name-handler-alist nil)) | |
140 (insert-file-contents-internal infile nil nil nil nil | |
141 'binary)) | |
142 (setq start (point-min) end (point-max)))) | |
143 ((consp infile) | |
144 (setq inbuf (get-buffer (car infile))) | |
145 (setq start (or (nth 1 infile) (point-min inbuf))) | |
146 (setq end (or (nth 2 infile) (point-max inbuf)))) | |
147 ((null infile) nil) | |
148 (t | |
149 (error 'wrong-type-argument | |
150 "Must be filename or (BUFFER [START [END]])" | |
151 infile))) | |
152 ;; now handle BUFFER | |
153 (let ((stderr (if (consp buffer) (second buffer) t))) | |
154 (if (consp buffer) (setq buffer (car buffer))) | |
155 (setq buffer | |
156 (cond ((null buffer) nil) | |
157 ((eq buffer t) (current-buffer)) | |
158 ;; use integerp for compatibility with existing | |
159 ;; call-process rmsism. | |
160 ((integerp buffer) (setq no-wait t) nil) | |
161 (t (get-buffer-create buffer)))) | |
162 (when (and stderr (not (eq t stderr))) | |
163 ;; both ERRBUF and STDERR being non-nil indicates to the | |
164 ;; code below that STDERR is a file and we should write | |
165 ;; ERRBUF to it; so clear out STDERR if we don't want this. | |
166 (if (bufferp stderr) (setq errbuf stderr stderr nil) | |
124 (setq stderr (expand-file-name stderr)) | 167 (setq stderr (expand-file-name stderr)) |
125 (setq errbuf (generate-new-buffer "*call-process*"))) | 168 (setq kill-errbuf t) |
169 (setq errbuf (generate-new-buffer "*call-process*")))) | |
170 ;; now start process. using a pty causes all sorts of | |
171 ;; weirdness, at least under cygwin, when there's input. #### i | |
172 ;; don't know what's going wrong and whether it's a cygwin-only | |
173 ;; problem. suffice to say that there were NO pty connections | |
174 ;; in the old version. | |
175 (let ((process-connection-type nil)) | |
126 (setq proc | 176 (setq proc |
127 (apply 'start-process-internal "*call-process*" | 177 (apply 'start-process-internal "*call-process*" |
128 buffer | 178 (if (eq t stderr) buffer (list buffer errbuf)) |
129 ;#### not implemented until my new process | 179 program args))) |
130 ;changes go in. | 180 ;; see comment above where the data was read from the file. |
131 ;(if (eq t stderr) buffer (list buffer errbuf)) | 181 (if kill-inbuf |
132 program args)) | 182 (set-process-output-coding-system proc 'binary)) |
133 (if buffer | 183 ;; point mark/stderr-mark at the right place (by default it's |
134 (set-marker (process-mark proc) (point buffer) buffer)) | 184 ;; end of buffer). |
135 (unwind-protect | 185 (if buffer |
136 (prog1 | 186 (set-marker (process-mark proc) (point buffer) buffer)) |
137 (catch 'call-process-done | 187 (if errbuf |
138 (when (not discard) | 188 (set-marker (process-stderr-mark proc) (point errbuf) errbuf)) |
139 (set-process-sentinel | 189 ;; now do I/O, very carefully! the unwind-protect makes sure |
140 proc | 190 ;; to clear out the sentinel, since it does a `throw', which would |
141 #'(lambda (proc status) | 191 ;; have no catch (or writes to a file -- we only want this on |
142 (cond ((eq 'exit (process-status proc)) | 192 ;; normal exit) |
143 (set-process-sentinel proc nil) | 193 (unwind-protect |
144 (throw 'call-process-done | 194 ;; if not NO-WAIT, set a sentinel to return the exit |
145 (process-exit-status proc))) | 195 ;; status. it will throw to this catch so we can exit |
146 ((eq 'signal (process-status proc)) | 196 ;; properly. |
147 (set-process-sentinel proc nil) | 197 (catch 'call-process-done |
148 (throw 'call-process-done status)))))) | 198 (set-process-sentinel |
149 (when inbuf | 199 proc |
150 (process-send-region proc 1 | 200 (if no-wait |
151 (1+ (buffer-size inbuf)) inbuf)) | 201 ;; we're trying really really hard to emulate |
152 (process-send-eof proc) | 202 ;; the old call-process, which would save the |
153 (when discard | 203 ;; stderr to a file even if discarding output. so |
154 ;; we're trying really really hard to emulate | 204 ;; we set a sentinel to save the output when |
155 ;; the old call-process. | 205 ;; we finish. |
156 (if errbuf | 206 ;; |
157 (set-process-sentinel | 207 ;; #### not clear if we should be doing this. |
158 proc | 208 ;; |
159 `(lambda (proc status) | 209 ;; NOTE NOTE NOTE: Due to the total bogosity of |
160 (write-region-internal | 210 ;; dynamic scoping, and the lack of closures, we |
161 1 (1+ (buffer-size)) | 211 ;; have to be careful how we write the first |
162 ,stderr | 212 ;; sentinel below since it may be executed after |
163 nil 'major-rms-kludge-city nil | 213 ;; this function has returned -- thus we fake a |
164 coding-system-for-write)))) | 214 ;; closure. (This doesn't apply to the second one, |
165 (setq errbuf nil) | 215 ;; which only gets executed within the |
166 (setq proc nil) | 216 ;; unwind-protect.) |
167 (throw 'call-process-done nil)) | 217 (if (and errbuf stderr) |
168 (while t | 218 (set-process-sentinel |
169 (accept-process-output proc) | 219 proc |
170 (if display (sit-for 0)))) | 220 `(lambda (proc status) |
171 (when errbuf | 221 (set-process-sentinel proc nil) |
172 (with-current-buffer errbuf | 222 (with-current-buffer ,errbuf |
173 (write-region-internal 1 (1+ (buffer-size)) stderr | 223 (write-region-internal |
174 nil 'major-rms-kludge-city nil | 224 1 (1+ (buffer-size)) |
175 coding-system-for-write)))) | 225 ,stderr |
176 (if proc (set-process-sentinel proc nil))))) | 226 nil 'major-rms-kludge-city nil |
177 (if inbuf (kill-buffer inbuf)) | 227 coding-system-for-write)) |
178 (if errbuf (kill-buffer errbuf)) | 228 (kill-buffer ,errbuf)))) |
179 (condition-case nil | 229 ;; normal sentinel: maybe write out stderr and return |
180 (if (and proc (process-live-p proc)) (kill-process proc)) | 230 ;; status. |
181 (error nil)))))) | 231 #'(lambda (proc status) |
182 | 232 (when (and errbuf stderr) |
183 (defun call-process (program &optional infile buffer displayp &rest args) | 233 (with-current-buffer errbuf |
184 "Call PROGRAM synchronously in separate process. | 234 (write-region-internal |
185 The program's input comes from file INFILE (nil means `/dev/null'). | 235 1 (1+ (buffer-size)) stderr |
186 Insert output in BUFFER before point; t means current buffer; | 236 nil 'major-rms-kludge-city nil |
187 nil for BUFFER means discard it; 0 means discard and don't wait. | 237 coding-system-for-write))) |
188 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, | 238 (cond ((eq 'exit (process-status proc)) |
189 REAL-BUFFER says what to do with standard output, as above, | 239 (set-process-sentinel proc nil) |
190 while STDERR-FILE says what to do with standard error in the child. | 240 (throw 'call-process-done |
191 STDERR-FILE may be nil (discard standard error output), | 241 (process-exit-status proc))) |
192 t (mix it with ordinary output), or a file name string. | 242 ((eq 'signal (process-status proc)) |
193 | 243 (set-process-sentinel proc nil) |
194 Fourth arg DISPLAYP non-nil means redisplay buffer as output is inserted. | 244 (throw 'call-process-done status)))))) |
195 Remaining arguments are strings passed as command arguments to PROGRAM. | 245 (if (not no-wait) |
196 | 246 ;; we're waiting. send the input and loop forever, |
197 If BUFFER is 0, `call-process' returns immediately with value nil. | 247 ;; handling process output and maybe redisplaying. |
198 Otherwise it waits for PROGRAM to terminate and returns a numeric exit status | 248 ;; exit happens through the sentinel or C-g. if |
199 or a signal description string. | 249 ;; C-g, send SIGINT the first time, EOF if not |
200 If you quit, the process is killed with SIGINT, or SIGKILL if you | 250 ;; already done so (might make the process exit), |
201 quit again." | 251 ;; and keep waiting. Another C-g will exit the |
202 (apply 'call-process-internal program infile buffer displayp args)) | 252 ;; whole function, and the unwind-protect will |
203 | 253 ;; kill the process. (Hence the documented semantics |
204 (defun call-process-region (start end program | 254 ;; of SIGINT/SIGKILL.) |
205 &optional deletep buffer displayp | 255 (let (eof-sent) |
206 &rest args) | 256 (condition-case nil |
207 "Send text from START to END to a synchronous process running PROGRAM. | 257 (progn |
208 Delete the text if fourth arg DELETEP is non-nil. | 258 (when inbuf |
209 | 259 (process-send-region proc start end inbuf)) |
210 Insert output in BUFFER before point; t means current buffer; | 260 (process-send-eof proc) |
211 nil for BUFFER means discard it; 0 means discard and don't wait. | 261 (setq eof-sent t) |
212 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, | 262 (while t |
213 REAL-BUFFER says what to do with standard output, as above, | 263 (accept-process-output proc) |
214 while STDERR-FILE says what to do with standard error in the child. | 264 (if display (sit-for 0)))) |
215 STDERR-FILE may be nil (discard standard error output), | 265 (quit |
216 t (mix it with ordinary output), or a file name string. | 266 (process-send-signal 'SIGINT proc) |
217 | 267 (unless eof-sent |
218 Sixth arg DISPLAYP non-nil means redisplay buffer as output is inserted. | 268 (process-send-eof proc)) |
219 Remaining args are passed to PROGRAM at startup as command args. | 269 (while t |
220 | 270 (accept-process-output proc) |
221 If BUFFER is 0, returns immediately with value nil. | 271 (if display (sit-for 0)))))) |
222 Otherwise waits for PROGRAM to terminate | 272 ;; discard and no wait: send the input, set PROC |
223 and returns a numeric exit status or a signal description string. | 273 ;; and ERRBUF to nil so that the unwind-protect |
224 If you quit, the process is first killed with SIGINT, then with SIGKILL if | 274 ;; forms don't erase the sentinel, kill the process, |
225 you quit again before the process exits." | 275 ;; or kill ERRBUF (the sentinel does that), and exit. |
226 (let ((temp | 276 (when inbuf |
227 (make-temp-name | 277 (process-send-region proc start end inbuf)) |
228 (concat (file-name-as-directory (temp-directory)) "emacs")))) | 278 (process-send-eof proc) |
229 (unwind-protect | 279 (setq errbuf nil) |
230 (progn | 280 (setq proc nil))) |
231 (write-region start end temp nil 'silent) | 281 (if proc (set-process-sentinel proc nil))))) |
232 (if deletep (delete-region start end)) | 282 ;; unwind-protect forms. |
233 (apply #'call-process program temp buffer displayp args)) | 283 (if (and inbuf kill-inbuf) (kill-buffer inbuf)) |
234 (ignore-file-errors (delete-file temp))))) | 284 (if (and errbuf kill-errbuf) (kill-buffer errbuf)) |
285 (condition-case nil | |
286 (if (and proc (process-live-p proc)) (kill-process proc)) | |
287 (error nil))))) | |
235 | 288 |
236 | 289 |
237 (defun shell-command (command &optional output-buffer) | 290 (defun shell-command (command &optional output-buffer) |
238 "Execute string COMMAND in inferior shell; display output, if any. | 291 "Execute string COMMAND in inferior shell; display output, if any. |
239 | 292 |
395 (progn (end-of-line) | 448 (progn (end-of-line) |
396 (point)))))) | 449 (point)))))) |
397 (t | 450 (t |
398 (set-window-start (display-buffer buffer) 1)))))))) | 451 (set-window-start (display-buffer buffer) 1)))))))) |
399 | 452 |
400 | |
401 (defun start-process (name buffer program &rest program-args) | |
402 "Start a program in a subprocess. Return the process object for it. | |
403 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS | |
404 NAME is name for process. It is modified if necessary to make it unique. | |
405 BUFFER is the buffer or (buffer-name) to associate with the process. | |
406 Process output goes at end of that buffer, unless you specify | |
407 an output stream or filter function to handle the output. | |
408 BUFFER may be also nil, meaning that this process is not associated | |
409 with any buffer | |
410 Third arg is program file name. It is searched for as in the shell. | |
411 Remaining arguments are strings to give program as arguments." | |
412 (apply 'start-process-internal name buffer program program-args)) | |
413 | |
414 (defun open-network-stream (name buffer host service &optional protocol) | |
415 "Open a TCP connection for a service to a host. | |
416 Returns a process object to represent the connection. | |
417 Input and output work as for subprocesses; `delete-process' closes it. | |
418 Args are NAME BUFFER HOST SERVICE. | |
419 NAME is name for process. It is modified if necessary to make it unique. | |
420 BUFFER is the buffer (or buffer-name) to associate with the process. | |
421 Process output goes at end of that buffer, unless you specify | |
422 an output stream or filter function to handle the output. | |
423 BUFFER may be also nil, meaning that this process is not associated | |
424 with any buffer | |
425 Third arg is name of the host to connect to, or its IP address. | |
426 Fourth arg SERVICE is name of the service desired, or an integer | |
427 specifying a port number to connect to. | |
428 Fifth argument PROTOCOL is a network protocol. Currently 'tcp | |
429 (Transmission Control Protocol) and 'udp (User Datagram Protocol) are | |
430 supported. When omitted, 'tcp is assumed. | |
431 | |
432 Output via `process-send-string' and input via buffer or filter (see | |
433 `set-process-filter') are stream-oriented. That means UDP datagrams are | |
434 not guaranteed to be sent and received in discrete packets. (But small | |
435 datagrams around 500 bytes that are not truncated by `process-send-string' | |
436 are usually fine.) Note further that UDP protocol does not guard against | |
437 lost packets." | |
438 (open-network-stream-internal name buffer host service protocol)) | |
439 | |
440 (defun shell-quote-argument (argument) | 453 (defun shell-quote-argument (argument) |
441 "Quote an argument for passing as argument to an inferior shell." | 454 "Quote an argument for passing as argument to an inferior shell." |
442 (if (and (eq system-type 'windows-nt) | 455 (if (and (eq system-type 'windows-nt) |
443 (let ((progname (downcase (file-name-nondirectory | 456 (let ((progname (downcase (file-name-nondirectory |
444 shell-file-name)))) | 457 shell-file-name)))) |