annotate lisp/code-process.el @ 4792:95b04754ea8c

Make #'equalp more compatible with CL; add a compiler macro, test & doc it. lisp/ChangeLog addition: 2009-11-08 Aidan Kehoe <kehoea@parhasard.net> * cl-extra.el (cl-string-vector-equalp) (cl-bit-vector-vector-equalp, cl-vector-array-equalp) (cl-hash-table-contents-equalp): New functions, to implement equalp treating arrays with identical contents as equivalent, as specified by Common Lisp. (equalp): Revise this function to implement array equivalence, and the hash-table equalp behaviour specified by CL. * cl-macs.el (equalp): Add a compiler macro for this function, used when one of the arguments is constant, and as such, its type is known at compile time. man/ChangeLog addition: 2009-11-08 Aidan Kehoe <kehoea@parhasard.net> * lispref/objects.texi (Equality Predicates): Document #'equalp here, as well as #'equal and #'eq. tests/ChangeLog addition: 2009-12-31 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-tests.el: Test much of the functionality of equalp; add a pointer to Paul Dietz' ANSI test suite for this function, converted to Emacs Lisp. Not including the tests themselves in XEmacs because who owns the copyright on the files is unclear and the GCL people didn't respond to my queries.
author Aidan Kehoe <kehoea@parhasard.net>
date Thu, 31 Dec 2009 15:09:41 +0000
parents 0b060ef35789
children 91b3aa59f49b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; code-process.el --- Process coding functions for XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985-1987, 1993, 1994, 1997 Free Software Foundation, Inc.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
4 ;; Copyright (C) 1995, 2000, 2002 Ben Wing
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Copyright (C) 1997 MORIOKA Tomohiko
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Author: Ben Wing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; MORIOKA Tomohiko
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; Keywords: mule, multilingual, coding system, process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; This file is very similar to code-process.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;; along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 (defvar process-coding-system-alist nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 "Alist to decide a coding system to use for a process I/O operation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 The format is ((PATTERN . VAL) ...),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 where PATTERN is a regular expression matching a program name,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 VAL is a coding system, a cons of coding systems, or a function symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 If VAL is a coding system, it is used for both decoding what received
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 from the program and encoding what sent to the program.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 If VAL is a cons of coding systems, the car part is used for decoding,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 and the cdr part is used for encoding.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
42 If VAL is a function symbol, it is called with two arguments, a symbol
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
43 indicating the operation being performed (one of `start-process',
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
44 `call-process', `open-network-stream', or `open-multicast-group') and the
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
45 program name. The function must return a coding system or a cons of
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
46 coding systems which are used as above.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 (defun call-process (program &optional infile buffer displayp &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 "Call PROGRAM synchronously in separate process.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
50
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 The program's input comes from file INFILE (nil means `/dev/null').
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
52 XEmacs feature: INFILE can also be a list of (BUFFER [START [END]]), i.e.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
53 a list of one to three elements, consisting of a buffer and optionally
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
54 a start position or start and end position. In this case, input comes
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
55 from the buffer, starting from START (defaults to the beginning of the
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
56 buffer) and ending at END (defaults to the end of the buffer).
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
57
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Insert output in BUFFER before point; t means current buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 nil for BUFFER means discard it; 0 means discard and don't wait.
837
0490271de7d8 [xemacs-hg @ 2002-05-14 05:30:30 by adrian]
adrian
parents: 771
diff changeset
60 If BUFFER is a string, then find or create a buffer with that name,
0490271de7d8 [xemacs-hg @ 2002-05-14 05:30:30 by adrian]
adrian
parents: 771
diff changeset
61 then insert the output in that buffer, before point.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 REAL-BUFFER says what to do with standard output, as above,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 while STDERR-FILE says what to do with standard error in the child.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 STDERR-FILE may be nil (discard standard error output),
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
66 t (mix it with ordinary output), a file name string, or (XEmacs feature)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
67 a buffer object. If STDERR-FILE is a buffer object (but not the name of
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
68 a buffer, since that would be interpreted as a file), the standard error
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
69 output will be inserted into the buffer before point.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
71 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 Remaining arguments are strings passed as command arguments to PROGRAM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
74 If BUFFER is 0, returns immediately with value nil.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
75 Otherwise waits for PROGRAM to terminate and returns a numeric exit status
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
76 or a signal description string. If you quit, the process is first killed
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
77 with SIGINT, then with SIGKILL if you quit again before the process exits.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
78
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
79 If INFILE is a file, we transfer its exact contents to the process without
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
80 any encoding/decoding. (#### This policy might change.)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
81
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
82 Otherwise, the read/write coding systems used for process I/O on the
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
83 process are determined as follows:
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
84
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
85 1. `coding-system-for-read', `coding-system-for-write', if non-nil.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
86 (Intended as a temporary overriding mechanism for use by Lisp
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
87 code.)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
88 2. The matching value for the process name from `process-coding-system-alist',
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
89 if any, and if non-nil. The value may be either a single coding
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
90 system, used for both read and write; or a cons of read/write; or a
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
91 function, called to get one of the other two values.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
92 3. For writing: If a buffer was given in INFILE, the value of
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
93 `buffer-file-coding-system' in that buffer.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
94 For reading: if a buffer was given in BUFFER, the value of
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
95 `buffer-file-coding-system-for-read' in that buffer.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
96 4. The value of `default-process-coding-system', which should be a cons
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
97 of read/write coding systems, if the values are non-nil.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
98 5. The coding system `undecided' for read, and `raw-text' for write.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
99
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
100 Note that the processes of determining the read and write coding systems
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
101 proceed essentially independently one from the other, as in `start-process'."
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
102 (let (cs-r cs-w)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
103 (let (ret)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
104 (catch 'found
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
105 (let ((alist process-coding-system-alist)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
106 (case-fold-search nil))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
107 (while alist
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
108 (if (string-match (car (car alist)) program)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
109 (throw 'found (setq ret (cdr (car alist)))))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
110 (setq alist (cdr alist))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
111 )))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
112 (if (functionp ret)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
113 (setq ret (funcall ret 'call-process program)))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
114 (cond ((consp ret)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
115 (setq cs-r (car ret)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
116 cs-w (cdr ret)))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
117 ((and ret (find-coding-system ret))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
118 (setq cs-r ret
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
119 cs-w ret))))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
120 (let ((coding-system-for-read
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
121 (or coding-system-for-read cs-r
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
122 (let ((thebuf (if (consp buffer) (car buffer) buffer)))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
123 (and (or (bufferp thebuf) (stringp thebuf))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
124 (get-buffer thebuf)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
125 (symbol-value-in-buffer
857
b5278486690c [xemacs-hg @ 2002-05-31 07:14:51 by michaels]
michaels
parents: 853
diff changeset
126 'buffer-file-coding-system-for-read (get-buffer thebuf))))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
127 (car default-process-coding-system)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
128 'undecided))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
129 (coding-system-for-write
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
130 (or coding-system-for-write cs-w
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
131 (and (consp infile)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
132 (symbol-value-in-buffer
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
133 'buffer-file-coding-system
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
134 (get-buffer (car infile))))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
135 (cdr default-process-coding-system)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
136 'raw-text)))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
137 (apply 'call-process-internal program infile buffer displayp args))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (defun call-process-region (start end program
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 &optional deletep buffer displayp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 "Send text from START to END to a synchronous process running PROGRAM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 Delete the text if fourth arg DELETEP is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 Insert output in BUFFER before point; t means current buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 nil for BUFFER means discard it; 0 means discard and don't wait.
837
0490271de7d8 [xemacs-hg @ 2002-05-14 05:30:30 by adrian]
adrian
parents: 771
diff changeset
147 If BUFFER is a string, then find or create a buffer with that name,
0490271de7d8 [xemacs-hg @ 2002-05-14 05:30:30 by adrian]
adrian
parents: 771
diff changeset
148 then insert the output in that buffer, before point.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 REAL-BUFFER says what to do with standard output, as above,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 while STDERR-FILE says what to do with standard error in the child.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 STDERR-FILE may be nil (discard standard error output),
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
153 t (mix it with ordinary output), a file name string, or (XEmacs feature)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
154 a buffer object. If STDERR-FILE is a buffer object (but not the name of
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
155 a buffer, since that would be interpreted as a file), the standard error
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
156 output will be inserted into the buffer before point.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 Sixth arg DISPLAYP non-nil means redisplay buffer as output is inserted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 Remaining args are passed to PROGRAM at startup as command args.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 If BUFFER is 0, returns immediately with value nil.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
162 Otherwise waits for PROGRAM to terminate and returns a numeric exit status
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
163 or a signal description string. If you quit, the process is first killed
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
164 with SIGINT, then with SIGKILL if you quit again before the process exits.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
165
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
166 The read/write coding systems used for process I/O on the process are
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
167 the same as for `call-process'."
2356
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
168
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
169 ;; We can't delete the region before feeding it to `call-process', so we
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
170 ;; take care not to delete the insertion when we delete the region. START
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
171 ;; and END may not be markers; copy them. (point) will end up after the
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
172 ;; insertion. A copy of (point) tracks the beginning of the insertion.
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
173
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
174 (let ((s (and deletep (copy-marker start))) ; Only YOU can
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
175 (e (and deletep (copy-marker end t))) ; prevent
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
176 (p (and deletep (copy-marker (point)))) ; excess consing!
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
177 (retval
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
178 (apply #'call-process program (list (current-buffer) start end)
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
179 buffer displayp args)))
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
180 (when deletep
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
181 (if (<= s p e)
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
182 ;; region was split by insertion
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
183 ;; the order checks are gilt lilies
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
184 (progn (when (< (point) e) (delete-region (point) e))
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
185 (when (< s p) (delete-region s p)))
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
186 ;; insertion was outside of region
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
187 (delete-region s e)))
0b060ef35789 [xemacs-hg @ 2004-10-28 11:31:09 by stephent]
stephent
parents: 1978
diff changeset
188 retval))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (defun start-process (name buffer program &rest program-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 "Start a program in a subprocess. Return the process object for it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 NAME is name for process. It is modified if necessary to make it unique.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 BUFFER is the buffer or (buffer-name) to associate with the process.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
194 Process output goes at end of that buffer, unless you specify
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
195 an output stream or filter function to handle the output.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
196 BUFFER may be also nil, meaning that this process is not associated
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
197 with any buffer.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
198 BUFFER can also have the form (REAL-BUFFER STDERR-BUFFER); in that case,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
199 REAL-BUFFER says what to do with standard output, as above,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
200 while STDERR-BUFFER says what to do with standard error in the child.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
201 STDERR-BUFFER may be nil (discard standard error output, unless a stderr
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
202 filter is set). Note that if you do not use this form at process creation,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
203 stdout and stderr will be mixed in the output buffer, and this cannot be
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
204 changed, even by setting a stderr filter.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 Third arg is program file name. It is searched for as in the shell.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 Remaining arguments are strings to give program as arguments.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
207
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
208 The read/write coding systems used for process I/O on the process are
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
209 determined as follows:
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
210
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
211 1. `coding-system-for-read', `coding-system-for-write', if non-nil.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
212 (Intended as a temporary overriding mechanism for use by Lisp
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
213 code.)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
214 2. The matching value for the process name from `process-coding-system-alist',
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
215 if any, and if non-nil. The value may be either a single coding
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
216 system, used for both read and write; or a cons of read/write; or a
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
217 function, called to get one of the other two values.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
218 3. The value of `default-process-coding-system', which should be a cons
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
219 of read/write coding systems, if the values are non-nil.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
220 4. The coding system `undecided' for read, and `raw-text' for write.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
221
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
222 Note that the processes of determining the read and write coding systems
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
223 proceed essentially independently one from the other. For example, a value
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
224 determined from `process-coding-system-alist' might specify a read coding
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
225 system but not a write coding system, in which the read coding system is as
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
226 specified and the write coding system comes from proceeding to step 3 (and
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
227 looking in `default-process-coding-system').
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
228
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
229 You can change the coding systems later on using
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
230 `set-process-coding-system', `set-process-input-coding-system', or
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
231 `set-process-output-coding-system'.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
232
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
233 See also `set-process-filter' and `set-process-stderr-filter'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (let (cs-r cs-w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (let (ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (catch 'found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (let ((alist process-coding-system-alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (while alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (if (string-match (car (car alist)) program)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (throw 'found (setq ret (cdr (car alist)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (setq alist (cdr alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (if (functionp ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (setq ret (funcall ret 'start-process program)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (cond ((consp ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (setq cs-r (car ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 cs-w (cdr ret)))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
249 ((and ret (find-coding-system ret))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (setq cs-r ret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 cs-w ret))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (let ((coding-system-for-read
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
253 (or coding-system-for-read cs-r
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
254 (car default-process-coding-system) 'undecided))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 (coding-system-for-write
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
256 (or coding-system-for-write cs-w
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
257 (cdr default-process-coding-system) 'raw-text)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (apply 'start-process-internal name buffer program program-args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (defvar network-coding-system-alist nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 "Alist to decide a coding system to use for a network I/O operation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 The format is ((PATTERN . VAL) ...),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 where PATTERN is a regular expression matching a network service name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 or is a port number to connect to,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 VAL is a coding system, a cons of coding systems, or a function symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 If VAL is a coding system, it is used for both decoding what received
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 from the network stream and encoding what sent to the network stream.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 If VAL is a cons of coding systems, the car part is used for decoding,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 and the cdr part is used for encoding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 If VAL is a function symbol, the function must return a coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 or a cons of coding systems which are used as above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 See also the function `find-operation-coding-system'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (defun open-network-stream (name buffer host service &optional protocol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 "Open a TCP connection for a service to a host.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
278 Return a process object to represent the connection.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 Input and output work as for subprocesses; `delete-process' closes it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 NAME is name for process. It is modified if necessary to make it unique.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 BUFFER is the buffer (or buffer-name) to associate with the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 Process output goes at end of that buffer, unless you specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 an output stream or filter function to handle the output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 BUFFER may be also nil, meaning that this process is not associated
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
285 with any buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 Third arg is name of the host to connect to, or its IP address.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 Fourth arg SERVICE is name of the service desired, or an integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 specifying a port number to connect to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 Fifth argument PROTOCOL is a network protocol. Currently 'tcp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (Transmission Control Protocol) and 'udp (User Datagram Protocol) are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 supported. When omitted, 'tcp is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
293 Output via `process-send-string' and input via buffer or filter (see
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 `set-process-filter') are stream-oriented. That means UDP datagrams are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 not guaranteed to be sent and received in discrete packets. (But small
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 datagrams around 500 bytes that are not truncated by `process-send-string'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 are usually fine.) Note further that UDP protocol does not guard against
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
298 lost packets.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
299
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
300 The read/write coding systems used for process I/O on the process are
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
301 determined as follows:
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
302
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
303 1. `coding-system-for-read', `coding-system-for-write', if non-nil.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
304 (Intended as a temporary overriding mechanism for use by Lisp
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
305 code.)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
306 2. The matching value for the service from `network-coding-system-alist',
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
307 if any, and if non-nil. The value may be either a single coding
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
308 system, used for both read and write; or a cons of read/write; or a
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
309 function, called to get one of the other two values.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
310 3. The value of `default-network-coding-system', which should be a cons
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
311 of read/write coding systems, if the values are non-nil.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
312 4. The coding system `undecided' for read, and `raw-text' for write.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
313
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
314 Note that the processes of determining the read and write coding systems
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
315 proceed essentially independently one from the other, as in `start-process'.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
316
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
317 You can change the coding systems later on using
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
318 `set-process-coding-system', `set-process-input-coding-system', or
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
319 `set-process-output-coding-system'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (let (cs-r cs-w)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (let (ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 (catch 'found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (let ((alist network-coding-system-alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (case-fold-search nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (while alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (setq pattern (car (car alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (cond ((numberp pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (and (numberp service)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 (eq pattern service)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 ((stringp pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (or (and (stringp service)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (string-match pattern service))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (and (numberp service)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (string-match pattern
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (number-to-string service))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (throw 'found (setq ret (cdr (car alist)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (setq alist (cdr alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 )))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (if (functionp ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (setq ret (funcall ret 'open-network-stream service)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (cond ((consp ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (setq cs-r (car ret)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 cs-w (cdr ret)))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
346 ((and ret (find-coding-system ret))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (setq cs-r ret
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 cs-w ret))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (let ((coding-system-for-read
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
350 (or coding-system-for-read cs-r
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
351 (car default-network-coding-system)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
352 'undecided))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (coding-system-for-write
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
354 (or coding-system-for-write cs-w
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
355 (cdr default-network-coding-system)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
356 'raw-text)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (open-network-stream-internal name buffer host service protocol))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
359 (defun set-buffer-process-coding-system (decoding encoding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
360 "Set coding systems for the process associated with the current buffer.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
361 DECODING is the coding system to be used to decode input from the process,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
362 ENCODING is the coding system to be used to encode output to the process.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
363
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 837
diff changeset
364 For a list of possible values of CODING-SYSTEM, use \\[coding-system-list]."
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
365 (interactive
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
366 "zCoding-system for process input: \nzCoding-system for process output: ")
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
367 (let ((proc (get-buffer-process (current-buffer))))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
368 (if (null proc)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
369 (error "no process")
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
370 (get-coding-system decoding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
371 (get-coding-system encoding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
372 (set-process-coding-system proc decoding encoding)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
373 (force-mode-line-update))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 444
diff changeset
374
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
375 ;;; code-process.el ends here