Mercurial > hg > xemacs-beta
comparison lisp/code-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 | 0490271de7d8 |
children | b5278486690c |
comparison
equal
deleted
inserted
replaced
852:d83885ef293b | 853:2b6fa2618f76 |
---|---|
1 ;;; code-process.el --- Process coding functions for XEmacs. | 1 ;;; code-process.el --- Process coding functions for XEmacs. |
2 | 2 |
3 ;; Copyright (C) 1985-1987, 1993, 1994, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985-1987, 1993, 1994, 1997 Free Software Foundation, Inc. |
4 ;; Copyright (C) 1995, 2000 Ben Wing | 4 ;; Copyright (C) 1995, 2000, 2002 Ben Wing |
5 ;; Copyright (C) 1997 MORIOKA Tomohiko | 5 ;; Copyright (C) 1997 MORIOKA Tomohiko |
6 | 6 |
7 ;; Author: Ben Wing | 7 ;; Author: Ben Wing |
8 ;; MORIOKA Tomohiko | 8 ;; MORIOKA Tomohiko |
9 ;; Maintainer: XEmacs Development Team | 9 ;; Maintainer: XEmacs Development Team |
37 VAL is a coding system, a cons of coding systems, or a function symbol. | 37 VAL is a coding system, a cons of coding systems, or a function symbol. |
38 If VAL is a coding system, it is used for both decoding what received | 38 If VAL is a coding system, it is used for both decoding what received |
39 from the program and encoding what sent to the program. | 39 from the program and encoding what sent to the program. |
40 If VAL is a cons of coding systems, the car part is used for decoding, | 40 If VAL is a cons of coding systems, the car part is used for decoding, |
41 and the cdr part is used for encoding. | 41 and the cdr part is used for encoding. |
42 If VAL is a function symbol, the function must return a coding system | 42 If VAL is a function symbol, it is called with two arguments, a symbol |
43 or a cons of coding systems which are used as above.") | 43 indicating the operation being performed (one of `start-process', |
44 `call-process', `open-network-stream', or `open-multicast-group') and the | |
45 program name. The function must return a coding system or a cons of | |
46 coding systems which are used as above.") | |
44 | 47 |
45 (defun call-process (program &optional infile buffer displayp &rest args) | 48 (defun call-process (program &optional infile buffer displayp &rest args) |
46 "Call PROGRAM synchronously in separate process. | 49 "Call PROGRAM synchronously in separate process. |
50 | |
47 The program's input comes from file INFILE (nil means `/dev/null'). | 51 The program's input comes from file INFILE (nil means `/dev/null'). |
52 XEmacs feature: INFILE can also be a list of (BUFFER [START [END]]), i.e. | |
53 a list of one to three elements, consisting of a buffer and optionally | |
54 a start position or start and end position. In this case, input comes | |
55 from the buffer, starting from START (defaults to the beginning of the | |
56 buffer) and ending at END (defaults to the end of the buffer). | |
57 | |
48 Insert output in BUFFER before point; t means current buffer; | 58 Insert output in BUFFER before point; t means current buffer; |
49 nil for BUFFER means discard it; 0 means discard and don't wait. | 59 nil for BUFFER means discard it; 0 means discard and don't wait. |
50 If BUFFER is a string, then find or create a buffer with that name, | 60 If BUFFER is a string, then find or create a buffer with that name, |
51 then insert the output in that buffer, before point. | 61 then insert the output in that buffer, before point. |
52 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, | 62 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, |
53 REAL-BUFFER says what to do with standard output, as above, | 63 REAL-BUFFER says what to do with standard output, as above, |
54 while STDERR-FILE says what to do with standard error in the child. | 64 while STDERR-FILE says what to do with standard error in the child. |
55 STDERR-FILE may be nil (discard standard error output), | 65 STDERR-FILE may be nil (discard standard error output), |
56 t (mix it with ordinary output), or a file name string. | 66 t (mix it with ordinary output), a file name string, or (XEmacs feature) |
57 | 67 a buffer object. If STDERR-FILE is a buffer object (but not the name of |
58 Fourth arg DISPLAYP non-nil means redisplay buffer as output is inserted. | 68 a buffer, since that would be interpreted as a file), the standard error |
69 output will be inserted into the buffer before point. | |
70 | |
71 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted. | |
59 Remaining arguments are strings passed as command arguments to PROGRAM. | 72 Remaining arguments are strings passed as command arguments to PROGRAM. |
60 | 73 |
61 If BUFFER is 0, `call-process' returns immediately with value nil. | 74 If BUFFER is 0, returns immediately with value nil. |
62 Otherwise it waits for PROGRAM to terminate and returns a numeric exit status | 75 Otherwise waits for PROGRAM to terminate and returns a numeric exit status |
63 or a signal description string. | 76 or a signal description string. If you quit, the process is first killed |
64 If you quit, the process is killed with SIGINT, or SIGKILL if you | 77 with SIGINT, then with SIGKILL if you quit again before the process exits. |
65 quit again." | 78 |
66 (let* ((coding-system-for-read | 79 If INFILE is a file, we transfer its exact contents to the process without |
67 (or coding-system-for-read | 80 any encoding/decoding. (#### This policy might change.) |
68 (let (ret) | 81 |
69 (catch 'found | 82 Otherwise, the read/write coding systems used for process I/O on the |
70 (let ((alist process-coding-system-alist) | 83 process are determined as follows: |
71 (case-fold-search nil)) | 84 |
72 (while alist | 85 1. `coding-system-for-read', `coding-system-for-write', if non-nil. |
73 (if (string-match (car (car alist)) program) | 86 (Intended as a temporary overriding mechanism for use by Lisp |
74 (throw 'found (setq ret (cdr (car alist)))) | 87 code.) |
75 ) | 88 2. The matching value for the process name from `process-coding-system-alist', |
76 (setq alist (cdr alist)) | 89 if any, and if non-nil. The value may be either a single coding |
77 ))) | 90 system, used for both read and write; or a cons of read/write; or a |
78 (if (functionp ret) | 91 function, called to get one of the other two values. |
79 (setq ret (funcall ret 'call-process program)) | 92 3. For writing: If a buffer was given in INFILE, the value of |
80 ) | 93 `buffer-file-coding-system' in that buffer. |
81 (cond ((consp ret) (car ret)) | 94 For reading: if a buffer was given in BUFFER, the value of |
82 ((not ret) 'undecided) | 95 `buffer-file-coding-system-for-read' in that buffer. |
83 ((find-coding-system ret) ret) | 96 4. The value of `default-process-coding-system', which should be a cons |
84 ) | 97 of read/write coding systems, if the values are non-nil. |
85 )))) | 98 5. The coding system `undecided' for read, and `raw-text' for write. |
86 (apply 'call-process-internal program infile buffer displayp args) | 99 |
87 )) | 100 Note that the processes of determining the read and write coding systems |
101 proceed essentially independently one from the other, as in `start-process'." | |
102 (let (cs-r cs-w) | |
103 (let (ret) | |
104 (catch 'found | |
105 (let ((alist process-coding-system-alist) | |
106 (case-fold-search nil)) | |
107 (while alist | |
108 (if (string-match (car (car alist)) program) | |
109 (throw 'found (setq ret (cdr (car alist))))) | |
110 (setq alist (cdr alist)) | |
111 ))) | |
112 (if (functionp ret) | |
113 (setq ret (funcall ret 'call-process program))) | |
114 (cond ((consp ret) | |
115 (setq cs-r (car ret) | |
116 cs-w (cdr ret))) | |
117 ((and ret (find-coding-system ret)) | |
118 (setq cs-r ret | |
119 cs-w ret)))) | |
120 (let ((coding-system-for-read | |
121 (or coding-system-for-read cs-r | |
122 (let ((thebuf (if (consp buffer) (car buffer) buffer))) | |
123 (and (or (bufferp thebuf) (stringp thebuf)) | |
124 (get-buffer thebuf) | |
125 (symbol-value-in-buffer | |
126 'buffer-file-coding-system-for-read thebuf))) | |
127 (car default-process-coding-system) | |
128 'undecided)) | |
129 (coding-system-for-write | |
130 (or coding-system-for-write cs-w | |
131 (and (consp infile) | |
132 (symbol-value-in-buffer | |
133 'buffer-file-coding-system | |
134 (get-buffer (car infile)))) | |
135 (cdr default-process-coding-system) | |
136 'raw-text))) | |
137 (apply 'call-process-internal program infile buffer displayp args)))) | |
88 | 138 |
89 (defun call-process-region (start end program | 139 (defun call-process-region (start end program |
90 &optional deletep buffer displayp | 140 &optional deletep buffer displayp |
91 &rest args) | 141 &rest args) |
92 "Send text from START to END to a synchronous process running PROGRAM. | 142 "Send text from START to END to a synchronous process running PROGRAM. |
98 then insert the output in that buffer, before point. | 148 then insert the output in that buffer, before point. |
99 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, | 149 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, |
100 REAL-BUFFER says what to do with standard output, as above, | 150 REAL-BUFFER says what to do with standard output, as above, |
101 while STDERR-FILE says what to do with standard error in the child. | 151 while STDERR-FILE says what to do with standard error in the child. |
102 STDERR-FILE may be nil (discard standard error output), | 152 STDERR-FILE may be nil (discard standard error output), |
103 t (mix it with ordinary output), or a file name string. | 153 t (mix it with ordinary output), a file name string, or (XEmacs feature) |
154 a buffer object. If STDERR-FILE is a buffer object (but not the name of | |
155 a buffer, since that would be interpreted as a file), the standard error | |
156 output will be inserted into the buffer before point. | |
104 | 157 |
105 Sixth arg DISPLAYP non-nil means redisplay buffer as output is inserted. | 158 Sixth arg DISPLAYP non-nil means redisplay buffer as output is inserted. |
106 Remaining args are passed to PROGRAM at startup as command args. | 159 Remaining args are passed to PROGRAM at startup as command args. |
107 | 160 |
108 If BUFFER is 0, returns immediately with value nil. | 161 If BUFFER is 0, returns immediately with value nil. |
109 Otherwise waits for PROGRAM to terminate | 162 Otherwise waits for PROGRAM to terminate and returns a numeric exit status |
110 and returns a numeric exit status or a signal description string. | 163 or a signal description string. If you quit, the process is first killed |
111 If you quit, the process is first killed with SIGINT, then with SIGKILL if | 164 with SIGINT, then with SIGKILL if you quit again before the process exits. |
112 you quit again before the process exits." | 165 |
113 (let ((temp | 166 The read/write coding systems used for process I/O on the process are |
114 (make-temp-name | 167 the same as for `call-process'." |
115 (concat (file-name-as-directory (temp-directory)) "emacs")))) | 168 ;; We used to delete the text before calling call-process; that was when |
116 (unwind-protect | 169 ;; a temporary file was used to pass the text to call-process. Now that |
117 (let (cs-r cs-w) | 170 ;; we don't do that, we delete the text afterward; if it's being inserted |
118 (let (ret) | 171 ;; in the same buffer, make sure we track the insertion, and don't get |
119 (catch 'found | 172 ;; any of it in the deleted region if insertion happens at either end |
120 (let ((alist process-coding-system-alist) | 173 ;; of the region. |
121 (case-fold-search nil)) | 174 (let ((s (and deletep (copy-marker start t))) |
122 (while alist | 175 (e (and deletep (copy-marker end)))) |
123 (if (string-match (car (car alist)) program) | 176 (apply #'call-process program (list (current-buffer) start end) |
124 (throw 'found (setq ret (cdr (car alist))))) | 177 buffer displayp args) |
125 (setq alist (cdr alist)) | 178 (if deletep (delete-region s e)))) |
126 ))) | |
127 (if (functionp ret) | |
128 (setq ret (funcall ret 'call-process-region program))) | |
129 (cond ((consp ret) | |
130 (setq cs-r (car ret) | |
131 cs-w (cdr ret))) | |
132 ((null ret) | |
133 (setq cs-r buffer-file-coding-system | |
134 cs-w buffer-file-coding-system)) | |
135 ((find-coding-system ret) | |
136 (setq cs-r ret | |
137 cs-w ret)))) | |
138 (let ((coding-system-for-read | |
139 (or coding-system-for-read cs-r)) | |
140 (coding-system-for-write | |
141 (or coding-system-for-write cs-w))) | |
142 (write-region start end temp nil 'silent) | |
143 (if deletep (delete-region start end)) | |
144 (apply #'call-process program temp buffer displayp args))) | |
145 (ignore-file-errors (delete-file temp))))) | |
146 | 179 |
147 (defun start-process (name buffer program &rest program-args) | 180 (defun start-process (name buffer program &rest program-args) |
148 "Start a program in a subprocess. Return the process object for it. | 181 "Start a program in a subprocess. Return the process object for it. |
149 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS | |
150 NAME is name for process. It is modified if necessary to make it unique. | 182 NAME is name for process. It is modified if necessary to make it unique. |
151 BUFFER is the buffer or (buffer-name) to associate with the process. | 183 BUFFER is the buffer or (buffer-name) to associate with the process. |
152 Process output goes at end of that buffer, unless you specify | 184 Process output goes at end of that buffer, unless you specify |
153 an output stream or filter function to handle the output. | 185 an output stream or filter function to handle the output. |
154 BUFFER may also be nil, meaning that this process is not associated | 186 BUFFER may be also nil, meaning that this process is not associated |
155 with any buffer. | 187 with any buffer. |
188 BUFFER can also have the form (REAL-BUFFER STDERR-BUFFER); in that case, | |
189 REAL-BUFFER says what to do with standard output, as above, | |
190 while STDERR-BUFFER says what to do with standard error in the child. | |
191 STDERR-BUFFER may be nil (discard standard error output, unless a stderr | |
192 filter is set). Note that if you do not use this form at process creation, | |
193 stdout and stderr will be mixed in the output buffer, and this cannot be | |
194 changed, even by setting a stderr filter. | |
156 Third arg is program file name. It is searched for as in the shell. | 195 Third arg is program file name. It is searched for as in the shell. |
157 Remaining arguments are strings to give program as arguments. | 196 Remaining arguments are strings to give program as arguments. |
158 INCODE and OUTCODE specify the coding-system objects used in input/output | 197 |
159 from/to the process." | 198 The read/write coding systems used for process I/O on the process are |
199 determined as follows: | |
200 | |
201 1. `coding-system-for-read', `coding-system-for-write', if non-nil. | |
202 (Intended as a temporary overriding mechanism for use by Lisp | |
203 code.) | |
204 2. The matching value for the process name from `process-coding-system-alist', | |
205 if any, and if non-nil. The value may be either a single coding | |
206 system, used for both read and write; or a cons of read/write; or a | |
207 function, called to get one of the other two values. | |
208 3. The value of `default-process-coding-system', which should be a cons | |
209 of read/write coding systems, if the values are non-nil. | |
210 4. The coding system `undecided' for read, and `raw-text' for write. | |
211 | |
212 Note that the processes of determining the read and write coding systems | |
213 proceed essentially independently one from the other. For example, a value | |
214 determined from `process-coding-system-alist' might specify a read coding | |
215 system but not a write coding system, in which the read coding system is as | |
216 specified and the write coding system comes from proceeding to step 3 (and | |
217 looking in `default-process-coding-system'). | |
218 | |
219 You can change the coding systems later on using | |
220 `set-process-coding-system', `set-process-input-coding-system', or | |
221 `set-process-output-coding-system'. | |
222 | |
223 See also `set-process-filter' and `set-process-stderr-filter'." | |
160 (let (cs-r cs-w) | 224 (let (cs-r cs-w) |
161 (let (ret) | 225 (let (ret) |
162 (catch 'found | 226 (catch 'found |
163 (let ((alist process-coding-system-alist) | 227 (let ((alist process-coding-system-alist) |
164 (case-fold-search nil)) | 228 (case-fold-search nil)) |
170 (if (functionp ret) | 234 (if (functionp ret) |
171 (setq ret (funcall ret 'start-process program))) | 235 (setq ret (funcall ret 'start-process program))) |
172 (cond ((consp ret) | 236 (cond ((consp ret) |
173 (setq cs-r (car ret) | 237 (setq cs-r (car ret) |
174 cs-w (cdr ret))) | 238 cs-w (cdr ret))) |
175 ((find-coding-system ret) | 239 ((and ret (find-coding-system ret)) |
176 (setq cs-r ret | 240 (setq cs-r ret |
177 cs-w ret)))) | 241 cs-w ret)))) |
178 (let ((coding-system-for-read | 242 (let ((coding-system-for-read |
179 (or coding-system-for-read cs-r | 243 (or coding-system-for-read cs-r |
180 (car default-process-coding-system))) | 244 (car default-process-coding-system) 'undecided)) |
181 (coding-system-for-write | 245 (coding-system-for-write |
182 (or coding-system-for-write cs-w | 246 (or coding-system-for-write cs-w |
183 (cdr default-process-coding-system)))) | 247 (cdr default-process-coding-system) 'raw-text))) |
184 (apply 'start-process-internal name buffer program program-args) | 248 (apply 'start-process-internal name buffer program program-args) |
185 ))) | 249 ))) |
186 | 250 |
187 (defvar network-coding-system-alist nil | 251 (defvar network-coding-system-alist nil |
188 "Alist to decide a coding system to use for a network I/O operation. | 252 "Alist to decide a coding system to use for a network I/O operation. |
201 | 265 |
202 (defun open-network-stream (name buffer host service &optional protocol) | 266 (defun open-network-stream (name buffer host service &optional protocol) |
203 "Open a TCP connection for a service to a host. | 267 "Open a TCP connection for a service to a host. |
204 Return a process object to represent the connection. | 268 Return a process object to represent the connection. |
205 Input and output work as for subprocesses; `delete-process' closes it. | 269 Input and output work as for subprocesses; `delete-process' closes it. |
206 Args are NAME BUFFER HOST SERVICE. | |
207 NAME is name for process. It is modified if necessary to make it unique. | 270 NAME is name for process. It is modified if necessary to make it unique. |
208 BUFFER is the buffer (or buffer-name) to associate with the process. | 271 BUFFER is the buffer (or buffer-name) to associate with the process. |
209 Process output goes at end of that buffer, unless you specify | 272 Process output goes at end of that buffer, unless you specify |
210 an output stream or filter function to handle the output. | 273 an output stream or filter function to handle the output. |
211 BUFFER may be also nil, meaning that this process is not associated | 274 BUFFER may be also nil, meaning that this process is not associated |
212 with any buffer | 275 with any buffer. |
213 Third arg is name of the host to connect to, or its IP address. | 276 Third arg is name of the host to connect to, or its IP address. |
214 Fourth arg SERVICE is name of the service desired, or an integer | 277 Fourth arg SERVICE is name of the service desired, or an integer |
215 specifying a port number to connect to. | 278 specifying a port number to connect to. |
216 Fifth argument PROTOCOL is a network protocol. Currently 'tcp | 279 Fifth argument PROTOCOL is a network protocol. Currently 'tcp |
217 (Transmission Control Protocol) and 'udp (User Datagram Protocol) are | 280 (Transmission Control Protocol) and 'udp (User Datagram Protocol) are |
220 Output via `process-send-string' and input via buffer or filter (see | 283 Output via `process-send-string' and input via buffer or filter (see |
221 `set-process-filter') are stream-oriented. That means UDP datagrams are | 284 `set-process-filter') are stream-oriented. That means UDP datagrams are |
222 not guaranteed to be sent and received in discrete packets. (But small | 285 not guaranteed to be sent and received in discrete packets. (But small |
223 datagrams around 500 bytes that are not truncated by `process-send-string' | 286 datagrams around 500 bytes that are not truncated by `process-send-string' |
224 are usually fine.) Note further that UDP protocol does not guard against | 287 are usually fine.) Note further that UDP protocol does not guard against |
225 lost packets." | 288 lost packets. |
289 | |
290 The read/write coding systems used for process I/O on the process are | |
291 determined as follows: | |
292 | |
293 1. `coding-system-for-read', `coding-system-for-write', if non-nil. | |
294 (Intended as a temporary overriding mechanism for use by Lisp | |
295 code.) | |
296 2. The matching value for the service from `network-coding-system-alist', | |
297 if any, and if non-nil. The value may be either a single coding | |
298 system, used for both read and write; or a cons of read/write; or a | |
299 function, called to get one of the other two values. | |
300 3. The value of `default-network-coding-system', which should be a cons | |
301 of read/write coding systems, if the values are non-nil. | |
302 4. The coding system `undecided' for read, and `raw-text' for write. | |
303 | |
304 Note that the processes of determining the read and write coding systems | |
305 proceed essentially independently one from the other, as in `start-process'. | |
306 | |
307 You can change the coding systems later on using | |
308 `set-process-coding-system', `set-process-input-coding-system', or | |
309 `set-process-output-coding-system'." | |
226 (let (cs-r cs-w) | 310 (let (cs-r cs-w) |
227 (let (ret) | 311 (let (ret) |
228 (catch 'found | 312 (catch 'found |
229 (let ((alist network-coding-system-alist) | 313 (let ((alist network-coding-system-alist) |
230 (case-fold-search nil) | 314 (case-fold-search nil) |
247 (if (functionp ret) | 331 (if (functionp ret) |
248 (setq ret (funcall ret 'open-network-stream service))) | 332 (setq ret (funcall ret 'open-network-stream service))) |
249 (cond ((consp ret) | 333 (cond ((consp ret) |
250 (setq cs-r (car ret) | 334 (setq cs-r (car ret) |
251 cs-w (cdr ret))) | 335 cs-w (cdr ret))) |
252 ((find-coding-system ret) | 336 ((and ret (find-coding-system ret)) |
253 (setq cs-r ret | 337 (setq cs-r ret |
254 cs-w ret)))) | 338 cs-w ret)))) |
255 (let ((coding-system-for-read | 339 (let ((coding-system-for-read |
256 (or coding-system-for-read cs-r)) | 340 (or coding-system-for-read cs-r |
341 (car default-network-coding-system) | |
342 'undecided)) | |
257 (coding-system-for-write | 343 (coding-system-for-write |
258 (or coding-system-for-write cs-w))) | 344 (or coding-system-for-write cs-w |
345 (cdr default-network-coding-system) | |
346 'raw-text))) | |
259 (open-network-stream-internal name buffer host service protocol)))) | 347 (open-network-stream-internal name buffer host service protocol)))) |
260 | 348 |
261 (defun set-buffer-process-coding-system (decoding encoding) | 349 (defun set-buffer-process-coding-system (decoding encoding) |
262 "Set coding systems for the process associated with the current buffer. | 350 "Set coding systems for the process associated with the current buffer. |
263 DECODING is the coding system to be used to decode input from the process, | 351 DECODING is the coding system to be used to decode input from the process, |
264 ENCODING is the coding system to be used to encode output to the process. | 352 ENCODING is the coding system to be used to encode output to the process. |
265 | 353 |
266 For a list of possible values of CODING-SYSTEM, use \\[list-coding-systems]." | 354 For a list of possible values of CODING-SYSTEM, use \\[coding-system-list]." |
267 (interactive | 355 (interactive |
268 "zCoding-system for process input: \nzCoding-system for process output: ") | 356 "zCoding-system for process input: \nzCoding-system for process output: ") |
269 (let ((proc (get-buffer-process (current-buffer)))) | 357 (let ((proc (get-buffer-process (current-buffer)))) |
270 (if (null proc) | 358 (if (null proc) |
271 (error "no process") | 359 (error "no process") |