annotate lisp/ilisp/comint-ipc.el @ 119:d101af7320b8

Added tag r20-1b11 for changeset 7d55a9ba150c
author cvs
date Mon, 13 Aug 2007 09:24:19 +0200
parents b82b59fe008d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; -*-Emacs-Lisp-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;;%Header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Rcs_Info: comint-ipc.el,v 1.20 1993/09/03 02:05:07 ivan Rel $
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; IPC extensions for comint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; Copyright (C) 1990 Chris McConnell, ccm@cs.cmu.edu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;;
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
11 ;;; Send mail to ilisp@naggum.no if you have problems.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;;
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
13 ;;; Send mail to ilisp-request@naggum.no if you want to be on the
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; ilisp mailing list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; but WITHOUT ANY WARRANTY. No author or distributor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; accepts responsibility to anyone for the consequences of using it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; or for whether it serves any particular purpose or works at all,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; unless he says so in writing. Refer to the GNU Emacs General Public
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; License for full details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Everyone is granted permission to copy, modify and redistribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; GNU Emacs, but only under the conditions described in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; GNU Emacs General Public License. A copy of this license is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; supposed to have been given to you along with GNU Emacs so you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; can know your rights and responsibilities. It should be in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; file named COPYING. Among other things, the copyright notice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; and this notice must be preserved on all copies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; This file contains extensions to multiplex the single channel of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; an inferior process between multiple purposes. It provides both
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; synchronous and asynchronous sends with error handling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; USAGE: Load this file and call comint-setup-ipc in a comint
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; buffer. This is not a standalone application. For an example of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; it being used see ilisp.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; CUSTOMIZATION: See the parameters and hooks below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; INTERFACE. See the function documentation and code for more information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; PROCESS INPUT: comint-send, comint-send-code, comint-default-send,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; comint-sync, comint-abort-sends
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; PROCESS OUTPUT: comint-display-output, comint-display-error-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;;%Parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defvar comint-log nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "If T, then record all process input and output in a buffer called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 process name.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defvar comint-send-newline t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "If T then add a newline to string in comint-default-send.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defvar comint-always-scroll nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "If T then process output will always be visible in first window on buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defvar comint-fix-error nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "String to send to send to the command interpreter to fix errors.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar comint-continue nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "String to send to continue an interrupted job.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar comint-interrupt-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 "Regular expression for the start of an interrupt in process output.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defvar comint-error-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "Regular expression for setting comint-errorp if found in process output.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defvar comint-output-buffer " *Output*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "Name of the output buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (defvar comint-error-buffer " *Error Output*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "Name of the error output buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defvar comint-show-status t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 "Set to nil to inhibit status redisplay.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;;%%Hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvar comint-output-filter (function identity)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "Given the complete OUTPUT of a send, return the result of the send.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defvar comint-interrupt-start 'comint-interrupt-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "Return the start in OUTPUT of the text printed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 comint-interrupt-subjob in the inferior process.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defvar comint-handler 'comint-error-popup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Default handler for sends. When a send completes, the handler is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 called with error-p, wait-p, message, output and prompt.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (defvar comint-update-status 'comint-update-status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 "Function to update the STATUS of the inferior process. It should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 set comint-status to a status string in addition to whatever else it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 does.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defvar comint-prompt-status 'comint-prompt-status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "Given the previous prompt and the last line output, return 'error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 if an error, T if a prompt and nil otherwise. If it is a prompt, also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 funcall comint-update-status to set the status. If old is nil, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 just return T if last line is a prompt.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defvar comint-abort-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "List of hooks to run after sends are aborted.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;;;%Globals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (defvar comint-send-queue nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 "List of currently pending IPC send requests. The first element in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 the queue is where output to the process will be stored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 A send record is a list of:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 string -- The string sent to the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 no-insert -- nil to insert output into the process buffer. If this is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 being done, the results will only contain the very last line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 wait-p -- nil if not waiting, non-nil if waiting. If it is a string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 results are inserted in the buffer until a result matches the string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 as a regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 status -- A symbol for the process status while the send is running.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 message -- A message to be displayed when an asynchronous send is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 popped up by the handler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 handler -- A function that given error-p, wait-p, message, output and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 prompt decides if the user should be notified. If it is nil or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 returns nil, then no error processing will be done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 running -- nil if a send is waiting, T if it is running, another send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 if interrupting and a string with pending output if the send was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 interrupted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 old-prompt -- The prompt before the send was sent. If it is nil, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 errors will not be detected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 line -- The start of the last line in the results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 result -- Cons of the output and the prompt after the send.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defvar comint-end-queue nil "Pointer to the end of comint-send-queue.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (defvar comint-queue-emptied t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "Set to T each time send queue empties.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defvar comint-output nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "Set to the output of the last send. This is useful when ilisp code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 is put in the send stream.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (defvar comint-errorp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 "Set to T if the last send was an error.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defvar comint-status " :run" "The current comint status.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (defvar comint-original-buffer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "The original buffer when there was output to a comint buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (defvar comint-last-send nil "Last send that was put in queue.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (defvar comint-aborting nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "Set to T if we are aborting commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;;%Utils
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (defun comint-remove-whitespace (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 "Remove leading and trailing whitespace in STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (if string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (let* ((start (if (string-match "[^ \t\n]" string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (end start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (while (string-match "[ \t\n]*[^ \t\n]+" string end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (setq end (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (substring string start end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defun comint-log (process string &optional output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "Log to PROCESS, STRING marking as optional OUTPUT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (if comint-log
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (set-buffer (get-buffer-create (process-name process)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (insert "{") (insert string) (insert "}"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (insert string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
189 ;;; v5.7b Removed by suggestion of erik@naggum.no (Erik Naggum).
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
191 ;;; (defun comint-send-string (proc str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
192 ;;; "Send PROCESS the contents of STRING as input.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
193 ;;; This is equivalent to process-send-string, except that long input strings
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
194 ;;; are broken up into chunks of size comint-input-chunk-size. Processes
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
195 ;;; are given a chance to output between chunks. This can help prevent
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
196 ;;; processes from hanging when you send them long inputs on some OS's."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
197 ;;; (comint-log proc str)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
198 ;;; (let* ((len (length str))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
199 ;;; (i (min len comint-input-chunk-size)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
200 ;;; (process-send-string proc (substring str 0 i))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
201 ;;; (while (< i len)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
202 ;;; (let ((next-i (+ i comint-input-chunk-size)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
203 ;;; (accept-process-output)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
204 ;;; (process-send-string proc (substring str i (min len next-i)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
205 ;;; (setq i next-i)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
206
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
207 ;;; v5.7b See above
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (defun comint-sender (process string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 "Send to PROCESS STRING with newline if comint-send-newline."
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
210 ;; (comint-send-string process string)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
211 (process-send-string process string)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (if comint-send-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (comint-log process "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (process-send-string process "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (defun comint-interrupt-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 "Interrupt the current subjob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (comint-log (get-buffer-process (current-buffer)) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (interrupt-process nil comint-ptyp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (defun comint-send-variables (send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 "Return a pointer to the start of the variables for SEND. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 returns \(running old-prompt line \(output . prompt))."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (cdr (cdr (cdr (cdr (cdr (cdr send)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (defun comint-send-results (send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 "Return the results of SEND which are \(output . prompt). If there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 an error, the prompt will be a list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (car (cdr (cdr (cdr (comint-send-variables send))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (defun comint-send-description (send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 "Return a description of SEND."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (let* ((status (cdr (cdr (cdr send)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (or (car (cdr status)) ;Message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (and (stringp (car send)) (car send)) ;String
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (and (car status) (symbol-name (car status))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (defun comint-interrupted ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 "Return T if there is an interrupted send."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (let ((send comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (while (and send (not done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (if (stringp (car (comint-send-variables (car send))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (setq done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (setq send (cdr send))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;;;%Default hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (defun comint-process-sentinel (process status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 "Update PROCESS STATUS by funcalling comint-update-status."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (setq status (process-status process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (if (buffer-name (process-buffer process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (set-buffer (process-buffer process)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (funcall comint-update-status status)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defun comint-interrupt-start (output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 "Return the start of comint-interrupt-regexp in OUTPUT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (if (and comint-interrupt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (string-match comint-interrupt-regexp output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (defun comint-update-status (status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 "Update the process STATUS of the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (setq comint-status (format " :%s" status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (if comint-show-status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (save-excursion (set-buffer (other-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (sit-for 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defun comint-prompt-status (old line &optional equal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 "Called by comint-process filter with OLD and LINE, return 'error if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 LINE is an error, T if it is a prompt as determined by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 comint-prompt-regexp or nil otherwise. Also set the status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 appropriately by funcalling comint-update-status. If specified EQUAL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 will be called with old and line and should return T if line is not an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 error. OLD will be nil for the first prompt."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (if (string-match comint-prompt-regexp line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (let ((error (or (if equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (funcall equal old line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (or (null old) (string-equal old line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 'error)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (funcall comint-update-status (if (eq error 'error) error 'ready))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (defun comint-insert (output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 "Insert process OUTPUT into the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (if output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (let* ((buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (process (get-buffer-process buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (mark (process-mark process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (at-end nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (if (eq (window-buffer window) buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (setq at-end (= (point) mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (setq window (get-buffer-window buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (goto-char mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (insert output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (set-marker mark (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (if window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (if (or at-end comint-always-scroll) (goto-char mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (if (not (pos-visible-in-window-p (point) window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (let ((original (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (select-window window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (recenter '(center))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (select-window original)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (defun comint-handle-error (output prompt keys &optional delay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 "Handle an error by beeping, displaying OUTPUT and then waiting for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 the user to pause. Once there is pause, PROMPT until one of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 characters in KEYS is typed. If optional DELAY is specified, it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 the number of seconds that the user must pause. The key found will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (setq delay (or delay 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (beep t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (comint-display-error output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (set-buffer comint-original-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (while (not (sit-for delay nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (execute-kbd-macro (read-key-sequence nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (if (not (get-buffer-window (get-buffer comint-error-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (comint-display-error output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (let ((cursor-in-echo-area t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (echo-keystrokes 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (while (progn (message prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (not (memq (setq char (downcase (read-char))) keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (if (= char ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (ilisp-scroll-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (setq quit-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (beep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (defun comint-error-popup (error wait-p message output prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 "If there is an ERROR pop up a window with MESSAGE and OUTPUT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 Nothing is done with PROMPT or WAIT-P."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (if error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (with-output-to-temp-buffer comint-output-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (set-buffer comint-output-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (if message (insert message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (insert output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (beep t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (defun comint-process-filter (process output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 "Filter PROCESS OUTPUT. See comint-send for more information. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 first element of the comint-send-queue is the current send entry. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 the entry has a nil no-insert flag, insert the results into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 process buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 If the send is an interrupt, comint-interrupt-start is funcalled on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 the output and should return the start of the output of an interrupt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 comint-prompt-status is called with the old prompt and the last line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 It should return 'error if the last line is an error, T if it is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 prompt and nil otherwise. It should also update the process status by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 funcalling comint-update-status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 If there is a send handler, it is called with \(error-p wait-p message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 output prompt) and should determine what sort of notification is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 appropriate and return T if errors should be fixed and NIL otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 If the prompt is an error, then comint-fix-error will be sent to fix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 the error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 When there is a prompt in the output stream, the next send will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 dispatched unless the wait flag for the send is a string. If it is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 string, then results will be discarded until one matches the string as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 a regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 Output to the process should only be done through the functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 comint-send or comint-default-send, or results will be mixed up."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (let* ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (comint-original-buffer (prog1 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (set-buffer (process-buffer process))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (match-data (match-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (no-insert (cdr send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (wait-p (cdr no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (messagep (cdr (cdr wait-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (handler (cdr messagep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (running (cdr handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (old-prompt (cdr running))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (line (cdr old-prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (result (car (cdr line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (old-result (car result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (no-insert (car no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (message (car messagep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (wait-p (car wait-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (sync (stringp wait-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (comint-log process output t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 ;; Remove leading whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (if (and (null old-result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (save-excursion (goto-char (process-mark process)) (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (eq (string-match "[ \t]*\n" output) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (setq output (substring output (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (rplaca result (concat old-result output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (while (string-match "\n" (car result) (car line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (rplaca line (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (if (not (or sync no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (comint-insert output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; Throw away output if storing in buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (rplaca result (substring (car result) (car line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (rplaca line 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (if (consp (car running)) ;Waiting for interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (let ((split (funcall comint-interrupt-start (car result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (if split
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (let ((interrupted (car running)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; Store output to previous send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (rplaca (comint-send-variables interrupted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (substring (car result) 0 split))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (rplaca result (substring (car result) (car line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (rplaca line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (rplaca running t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (if (not (consp (car running))) ;Look for prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (let* ((last (substring (car result) (car line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (is-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (funcall comint-prompt-status (car old-prompt) last)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (if is-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (let* ((output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (if (or no-insert sync)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (funcall comint-output-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (substring (car result) 0 (car line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (handler (car handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (error (eq is-prompt 'error)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (setq old-result (car result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (rplaca result output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (rplacd result (if error (list last) last))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (setq comint-output (car result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 comint-errorp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (or error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (and comint-error-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 comint-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (string-match comint-error-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 comint-output))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (unwind-protect
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
460 ;; (if handler
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
461 ;; (setq handler
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
462 ;; (funcall handler comint-errorp wait-p
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
463 ;; message output last)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
464
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
465 ;; v5.7b Patch suggested by fujieda@jaist.ac.jp
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
466 ;; (Kazuhiro Fujieda). Here is his comment.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
467
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
468 ;; "When the 'handler' is called, the current
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
469 ;; buffer may be changed. 'comint-process-filter'
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
470 ;; accesses some buffer-local variables, for
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
471 ;; example 'comint-send-queue' and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
472 ;; 'comint-end-queue'. If the current buffer is
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
473 ;; changed in the 'handler', the entities of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
474 ;; these buffer-local variables is replaced, and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
475 ;; corrupt successive behaviors."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
476
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
477 ;; The code hereafter fixes the problem.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
478
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (if handler
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
480 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
481 (setq handler
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
482 (funcall handler comint-errorp wait-p
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
483 message output last))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
484
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (if (and error handler no-insert comint-fix-error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (cons (list comint-fix-error t nil 'fix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 "Fixing error" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 nil nil 0 (cons nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; We may have aborted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (or (cdr comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 comint-send-queue))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (if sync
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (let ((match (string-match wait-p old-result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (if match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (rplaca
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (cdr (cdr (cdr (cdr (car comint-end-queue)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 "Done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (if (not no-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (comint-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (substring old-result 0 match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (substring old-result (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (rplaca result (substring old-result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 match (car line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (rplaca messagep "Done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (rplaca running nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (comint-dispatch-send process))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 ;; Not waiting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (rplaca messagep "Done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (rplaca running nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (comint-dispatch-send process))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (rplacd result nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (store-match-data match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (if (or (get-buffer-window comint-original-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (eq (window-buffer (minibuffer-window)) comint-original-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (set-buffer comint-original-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (defun comint-dispatch-send (process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 "Dispatch the next send in PROCESS comint-send-queue, popping the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 current send if done."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (let* ((send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (results (comint-send-results send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (prompt (cdr results)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; Never pop the last record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (cond ((and (null comint-send-queue) ; Catch a bug.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (null comint-end-queue)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ((eq comint-send-queue comint-end-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (let ((init (car send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (running (comint-send-variables send)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (setq comint-queue-emptied t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 ;; Set old prompt to prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (if prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (rplaca (cdr (comint-send-variables send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (if (consp prompt) (car prompt) prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (rplaca send nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (if init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (funcall init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (if (stringp (car running))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;; Continue if interrupted. There is no way to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ;; sense if the interrupted command actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 ;; started, so it is possible that a command will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;; get lost.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (progn (funcall comint-update-status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (car (cdr (cdr (cdr send)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (comint-sender process comint-continue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (comint-process-filter process (car running))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (rplaca running t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (if prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ;; Pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (setq comint-send-queue (cdr comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;; Set prompt to top-level prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (setq prompt (cdr (comint-send-results (car comint-end-queue)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (let* ((top-level (eq comint-send-queue comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (string (car send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (no-insert (cdr send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (wait-p (cdr no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (status (cdr wait-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (message (cdr status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (status (car status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (no-insert (car no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (message (car message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (running (comint-send-variables send)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (if top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (rplaca send nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (if (stringp string) (funcall comint-update-status status)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (if (and message (not no-insert) (not (stringp (car wait-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (not top-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 ;; Display message on first output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (comint-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (concat comment-start comment-start comment-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 message comment-end "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (if (and string (not (stringp string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ;; Elisp code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (rplacd (comint-send-results (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (if (consp prompt) (car prompt) prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (funcall string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (comint-dispatch-send process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (if (stringp (car running))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 ;; Continue interrupted send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (let ((output (car running)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (if (or top-level (car (comint-send-results send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (not (string-equal output "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 ;; Continue old command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (rplaca running t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (funcall comint-update-status status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (comint-sender process comint-continue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (comint-process-filter process output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ;; Send queued default sends
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (if (and top-level string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 (comint-sender process string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 ;; Assume we have to restart the command since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 ;; there is no output. There is no way to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ;; sense whether or not the inferior has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 ;; started processing the previous send. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ;; is a problem only if the original did start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 ;; and had side effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (rplaca running nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (cons (list comint-fix-error t nil 'fix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 "Fixing error" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 nil nil 0 (cons nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (comint-dispatch-send process)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (if (not top-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 ;; New send, set old prompt to the prompt of previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (rplaca (cdr (comint-send-variables send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (if (consp prompt) (car prompt) prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (if string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (rplaca running t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (comint-sender process string))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (defun comint-interrupt (process send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 "Interrupt PROCESS to send SEND if comint-continue is defined and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 the current send is not waiting. Otherwise, SEND will be the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 send."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (if (and comint-continue (not (car (cdr (cdr (car comint-send-queue))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (let* ((current (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ;; string no-insert wait-p status message handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (list nil t nil 'interrupt "Interrupt" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ;; running old-prompt line (output . prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 current nil 0 (cons nil nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (setq comint-send-queue (cons interrupt (cons send comint-send-queue)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (funcall comint-update-status 'interrupt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (comint-interrupt-subjob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (if (eq comint-send-queue comint-end-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (cons (car comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (cons send comint-send-queue)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (rplacd comint-send-queue (cons send (cdr comint-send-queue))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;;;%Interface
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (defun comint-setup-ipc (&optional force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 "Setup for IPC in the current buffer. If called interactively,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 force comint-send-queue to be initialized."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (make-local-variable 'comint-send-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (make-local-variable 'comint-always-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (make-local-variable 'comint-fix-error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (make-local-variable 'comint-continue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (make-local-variable 'comint-interrupt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (make-local-variable 'comint-error-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (make-local-variable 'comint-output-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (make-local-variable 'comint-interrupt-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (make-local-variable 'comint-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (make-local-variable 'comint-update-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (make-local-variable 'comint-prompt-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (make-local-variable 'comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (make-local-variable 'comint-end-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (make-local-variable 'comint-queue-emptied)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (make-local-variable 'comint-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (make-local-variable 'comint-errorp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (make-local-variable 'comint-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (make-local-variable 'comint-aborting)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (if (or force (not comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (list (list nil nil nil 'run "Top Level"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 nil t nil 0 (cons nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 comint-end-queue comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (let ((process (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (set-process-filter process 'comint-process-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (set-process-sentinel process 'comint-process-sentinel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (setq mode-line-process 'comint-status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 ;;;%%Input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (defun comint-send (process string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 &optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 no-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 wait
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 "Do a send to PROCESS of STRING. Optionally specify NO-INSERT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 WAIT, STATUS, MESSAGE, HANDLER and AFTER. Without optional arguments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 this is just like process-send-string. If STRING is not a string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 then it is assumed to be an elisp function and will be called when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 encountered in the send queue. The send will be the next one if WAIT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 after the last send if AFTER, otherwise it will be put at the end of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 the queue. If WAIT is non-NIL or on the first send to a busy inferior,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 the inferior will be interrupted if possible, see comint-interrupt for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 more information. Once the send is sent, the process status will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 STATUS or 'run. Output of the send will be inserted into the process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 buffer unless NO-INSERT. This function returns a list of \(result .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 prompt). If WAIT is a string, output will be inserted until one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 matches the string as a regexp. If WAIT is T, then PROMPT will have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 the prompt when finished and RESULT will have the output. If PROMPT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 is a list, then there was an error. If WAIT is not T, then the list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 returned will change when the send has been sent and is finished. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 HANDLER is nil it will be set to comint-handler. If it is T, errors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 will be ignored. When a send is finished, it calls handler with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 \(error-p WAIT MESSAGE output prompt) which decides what to do with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 the output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 VARIABLES:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 comint-always-scroll will cause all process output to be visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 comint-fix-error is the string used to fix errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 comint-continue is the string used to continue after an interrupt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 comint-interrupt-regexp is the default regexp to use in finding the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 start of the interrupt text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 comint-error-regexp will set comint-errorp if found in the process output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 FUNCTIONS: Each of the functions in these variables is called with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 the buffer set to the appropriate process buffer and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 comint-original-buffer bound to the buffer current when the process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 filter was called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 comint-update-status is a function \(status) that is called each time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 the process status changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 comint-prompt-status is called with the old prompt and the last line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 It should return 'error if the last line is an error, T if it is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 prompt and nil otherwise. It should also update the process status by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 funcalling comint-update-status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 comint-output-filter is a function \(output) for sends with NO-INSERT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 It should return the output string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 comint-interrupt-start is a function \(output) that returns the start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 of the interrupt text in output using comint-interrupt-regexp to find it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (set-buffer (process-buffer process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (let* ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (send (list string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 no-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 wait
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (or status 'run)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (if (eq handler t) nil (or handler comint-handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 ;; running, old-prompt, line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 nil nil 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 ;; (output . prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (cons nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (pointer (comint-send-results send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (top-level (eq comint-send-queue comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (end (car comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (current (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (prompt (cdr (comint-send-results current)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (ok nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (setq comint-aborting nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (if (and top-level (or (stringp wait) prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (setq comint-send-queue (cons send comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (comint-dispatch-send process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (if (or (and wait (not after) (not prompt)) top-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (comint-interrupt process send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (let ((looking t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (next comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (if after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (while (and looking next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (if (eq (car next) comint-last-send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (rplacd next (cons send (cdr next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (setq looking nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (setq next (cdr next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (if looking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (rplaca comint-end-queue send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (setq comint-end-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (rplacd comint-end-queue (cons end nil))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (setq comint-last-send send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (let ((inhibit-quit nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (if (eq wait t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (while (not (cdr pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (accept-process-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (sit-for 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (setq ok pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (if (not ok)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (if (eq send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (let ((interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ;; string no-insert wait status message handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (list nil t nil 'interrupt "Interrupt" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 ;; running old-prompt line (output . prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 send (car (cdr (comint-send-variables send)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 nil (cons nil nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (cons interrupt (cdr comint-send-queue)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (comint-interrupt-subjob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (setq comint-send-queue (delq send comint-send-queue))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (defun comint-send-code (process code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 "Execute after the previous send in PROCESS queue CODE. You do not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 want to execute synchronous sends in the code or it will lock up. "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (comint-send process code nil nil nil nil nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (defun comint-default-send (process string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 "Send to PROCESS top-level, STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (set-buffer (process-buffer process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (let* ((top (car comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (old (car top)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (rplaca (cdr (cdr (cdr (cdr (car comint-end-queue))))) string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (if (eq comint-send-queue comint-end-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (progn (funcall comint-update-status 'run)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (rplaca (comint-send-variables (car comint-send-queue)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (rplacd (comint-send-results (car comint-send-queue)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (comint-sender process string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (rplaca top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (if old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (concat old (if comint-send-newline "\n") string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 string))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (defun comint-sync (process start start-regexp end end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 "Synchronize with PROCESS output stream. START will be sent with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 each prompt received until START-REGEXP shows up in the stream. Then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 END will be sent and all output will be discarded until END-REGEXP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 shows up in the output stream."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (comint-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 nil start-regexp 'sync "Start sync"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (function (lambda (error-p wait message output prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (if (not (string-match wait output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (comint-sender
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (get-buffer-process (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (car (car comint-send-queue))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (comint-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 t end-regexp 'sync "End sync"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (function (lambda (&rest args) nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (defun comint-abort-sends (&optional process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 "Abort all of the pending sends for optional PROCESS and show their
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 messages in *Aborted Commands*."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (setq process (or process (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (set-buffer (process-buffer process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (setq comint-aborting t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (if (not (eq comint-send-queue comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (let* ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (vars (comint-send-variables send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (pointer comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (new nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (interrupt (and (car vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (not (cdr (comint-send-results send))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (if interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (progn ;Sent, but no prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (if (consp (car vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (progn (setq new (list send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (rplaca (cdr (cdr (cdr (cdr (cdr send)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (function (lambda (&rest args) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (setq new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (list nil t nil 'interrupt "Interrupt"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (function (lambda (&rest args) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 send (car (cdr (comint-send-variables send)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 nil (cons nil nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (comint-interrupt-subjob)))) ;Already interrupting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (set-buffer (get-buffer-create "*Aborted Commands*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (delete-region (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (while (not (eq pointer comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (let ((send (car pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (if (car (cdr (cdr (cdr (cdr send))))) ;Message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (set-buffer "*Aborted Commands*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (insert (comint-send-description send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (insert "\n\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (if (and comint-fix-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (stringp (car (comint-send-variables send))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 ;; Interrupted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (setq new (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (list comint-fix-error t nil 'fix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 "Fixing error" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 nil nil 0 (cons nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (setq pointer (cdr pointer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (bury-buffer "*Aborted Commands*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (rplaca (car comint-end-queue) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (reverse (cons (car comint-end-queue) new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 comint-end-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (let ((pointer comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (while (cdr pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (setq pointer (cdr pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (run-hooks 'comint-abort-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (if (not interrupt) (comint-dispatch-send process))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (defun comint-current-send (showp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 "Show the message of the current send in the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (if showp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (with-output-to-temp-buffer comint-output-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (let ((send comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (set-buffer comint-output-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (insert "Pending commands:\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (while send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (let ((message (car (cdr (cdr (cdr (cdr (car send))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (if message (insert (concat message "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (setq send (cdr send)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (concat "Command: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (or (comint-send-description (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 "Unknown"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (defun comint-display-output (text &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 "Put TEXT in optional BUFFER and show it in a small temporary window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (setq buffer (or buffer comint-output-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (with-output-to-temp-buffer buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (insert text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (set-buffer-modified-p nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 ;; Perhaps this should use ilisp-display-output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (defun comint-display-error (text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 "Put TEXT in the comint-error-buffer and display it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (comint-display-output text comint-error-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (provide 'comint-ipc)