annotate lisp/ilisp/comint-ipc.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children b82b59fe008d
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 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; Send mail to ilisp@lehman.com if you have problems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; Send mail to ilisp-request@lehman.com if you want to be on the
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (defun comint-send-string (proc str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 "Send PROCESS the contents of STRING as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 This is equivalent to process-send-string, except that long input strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 are broken up into chunks of size comint-input-chunk-size. Processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 are given a chance to output between chunks. This can help prevent processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 from hanging when you send them long inputs on some OS's."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (comint-log proc str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (let* ((len (length str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (i (min len comint-input-chunk-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (process-send-string proc (substring str 0 i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (while (< i len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (let ((next-i (+ i comint-input-chunk-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (accept-process-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (process-send-string proc (substring str i (min len next-i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (setq i next-i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (defun comint-sender (process string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 "Send to PROCESS STRING with newline if comint-send-newline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (comint-send-string process string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (if comint-send-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (comint-log process "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (process-send-string process "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (defun comint-interrupt-subjob ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 "Interrupt the current subjob."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (comint-log (get-buffer-process (current-buffer)) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (interrupt-process nil comint-ptyp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (defun comint-send-variables (send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 "Return a pointer to the start of the variables for SEND. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 returns \(running old-prompt line \(output . prompt))."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (cdr (cdr (cdr (cdr (cdr (cdr send)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (defun comint-send-results (send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 "Return the results of SEND which are \(output . prompt). If there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 an error, the prompt will be a list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (car (cdr (cdr (cdr (comint-send-variables send))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (defun comint-send-description (send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 "Return a description of SEND."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (let* ((status (cdr (cdr (cdr send)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (or (car (cdr status)) ;Message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (and (stringp (car send)) (car send)) ;String
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (and (car status) (symbol-name (car status))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (defun comint-interrupted ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 "Return T if there is an interrupted send."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (let ((send comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (while (and send (not done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (if (stringp (car (comint-send-variables (car send))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (setq done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq send (cdr send))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;;;%Default hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (defun comint-process-sentinel (process status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 "Update PROCESS STATUS by funcalling comint-update-status."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq status (process-status process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (if (buffer-name (process-buffer process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (set-buffer (process-buffer process)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (funcall comint-update-status status)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (defun comint-interrupt-start (output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 "Return the start of comint-interrupt-regexp in OUTPUT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (if (and comint-interrupt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (string-match comint-interrupt-regexp output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (defun comint-update-status (status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 "Update the process STATUS of the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (setq comint-status (format " :%s" status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (if comint-show-status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (save-excursion (set-buffer (other-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (sit-for 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (defun comint-prompt-status (old line &optional equal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 "Called by comint-process filter with OLD and LINE, return 'error if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 LINE is an error, T if it is a prompt as determined by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 comint-prompt-regexp or nil otherwise. Also set the status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 appropriately by funcalling comint-update-status. If specified EQUAL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 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
286 error. OLD will be nil for the first prompt."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (if (string-match comint-prompt-regexp line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (let ((error (or (if equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (funcall equal old line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (or (null old) (string-equal old line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 'error)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (funcall comint-update-status (if (eq error 'error) error 'ready))
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 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (defun comint-insert (output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 "Insert process OUTPUT into the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (if output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (let* ((buffer (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (process (get-buffer-process buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (mark (process-mark process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (at-end nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (if (eq (window-buffer window) buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (setq at-end (= (point) mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setq window (get-buffer-window buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (goto-char mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (insert output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (set-marker mark (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (if window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (if (or at-end comint-always-scroll) (goto-char mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (if (not (pos-visible-in-window-p (point) window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (let ((original (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (select-window window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (recenter '(center))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (select-window original)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (defun comint-handle-error (output prompt keys &optional delay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 "Handle an error by beeping, displaying OUTPUT and then waiting for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 the user to pause. Once there is pause, PROMPT until one of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 characters in KEYS is typed. If optional DELAY is specified, it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 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
328 returned."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (setq delay (or delay 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (beep t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (comint-display-error output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (set-buffer comint-original-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (while (not (sit-for delay nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (execute-kbd-macro (read-key-sequence nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (if (not (get-buffer-window (get-buffer comint-error-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (comint-display-error output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (let ((cursor-in-echo-area t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (echo-keystrokes 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (while (progn (message prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (not (memq (setq char (downcase (read-char))) keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (if (= char ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (ilisp-scroll-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (setq quit-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (beep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (defun comint-error-popup (error wait-p message output prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 "If there is an ERROR pop up a window with MESSAGE and OUTPUT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 Nothing is done with PROMPT or WAIT-P."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (if error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (with-output-to-temp-buffer comint-output-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (set-buffer comint-output-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (if message (insert message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (insert output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (beep t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (defun comint-process-filter (process output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 "Filter PROCESS OUTPUT. See comint-send for more information. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 first element of the comint-send-queue is the current send entry. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 the entry has a nil no-insert flag, insert the results into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 process buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 If the send is an interrupt, comint-interrupt-start is funcalled on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 the output and should return the start of the output of an interrupt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 comint-prompt-status is called with the old prompt and the last line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 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
375 prompt and nil otherwise. It should also update the process status by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 funcalling comint-update-status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 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
379 output prompt) and should determine what sort of notification is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 appropriate and return T if errors should be fixed and NIL otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 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
383 the error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 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
386 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
387 string, then results will be discarded until one matches the string as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 a regexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 Output to the process should only be done through the functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 comint-send or comint-default-send, or results will be mixed up."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (let* ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (comint-original-buffer (prog1 (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (set-buffer (process-buffer process))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (match-data (match-data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (no-insert (cdr send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (wait-p (cdr no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (messagep (cdr (cdr wait-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (handler (cdr messagep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (running (cdr handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (old-prompt (cdr running))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (line (cdr old-prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (result (car (cdr line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (old-result (car result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (no-insert (car no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (message (car messagep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (wait-p (car wait-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (sync (stringp wait-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (comint-log process output t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ;; Remove leading whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (if (and (null old-result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (save-excursion (goto-char (process-mark process)) (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (eq (string-match "[ \t]*\n" output) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (setq output (substring output (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (rplaca result (concat old-result output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (while (string-match "\n" (car result) (car line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (rplaca line (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (if (not (or sync no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (comint-insert output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; Throw away output if storing in buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (rplaca result (substring (car result) (car line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (rplaca line 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (if (consp (car running)) ;Waiting for interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (let ((split (funcall comint-interrupt-start (car result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (if split
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (let ((interrupted (car running)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ;; Store output to previous send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (rplaca (comint-send-variables interrupted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (substring (car result) 0 split))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (rplaca result (substring (car result) (car line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (rplaca line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (rplaca running t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (if (not (consp (car running))) ;Look for prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (let* ((last (substring (car result) (car line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (is-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (funcall comint-prompt-status (car old-prompt) last)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (if is-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (let* ((output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (if (or no-insert sync)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (funcall comint-output-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (substring (car result) 0 (car line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (handler (car handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (error (eq is-prompt 'error)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (setq old-result (car result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (rplaca result output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (rplacd result (if error (list last) last))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (setq comint-output (car result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 comint-errorp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (or error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (and comint-error-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 comint-output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (string-match 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 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (if handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (setq handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (funcall handler comint-errorp wait-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 message output last)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (if (and error handler no-insert comint-fix-error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (cons (list comint-fix-error t nil 'fix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 "Fixing error" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 nil nil 0 (cons nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; We may have aborted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (or (cdr comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 comint-send-queue))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (if sync
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (let ((match (string-match wait-p old-result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (if match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (rplaca
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (cdr (cdr (cdr (cdr (car comint-end-queue)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 "Done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (if (not no-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (comint-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (substring old-result 0 match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (substring old-result (match-end 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (rplaca result (substring old-result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 match (car line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (rplaca messagep "Done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (rplaca running nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (comint-dispatch-send process))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; Not waiting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (rplaca messagep "Done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (rplaca running nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (comint-dispatch-send process))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (rplacd result nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (store-match-data match-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (if (or (get-buffer-window comint-original-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (eq (window-buffer (minibuffer-window)) comint-original-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (set-buffer comint-original-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (defun comint-dispatch-send (process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 "Dispatch the next send in PROCESS comint-send-queue, popping the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 current send if done."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (let* ((send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (results (comint-send-results send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (prompt (cdr results)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; Never pop the last record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (cond ((and (null comint-send-queue) ; Catch a bug.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (null comint-end-queue)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ((eq comint-send-queue comint-end-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (let ((init (car send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (running (comint-send-variables send)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (setq comint-queue-emptied t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;; Set old prompt to prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (if prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (rplaca (cdr (comint-send-variables send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (if (consp prompt) (car prompt) prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (rplaca send nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (if init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (funcall init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (if (stringp (car running))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ;; Continue if interrupted. There is no way to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ;; sense if the interrupted command actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 ;; started, so it is possible that a command will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 ;; get lost.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (progn (funcall comint-update-status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (car (cdr (cdr (cdr send)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (comint-sender process comint-continue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (comint-process-filter process (car running))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (rplaca running t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (if prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; Pop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (setq comint-send-queue (cdr comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ;; Set prompt to top-level prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (setq prompt (cdr (comint-send-results (car comint-end-queue)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (let* ((top-level (eq comint-send-queue comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (string (car send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (no-insert (cdr send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (wait-p (cdr no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (status (cdr wait-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (message (cdr status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (status (car status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (no-insert (car no-insert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (message (car message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (running (comint-send-variables send)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (if top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (rplaca send nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (if (stringp string) (funcall comint-update-status status)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (if (and message (not no-insert) (not (stringp (car wait-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (not top-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 ;; Display message on first output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (comint-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (concat comment-start comment-start comment-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 message comment-end "\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (if (and string (not (stringp string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ;; Elisp code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (rplacd (comint-send-results (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (if (consp prompt) (car prompt) prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (funcall string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (comint-dispatch-send process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (if (stringp (car running))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;; Continue interrupted send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (let ((output (car running)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (if (or top-level (car (comint-send-results send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (not (string-equal output "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 ;; Continue old command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (rplaca running t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (funcall comint-update-status status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (comint-sender process comint-continue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (comint-process-filter process output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ;; Send queued default sends
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (if (and top-level string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (comint-sender process string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;; Assume we have to restart the command since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;; there is no output. There is no way to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ;; sense whether or not the inferior has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ;; started processing the previous send. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 ;; is a problem only if the original did start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ;; and had side effects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (rplaca running nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (cons (list comint-fix-error t nil 'fix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 "Fixing error" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 nil nil 0 (cons nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (comint-dispatch-send process)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (if (not top-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 ;; New send, set old prompt to the prompt of previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (rplaca (cdr (comint-send-variables send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (if (consp prompt) (car prompt) prompt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (if string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (rplaca running t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (comint-sender process string))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (defun comint-interrupt (process send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 "Interrupt PROCESS to send SEND if comint-continue is defined and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 the current send is not waiting. Otherwise, SEND will be the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 send."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (if (and comint-continue (not (car (cdr (cdr (car comint-send-queue))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (let* ((current (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 ;; string no-insert wait-p status message handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (list nil t nil 'interrupt "Interrupt" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 ;; running old-prompt line (output . prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 current nil 0 (cons nil nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (setq comint-send-queue (cons interrupt (cons send comint-send-queue)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (funcall comint-update-status 'interrupt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (comint-interrupt-subjob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (if (eq comint-send-queue comint-end-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (cons (car comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (cons send comint-send-queue)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (rplacd comint-send-queue (cons send (cdr comint-send-queue))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 ;;;%Interface
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (defun comint-setup-ipc (&optional force)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 "Setup for IPC in the current buffer. If called interactively,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 force comint-send-queue to be initialized."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (make-local-variable 'comint-send-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (make-local-variable 'comint-always-scroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (make-local-variable 'comint-fix-error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (make-local-variable 'comint-continue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (make-local-variable 'comint-interrupt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (make-local-variable 'comint-error-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (make-local-variable 'comint-output-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (make-local-variable 'comint-interrupt-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (make-local-variable 'comint-handler)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (make-local-variable 'comint-update-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (make-local-variable 'comint-prompt-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (make-local-variable 'comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (make-local-variable 'comint-end-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (make-local-variable 'comint-queue-emptied)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (make-local-variable 'comint-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (make-local-variable 'comint-errorp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (make-local-variable 'comint-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (make-local-variable 'comint-aborting)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (if (or force (not comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (list (list nil nil nil 'run "Top Level"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 nil t nil 0 (cons nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 comint-end-queue comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (let ((process (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (set-process-filter process 'comint-process-filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (set-process-sentinel process 'comint-process-sentinel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (setq mode-line-process 'comint-status))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ;;;%%Input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (defun comint-send (process string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 &optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 no-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 wait
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 "Do a send to PROCESS of STRING. Optionally specify NO-INSERT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 WAIT, STATUS, MESSAGE, HANDLER and AFTER. Without optional arguments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 this is just like process-send-string. If STRING is not a string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 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
665 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
666 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
667 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
668 the inferior will be interrupted if possible, see comint-interrupt for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 more information. Once the send is sent, the process status will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 STATUS or 'run. Output of the send will be inserted into the process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 buffer unless NO-INSERT. This function returns a list of \(result .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 prompt). If WAIT is a string, output will be inserted until one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 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
674 the prompt when finished and RESULT will have the output. If PROMPT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 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
676 returned will change when the send has been sent and is finished. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 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
678 will be ignored. When a send is finished, it calls handler with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 \(error-p WAIT MESSAGE output prompt) which decides what to do with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 the output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 VARIABLES:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 comint-always-scroll will cause all process output to be visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 comint-fix-error is the string used to fix errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 comint-continue is the string used to continue after an interrupt.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 comint-interrupt-regexp is the default regexp to use in finding the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 start of the interrupt text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 comint-error-regexp will set comint-errorp if found in the process output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 FUNCTIONS: Each of the functions in these variables is called with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 the buffer set to the appropriate process buffer and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 comint-original-buffer bound to the buffer current when the process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 filter was called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 comint-update-status is a function \(status) that is called each time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 the process status changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 comint-prompt-status is called with the old prompt and the last line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 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
705 prompt and nil otherwise. It should also update the process status by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 funcalling comint-update-status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 comint-output-filter is a function \(output) for sends with NO-INSERT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 It should return the output string.
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-interrupt-start is a function \(output) that returns the start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 of the interrupt text in output using comint-interrupt-regexp to find it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (set-buffer (process-buffer process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (let* ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (send (list string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 no-insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 wait
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (or status 'run)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (if (eq handler t) nil (or handler comint-handler))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 ;; running, old-prompt, line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 nil nil 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 ;; (output . prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (cons nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (pointer (comint-send-results send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (top-level (eq comint-send-queue comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (end (car comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (current (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (prompt (cdr (comint-send-results current)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (ok nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (setq comint-aborting nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (if (and top-level (or (stringp wait) prompt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (setq comint-send-queue (cons send comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (comint-dispatch-send process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (if (or (and wait (not after) (not prompt)) top-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (comint-interrupt process send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (let ((looking t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (next comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (if after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (while (and looking next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (if (eq (car next) comint-last-send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (rplacd next (cons send (cdr next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (setq looking nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (setq next (cdr next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (if looking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (rplaca comint-end-queue send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (setq comint-end-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (rplacd comint-end-queue (cons end nil))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (setq comint-last-send send)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (let ((inhibit-quit nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (if (eq wait t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (while (not (cdr pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (accept-process-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (sit-for 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (setq ok pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (if (not ok)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (if (eq send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (let ((interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 ;; string no-insert wait status message handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (list nil t nil 'interrupt "Interrupt" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 ;; running old-prompt line (output . prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 send (car (cdr (comint-send-variables send)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 nil (cons nil nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (cons interrupt (cdr comint-send-queue)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (comint-interrupt-subjob))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (setq comint-send-queue (delq send comint-send-queue))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (defun comint-send-code (process code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 "Execute after the previous send in PROCESS queue CODE. You do not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 want to execute synchronous sends in the code or it will lock up. "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (comint-send process code nil nil nil nil nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (defun comint-default-send (process string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 "Send to PROCESS top-level, STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (set-buffer (process-buffer process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (let* ((top (car comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (old (car top)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (rplaca (cdr (cdr (cdr (cdr (car comint-end-queue))))) string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (if (eq comint-send-queue comint-end-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 (progn (funcall comint-update-status 'run)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (rplaca (comint-send-variables (car comint-send-queue)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (rplacd (comint-send-results (car comint-send-queue)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (comint-sender process string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (rplaca top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (if old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (concat old (if comint-send-newline "\n") string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 string))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (defun comint-sync (process start start-regexp end end-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 "Synchronize with PROCESS output stream. START will be sent with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 each prompt received until START-REGEXP shows up in the stream. Then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 END will be sent and all output will be discarded until END-REGEXP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 shows up in the output stream."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (comint-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 nil start-regexp 'sync "Start sync"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (function (lambda (error-p wait message output prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 (if (not (string-match wait output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (comint-sender
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (get-buffer-process (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (car (car comint-send-queue))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (comint-send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 t end-regexp 'sync "End sync"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (function (lambda (&rest args) nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (defun comint-abort-sends (&optional process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 "Abort all of the pending sends for optional PROCESS and show their
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 messages in *Aborted Commands*."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (setq process (or process (get-buffer-process (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (set-buffer (process-buffer process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (setq comint-aborting t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (if (not (eq comint-send-queue comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (let* ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (send (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (vars (comint-send-variables send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (pointer comint-send-queue)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (new nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (interrupt (and (car vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (not (cdr (comint-send-results send))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (if interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (progn ;Sent, but no prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (if (consp (car vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (progn (setq new (list send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (rplaca (cdr (cdr (cdr (cdr (cdr send)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (function (lambda (&rest args) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (setq new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (list nil t nil 'interrupt "Interrupt"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (function (lambda (&rest args) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 send (car (cdr (comint-send-variables send)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 nil (cons nil nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (comint-interrupt-subjob)))) ;Already interrupting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (set-buffer (get-buffer-create "*Aborted Commands*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (delete-region (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (while (not (eq pointer comint-end-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (let ((send (car pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (if (car (cdr (cdr (cdr (cdr send))))) ;Message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (set-buffer "*Aborted Commands*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (insert (comint-send-description send))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (insert "\n\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (if (and comint-fix-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (stringp (car (comint-send-variables send))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 ;; Interrupted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (setq new (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (list comint-fix-error t nil 'fix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 "Fixing error" nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 nil nil 0 (cons nil nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (setq pointer (cdr pointer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (bury-buffer "*Aborted Commands*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (rplaca (car comint-end-queue) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (setq comint-send-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (reverse (cons (car comint-end-queue) new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 comint-end-queue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (let ((pointer comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (while (cdr pointer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (setq pointer (cdr pointer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (run-hooks 'comint-abort-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (if (not interrupt) (comint-dispatch-send process))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (defun comint-current-send (showp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 "Show the message of the current send in the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (if showp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (with-output-to-temp-buffer comint-output-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (let ((send comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (set-buffer comint-output-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (insert "Pending commands:\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (while send
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (let ((message (car (cdr (cdr (cdr (cdr (car send))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (if message (insert (concat message "\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (setq send (cdr send)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (concat "Command: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (or (comint-send-description (car comint-send-queue))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 "Unknown"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (defun comint-display-output (text &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 "Put TEXT in optional BUFFER and show it in a small temporary window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (setq buffer (or buffer comint-output-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (with-output-to-temp-buffer buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (insert text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (set-buffer-modified-p nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 ;; Perhaps this should use ilisp-display-output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (defun comint-display-error (text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 "Put TEXT in the comint-error-buffer and display it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (comint-display-output text comint-error-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (provide 'comint-ipc)