Mercurial > emacs
annotate lisp/comint.el @ 901:38d1af64858c
*** empty log message ***
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Fri, 31 Jul 1992 00:08:13 +0000 |
parents | 1b3af6ad85be |
children | 4c6cdb66c74c |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
1 ;;; comint.el --- general command interpreter in a window stuff |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
2 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
3 ;;; Copyright Olin Shivers (1988). |
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
811
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
5 ;; Maintainer: Olin Shivers <shivers@cs.cmu.edu> |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
6 ;; Version: 2.03 |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
7 ;; Keyword: estensions, processes |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
8 |
114 | 9 ;;; This file is part of GNU Emacs. |
10 | |
11 ;;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
13 ;;; the Free Software Foundation; either version 2, or (at your option) |
114 | 14 ;;; any later version. |
15 | |
16 ;;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;;; GNU General Public License for more details. | |
20 | |
21 ;;; You should have received a copy of the GNU General Public License | |
22 ;;; along with GNU Emacs; see the file COPYING. If not, write to | |
23 ;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
25 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
26 |
584 | 27 ;;; The changelog is at the end of this file. |
28 | |
29 ;;; Please send me bug reports, bug fixes, and extensions, so that I can | |
30 ;;; merge them into the master source. | |
31 ;;; - Olin Shivers (shivers@cs.cmu.edu) | |
32 | |
114 | 33 ;;; This file defines a general command-interpreter-in-a-buffer package |
34 ;;; (comint mode). The idea is that you can build specific process-in-a-buffer | |
35 ;;; modes on top of comint mode -- e.g., lisp, shell, scheme, T, soar, .... | |
36 ;;; This way, all these specific packages share a common base functionality, | |
37 ;;; and a common set of bindings, which makes them easier to use (and | |
38 ;;; saves code, implementation time, etc., etc.). | |
39 | |
584 | 40 ;;; Several packages are already defined using comint mode: |
41 ;;; - cmushell.el defines a shell-in-a-buffer mode. | |
42 ;;; - cmulisp.el defines a simple lisp-in-a-buffer mode. | |
43 ;;; Cmushell and cmulisp mode are similar to, and intended to replace, | |
44 ;;; their counterparts in the standard gnu emacs release (in shell.el). | |
45 ;;; These replacements are more featureful, robust, and uniform than the | |
46 ;;; released versions. The key bindings in lisp mode are also more compatible | |
47 ;;; with the bindings of Hemlock and Zwei (the Lisp Machine emacs). | |
48 ;;; | |
49 ;;; - The file cmuscheme.el defines a scheme-in-a-buffer mode. | |
50 ;;; - The file tea.el tunes scheme and inferior-scheme modes for T. | |
51 ;;; - The file soar.el tunes lisp and inferior-lisp modes for Soar. | |
52 ;;; - cmutex.el defines tex and latex modes that invoke tex, latex, bibtex, | |
53 ;;; previewers, and printers from within emacs. | |
54 ;;; - background.el allows csh-like job control inside emacs. | |
55 ;;; It is pretty easy to make new derived modes for other processes. | |
56 | |
114 | 57 ;;; For documentation on the functionality provided by comint mode, and |
58 ;;; the hooks available for customising it, see the comments below. | |
59 ;;; For further information on the standard derived modes (shell, | |
60 ;;; inferior-lisp, inferior-scheme, ...), see the relevant source files. | |
61 | |
584 | 62 ;;; For hints on converting existing process modes (e.g., tex-mode, |
63 ;;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode | |
114 | 64 ;;; instead of shell-mode, see the notes at the end of this file. |
65 | |
66 | |
584 | 67 ;;; Brief Command Documentation: |
68 ;;;============================================================================ | |
69 ;;; Comint Mode Commands: (common to all derived modes, like cmushell & cmulisp | |
70 ;;; mode) | |
71 ;;; | |
72 ;;; m-p comint-previous-input Cycle backwards in input history | |
73 ;;; m-n comint-next-input Cycle forwards | |
74 ;;; m-s comint-previous-similar-input Previous similar input | |
705 | 75 ;;; c-m-r comint-previous-input-matching Search backwards in input history |
584 | 76 ;;; return comint-send-input |
77 ;;; c-a comint-bol Beginning of line; skip prompt. | |
78 ;;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff. | |
79 ;;; c-c c-u comint-kill-input ^u | |
80 ;;; c-c c-w backward-kill-word ^w | |
81 ;;; c-c c-c comint-interrupt-subjob ^c | |
82 ;;; c-c c-z comint-stop-subjob ^z | |
83 ;;; c-c c-\ comint-quit-subjob ^\ | |
84 ;;; c-c c-o comint-kill-output Delete last batch of process output | |
85 ;;; c-c c-r comint-show-output Show last batch of process output | |
86 ;;; | |
114 | 87 ;;; Not bound by default in comint-mode |
88 ;;; send-invisible Read a line w/o echo, and send to proc | |
89 ;;; (These are bound in shell-mode) | |
90 ;;; comint-dynamic-complete Complete filename at point. | |
91 ;;; comint-dynamic-list-completions List completions in help buffer. | |
92 ;;; comint-replace-by-expanded-filename Expand and complete filename at point; | |
93 ;;; replace with expanded/completed name. | |
584 | 94 ;;; comint-kill-subjob No mercy. |
95 ;;; comint-continue-subjob Send CONT signal to buffer's process | |
96 ;;; group. Useful if you accidentally | |
97 ;;; suspend your process (with C-c C-z). | |
98 ;;; | |
99 ;;; These used to be bound for RMS -- I prefer the input history stuff, | |
100 ;;; but you might like 'em. | |
101 ;;; m-P comint-msearch-input Search backwards for prompt | |
102 ;;; m-N comint-psearch-input Search forwards for prompt | |
103 ;;; C-cR comint-msearch-input-matching Search backwards for prompt & string | |
114 | 104 |
584 | 105 ;;; comint-mode-hook is the comint mode hook. Basically for your keybindings. |
106 ;;; comint-load-hook is run after loading in this package. | |
107 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
108 ;;; Code: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
109 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
110 (defconst comint-version "2.03") |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
793
diff
changeset
|
111 |
114 | 112 |
113 ;;; Buffer Local Variables: | |
114 ;;;============================================================================ | |
115 ;;; Comint mode buffer local variables: | |
116 ;;; comint-prompt-regexp - string comint-bol uses to match prompt. | |
705 | 117 ;;; comint-last-input-start - marker Handy if inferior always echos |
584 | 118 ;;; comint-last-input-end - marker For comint-kill-output command |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
119 ;;; comint-input-ring-size - integer For the input history |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
120 ;;; comint-input-ring - ring mechanism |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
121 ;;; comint-input-ring-index - marker ... |
114 | 122 ;;; comint-last-input-match - string ... |
123 ;;; comint-get-old-input - function Hooks for specific | |
124 ;;; comint-input-sentinel - function process-in-a-buffer | |
125 ;;; comint-input-filter - function modes. | |
126 ;;; comint-input-send - function | |
127 ;;; comint-eol-on-send - boolean | |
128 | |
584 | 129 (defvar comint-prompt-regexp "^" |
130 "Regexp to recognise prompts in the inferior process. | |
131 Defaults to \"^\", the null string at BOL. | |
114 | 132 |
133 Good choices: | |
584 | 134 Canonical Lisp: \"^[^> ]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp) |
114 | 135 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\" |
584 | 136 franz: \"^\\(->\\|<[0-9]*>:\\) *\" |
137 kcl: \"^>+ *\" | |
138 shell: \"^[^#$%>]*[#$%>] *\" | |
139 T: \"^>+ *\" | |
114 | 140 |
584 | 141 This is a good thing to set in mode hooks.") |
114 | 142 |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
143 (defvar comint-input-ring-size 30 |
584 | 144 "Size of input history ring.") |
114 | 145 |
146 ;;; Here are the per-interpreter hooks. | |
584 | 147 (defvar comint-get-old-input (function comint-get-old-input-default) |
148 "Function that submits old text in comint mode. | |
114 | 149 This function is called when return is typed while the point is in old text. |
150 It returns the text to be submitted as process input. The default is | |
151 comint-get-old-input-default, which grabs the current line, and strips off | |
584 | 152 leading text matching comint-prompt-regexp") |
114 | 153 |
584 | 154 (defvar comint-input-sentinel (function ignore) |
155 "Called on each input submitted to comint mode process by comint-send-input. | |
156 Thus it can, for instance, track cd/pushd/popd commands issued to the csh.") | |
114 | 157 |
584 | 158 (defvar comint-input-filter |
159 (function (lambda (str) (not (string-match "\\`\\s *\\'" str)))) | |
160 "Predicate for filtering additions to input history. | |
114 | 161 Only inputs answering true to this function are saved on the input |
584 | 162 history list. Default is to save anything that isn't all whitespace") |
163 | |
164 (defvar comint-input-sender (function comint-simple-send) | |
165 "Function to actually send to PROCESS the STRING submitted by user. | |
166 Usually this is just 'comint-simple-send, but if your mode needs to | |
167 massage the input string, this is your hook. This is called from | |
168 the user command comint-send-input. comint-simple-send just sends | |
169 the string plus a newline.") | |
170 | |
171 (defvar comint-eol-on-send 'T | |
172 "If non-nil, then jump to the end of the line before sending input to process. | |
173 See comint-send-input") | |
114 | 174 |
175 (defvar comint-mode-hook '() | |
584 | 176 "Called upon entry into comint-mode |
177 This is run before the process is cranked up.") | |
178 | |
179 (defvar comint-exec-hook '() | |
180 "Called each time a process is exec'd by comint-exec. | |
181 This is called after the process is cranked up. It is useful for things that | |
182 must be done each time a process is executed in a comint-mode buffer (e.g., | |
183 (process-kill-without-query)). In contrast, the comint-mode-hook is only | |
184 executed once when the buffer is created.") | |
185 | |
186 (defvar comint-mode-map nil) | |
114 | 187 |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
188 (defvar comint-last-input-start) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
189 (defvar comint-last-input-end) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
190 |
114 | 191 (defun comint-mode () |
192 "Major mode for interacting with an inferior interpreter. | |
193 Interpreter name is same as buffer name, sans the asterisks. | |
194 Return at end of buffer sends line as input. | |
195 Return not at end copies rest of line to end and sends it. | |
584 | 196 Setting mode variable comint-eol-on-send means jump to the end of the line |
197 before submitting new input. | |
114 | 198 |
199 This mode is typically customised to create inferior-lisp-mode, | |
584 | 200 shell-mode, etc.. This can be done by setting the hooks |
201 comint-input-sentinel, comint-input-filter, comint-input-sender and | |
202 comint-get-old-input to appropriate functions, and the variable | |
203 comint-prompt-regexp to the appropriate regular expression. | |
114 | 204 |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
205 An input history is maintained of size comint-input-ring-size, and |
114 | 206 can be accessed with the commands comint-next-input [\\[comint-next-input]] and |
207 comint-previous-input [\\[comint-previous-input]]. Commands not keybound by | |
208 default are send-invisible, comint-dynamic-complete, and | |
209 comint-list-dynamic-completions. | |
210 | |
211 If you accidentally suspend your process, use \\[comint-continue-subjob] | |
212 to continue it. | |
213 | |
214 \\{comint-mode-map} | |
215 | |
584 | 216 Entry to this mode runs the hooks on comint-mode-hook" |
114 | 217 (interactive) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
218 (let ((old-ring (and (assq 'comint-input-ring (buffer-local-variables)) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
219 (boundp 'comint-input-ring) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
220 comint-input-ring)) |
584 | 221 (old-ptyp comint-ptyp)) ; preserve across local var kill. gross. |
222 ; (kill-all-local-variables) ; Removed 1/15/90 Olin | |
223 (setq major-mode 'comint-mode) | |
224 (setq mode-name "Comint") | |
225 (setq mode-line-process '(": %s")) | |
226 (use-local-map comint-mode-map) | |
705 | 227 (make-local-variable 'comint-last-input-start) |
228 (setq comint-last-input-start (make-marker)) | |
584 | 229 (make-local-variable 'comint-last-input-end) |
230 (setq comint-last-input-end (make-marker)) | |
231 (make-local-variable 'comint-last-input-match) | |
232 (setq comint-last-input-match "") | |
233 (make-local-variable 'comint-prompt-regexp) ; Don't set; default | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
234 (make-local-variable 'comint-input-ring-size) ; ...to global val. |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
235 (make-local-variable 'comint-input-ring) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
236 (make-local-variable 'comint-input-ring-index) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
237 (setq comint-input-ring-index 0) |
584 | 238 (make-local-variable 'comint-get-old-input) |
239 (make-local-variable 'comint-input-sentinel) | |
240 (make-local-variable 'comint-input-filter) | |
241 (make-local-variable 'comint-input-sender) | |
242 (make-local-variable 'comint-eol-on-send) | |
243 (make-local-variable 'comint-ptyp) | |
244 (setq comint-ptyp old-ptyp) | |
705 | 245 (make-local-variable 'comint-exec-hook) |
584 | 246 (run-hooks 'comint-mode-hook) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
247 ;Do this after the hook so the user can mung COMINT-INPUT-RING-SIZE w/his hook. |
584 | 248 ;The test is so we don't lose history if we run comint-mode twice in |
249 ;a buffer. | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
250 (setq comint-input-ring (if (ring-p old-ring) old-ring |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
251 (make-ring comint-input-ring-size))))) |
584 | 252 |
253 ;;; The old-ptyp stuff above is because we have to preserve the value of | |
254 ;;; comint-ptyp across calls to comint-mode, in spite of the | |
255 ;;; kill-all-local-variables that it does. Blech. Hopefully, this will all | |
256 ;;; go away when a later release fixes the signalling bug. | |
257 ;;; (Later: I removed the kill-all-local-variables, but have left this | |
258 ;;; other code in place just in case I reverse myself.) | |
114 | 259 |
584 | 260 (if comint-mode-map |
261 nil | |
262 (setq comint-mode-map (make-sparse-keymap)) | |
263 (define-key comint-mode-map "\ep" 'comint-previous-input) | |
264 (define-key comint-mode-map "\en" 'comint-next-input) | |
265 (define-key comint-mode-map "\es" 'comint-previous-similar-input) | |
266 (define-key comint-mode-map "\C-m" 'comint-send-input) | |
267 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof) | |
268 (define-key comint-mode-map "\C-a" 'comint-bol) | |
269 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input) | |
270 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word) | |
271 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob) | |
272 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob) | |
273 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob) | |
274 (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output) | |
275 (define-key comint-mode-map "\C-\M-r" 'comint-previous-input-matching) | |
276 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output) | |
277 ;;; prompt-search commands commented out 3/90 -Olin | |
278 ; (define-key comint-mode-map "\eP" 'comint-msearch-input) | |
279 ; (define-key comint-mode-map "\eN" 'comint-psearch-input) | |
280 ; (define-key comint-mode-map "\C-cR" 'comint-msearch-input-matching) | |
281 ) | |
282 | |
283 | |
284 ;;; This function is used to make a full copy of the comint mode map, | |
285 ;;; so that client modes won't interfere with each other. This function | |
286 ;;; isn't necessary in emacs 18.5x, but we keep it around for 18.4x versions. | |
287 (defun full-copy-sparse-keymap (km) | |
288 "Recursively copy the sparse keymap KM" | |
289 (cond ((consp km) | |
290 (cons (full-copy-sparse-keymap (car km)) | |
291 (full-copy-sparse-keymap (cdr km)))) | |
292 (t km))) | |
293 | |
294 (defun comint-check-proc (buffer) | |
295 "True if there is a process associated w/buffer BUFFER, and | |
296 it is alive (status RUN or STOP). BUFFER can be either a buffer or the | |
297 name of one" | |
298 (let ((proc (get-buffer-process buffer))) | |
114 | 299 (and proc (memq (process-status proc) '(run stop))))) |
300 | |
301 ;;; Note that this guy, unlike shell.el's make-shell, barfs if you pass it () | |
302 ;;; for the second argument (program). | |
870
1b3af6ad85be
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
864
diff
changeset
|
303 ;;;###autoload |
114 | 304 (defun make-comint (name program &optional startfile &rest switches) |
584 | 305 (let ((buffer (get-buffer-create (concat "*" name "*")))) |
114 | 306 ;; If no process, or nuked process, crank up a new one and put buffer in |
307 ;; comint mode. Otherwise, leave buffer and existing process alone. | |
182 | 308 (cond ((not (comint-check-proc buffer)) |
584 | 309 (save-excursion |
114 | 310 (set-buffer buffer) |
311 (comint-mode)) ; Install local vars, mode, keymap, ... | |
312 (comint-exec buffer name program startfile switches))) | |
313 buffer)) | |
314 | |
584 | 315 (defvar comint-ptyp t |
316 "True if communications via pty; false if by pipe. Buffer local. | |
317 This is to work around a bug in emacs process signalling.") | |
318 | |
114 | 319 (defun comint-exec (buffer name command startfile switches) |
320 "Fires up a process in buffer for comint modes. | |
584 | 321 Blasts any old process running in the buffer. Doesn't set the buffer mode. |
322 You can use this to cheaply run a series of processes in the same comint | |
323 buffer. The hook comint-exec-hook is run after each exec." | |
114 | 324 (save-excursion |
325 (set-buffer buffer) | |
326 (let ((proc (get-buffer-process buffer))) ; Blast any old process. | |
327 (if proc (delete-process proc))) | |
328 ;; Crank up a new process | |
329 (let ((proc (comint-exec-1 name buffer command switches))) | |
584 | 330 (make-local-variable 'comint-ptyp) |
331 (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe. | |
114 | 332 ;; Jump to the end, and set the process mark. |
584 | 333 (goto-char (point-max)) |
705 | 334 (set-marker (process-mark proc) (point)) |
114 | 335 ;; Feed it the startfile. |
336 (cond (startfile | |
337 ;;This is guaranteed to wait long enough | |
338 ;;but has bad results if the comint does not prompt at all | |
339 ;; (while (= size (buffer-size)) | |
340 ;; (sleep-for 1)) | |
341 ;;I hope 1 second is enough! | |
342 (sleep-for 1) | |
343 (goto-char (point-max)) | |
344 (insert-file-contents startfile) | |
345 (setq startfile (buffer-substring (point) (point-max))) | |
346 (delete-region (point) (point-max)) | |
584 | 347 (comint-send-string proc startfile))) |
348 (run-hooks 'comint-exec-hook) | |
705 | 349 buffer))) |
114 | 350 |
351 ;;; This auxiliary function cranks up the process for comint-exec in | |
638 | 352 ;;; the appropriate environment. |
114 | 353 |
354 (defun comint-exec-1 (name buffer command switches) | |
638 | 355 (let ((process-environment |
356 (comint-update-env process-environment | |
357 (list (format "TERMCAP=emacs:co#%d:tc=unknown" | |
778 | 358 (frame-width)) |
638 | 359 "TERM=emacs" |
360 "EMACS=t")))) | |
361 (apply 'start-process name buffer command switches))) | |
584 | 362 |
363 | |
114 | 364 |
365 ;; This is just (append new old-env) that compresses out shadowed entries. | |
793
6fb68a1460a6
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
366 ;; It's also pretty ugly, mostly due to lisp's horrible iteration structures. |
114 | 367 (defun comint-update-env (old-env new) |
368 (let ((ans (reverse new)) | |
369 (vars (mapcar (function (lambda (vv) | |
370 (and (string-match "^[^=]*=" vv) | |
371 (substring vv 0 (match-end 0))))) | |
372 new))) | |
373 (while old-env | |
374 (let* ((vv (car old-env)) ; vv is var=value | |
375 (var (and (string-match "^[^=]*=" vv) | |
376 (substring vv 0 (match-end 0))))) | |
377 (setq old-env (cdr old-env)) | |
584 | 378 (cond ((not (and var (comint-mem var vars))) |
114 | 379 (if var (setq var (cons var vars))) |
380 (setq ans (cons vv ans)))))) | |
381 (nreverse ans))) | |
584 | 382 |
383 ;;; This should be in emacs, but it isn't. | |
384 (defun comint-mem (item list &optional elt=) | |
385 "Test to see if ITEM is equal to an item in LIST. | |
386 Option comparison function ELT= defaults to equal." | |
387 (let ((elt= (or elt= (function equal))) | |
388 (done nil)) | |
389 (while (and list (not done)) | |
390 (if (funcall elt= item (car list)) | |
391 (setq done list) | |
392 (setq list (cdr list)))) | |
393 done)) | |
394 | |
114 | 395 |
584 | 396 ;;; Ring Code |
397 ;;;============================================================================ | |
398 ;;; This code defines a ring data structure. A ring is a | |
399 ;;; (hd-index tl-index . vector) | |
400 ;;; list. You can insert to, remove from, and rotate a ring. When the ring | |
401 ;;; fills up, insertions cause the oldest elts to be quietly dropped. | |
402 ;;; | |
403 ;;; HEAD = index of the newest item on the ring. | |
404 ;;; TAIL = index of the oldest item on the ring. | |
405 ;;; | |
406 ;;; These functions are used by the input history mechanism, but they can | |
407 ;;; be used for other purposes as well. | |
408 | |
409 (defun ring-p (x) | |
410 "T if X is a ring; NIL otherwise." | |
411 (and (consp x) (integerp (car x)) | |
412 (consp (cdr x)) (integerp (car (cdr x))) | |
413 (vectorp (cdr (cdr x))))) | |
414 | |
415 (defun make-ring (size) | |
416 "Make a ring that can contain SIZE elts" | |
417 (cons 1 (cons 0 (make-vector (+ size 1) nil)))) | |
418 | |
419 (defun ring-plus1 (index veclen) | |
420 "INDEX+1, with wraparound" | |
421 (let ((new-index (+ index 1))) | |
422 (if (= new-index veclen) 0 new-index))) | |
423 | |
424 (defun ring-minus1 (index veclen) | |
425 "INDEX-1, with wraparound" | |
426 (- (if (= 0 index) veclen index) 1)) | |
427 | |
428 (defun ring-length (ring) | |
429 "Number of elts in the ring." | |
430 (let ((hd (car ring)) (tl (car (cdr ring))) (siz (length (cdr (cdr ring))))) | |
431 (let ((len (if (<= hd tl) (+ 1 (- tl hd)) (+ 1 tl (- siz hd))))) | |
432 (if (= len siz) 0 len)))) | |
433 | |
434 (defun ring-empty-p (ring) | |
435 (= 0 (ring-length ring))) | |
436 | |
437 (defun ring-insert (ring item) | |
438 "Insert a new item onto the ring. If the ring is full, dump the oldest | |
439 item to make room." | |
440 (let* ((vec (cdr (cdr ring))) (len (length vec)) | |
441 (new-hd (ring-minus1 (car ring) len))) | |
442 (setcar ring new-hd) | |
443 (aset vec new-hd item) | |
444 (if (ring-empty-p ring) ;overflow -- dump one off the tail. | |
445 (setcar (cdr ring) (ring-minus1 (car (cdr ring)) len))))) | |
446 | |
447 (defun ring-remove (ring) | |
448 "Remove the oldest item retained on the ring." | |
449 (if (ring-empty-p ring) (error "Ring empty") | |
450 (let ((tl (car (cdr ring))) (vec (cdr (cdr ring)))) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
451 (setcar (cdr ring) (ring-minus1 tl (length vec))) |
584 | 452 (aref vec tl)))) |
453 | |
454 ;;; This isn't actually used in this package. I just threw it in in case | |
455 ;;; someone else wanted it. If you want rotating-ring behavior on your history | |
456 ;;; retrieval (analagous to kill ring behavior), this function is what you | |
457 ;;; need. I should write the yank-input and yank-pop-input-or-kill to go with | |
458 ;;; this, and not bind it to a key by default, so it would be available to | |
459 ;;; people who want to bind it to a key. But who would want it? Blech. | |
460 (defun ring-rotate (ring n) | |
461 (if (not (= n 0)) | |
462 (if (ring-empty-p ring) ;Is this the right error check? | |
463 (error "ring empty") | |
464 (let ((hd (car ring)) (tl (car (cdr ring))) (vec (cdr (cdr ring)))) | |
465 (let ((len (length vec))) | |
466 (while (> n 0) | |
467 (setq tl (ring-plus1 tl len)) | |
468 (aset ring tl (aref ring hd)) | |
469 (setq hd (ring-plus1 hd len)) | |
470 (setq n (- n 1))) | |
471 (while (< n 0) | |
472 (setq hd (ring-minus1 hd len)) | |
473 (aset vec hd (aref vec tl)) | |
474 (setq tl (ring-minus1 tl len)) | |
475 (setq n (- n 1)))) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
476 (setcar ring hd) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
477 (setcar (cdr ring) tl))))) |
584 | 478 |
479 (defun comint-mod (n m) | |
480 "Returns N mod M. M is positive. Answer is guaranteed to be non-negative, | |
481 and less than m." | |
482 (let ((n (% n m))) | |
483 (if (>= n 0) n | |
484 (+ n | |
485 (if (>= m 0) m (- m)))))) ; (abs m) | |
486 | |
487 (defun ring-ref (ring index) | |
488 (let ((numelts (ring-length ring))) | |
489 (if (= numelts 0) (error "indexed empty ring") | |
490 (let* ((hd (car ring)) (tl (car (cdr ring))) (vec (cdr (cdr ring))) | |
491 (index (comint-mod index numelts)) | |
492 (vec-index (comint-mod (+ index hd) | |
493 (length vec)))) | |
494 (aref vec vec-index))))) | |
495 | |
496 | |
114 | 497 ;;; Input history retrieval commands |
498 ;;; M-p -- previous input M-n -- next input | |
584 | 499 ;;; M-C-r -- previous input matching |
114 | 500 ;;; =========================================================================== |
501 | |
502 (defun comint-previous-input (arg) | |
503 "Cycle backwards through input history." | |
504 (interactive "*p") | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
505 (let ((len (ring-length comint-input-ring))) |
584 | 506 (cond ((<= len 0) |
507 (message "Empty input ring") | |
508 (ding)) | |
509 ((not (comint-after-pmark-p)) | |
510 (message "Not after process mark") | |
511 (ding)) | |
512 (t | |
513 (cond ((eq last-command 'comint-previous-input) | |
514 (delete-region (mark) (point))) | |
515 ((eq last-command 'comint-previous-similar-input) | |
516 (delete-region | |
517 (process-mark (get-buffer-process (current-buffer))) | |
518 (point))) | |
519 (t | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
520 (setq comint-input-ring-index |
584 | 521 (if (> arg 0) -1 |
522 (if (< arg 0) 1 0))) | |
523 (push-mark (point)))) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
524 (setq comint-input-ring-index (comint-mod (+ comint-input-ring-index arg) len)) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
525 (message "%d" (1+ comint-input-ring-index)) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
526 (insert (ring-ref comint-input-ring comint-input-ring-index)) |
584 | 527 (setq this-command 'comint-previous-input))))) |
528 | |
114 | 529 (defun comint-next-input (arg) |
530 "Cycle forwards through input history." | |
531 (interactive "*p") | |
532 (comint-previous-input (- arg))) | |
533 | |
584 | 534 (defvar comint-last-input-match "" |
535 "Last string searched for by comint input history search, for defaulting. | |
536 Buffer local variable.") | |
537 | |
114 | 538 (defun comint-previous-input-matching (str) |
539 "Searches backwards through input history for substring match." | |
540 (interactive (let* ((last-command last-command) ; preserve around r-f-m | |
541 (s (read-from-minibuffer | |
864
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
542 (format "Command substring (default %s): " |
fe5f6b7c9727
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
543 comint-last-input-match)))) |
114 | 544 (list (if (string= s "") comint-last-input-match s)))) |
545 ; (interactive "sCommand substring: ") | |
546 (setq comint-last-input-match str) ; update default | |
547 (if (not (eq last-command 'comint-previous-input)) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
548 (setq comint-input-ring-index -1)) |
114 | 549 (let ((str (regexp-quote str)) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
550 (len (ring-length comint-input-ring)) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
551 (n (+ comint-input-ring-index 1))) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
552 (while (and (< n len) (not (string-match str (ring-ref comint-input-ring n)))) |
114 | 553 (setq n (+ n 1))) |
554 (cond ((< n len) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
555 (comint-previous-input (- n comint-input-ring-index))) |
114 | 556 (t (if (eq last-command 'comint-previous-input) |
557 (setq this-command 'comint-previous-input)) | |
584 | 558 (message "Not found.") |
559 (ding))))) | |
560 | |
561 | |
562 ;;; These next three commands are alternatives to the input history commands | |
563 ;;; -- comint-next-input, comint-previous-input and | |
564 ;;; comint-previous-input-matching. They search through the process buffer | |
565 ;;; text looking for occurrences of the prompt. Bound to M-P, M-N, and C-c R | |
566 ;;; (uppercase P, N, and R) for now. Try'em out. Go with what you like... | |
567 | |
568 ;;; comint-msearch-input-matching prompts for a string, not a regexp. | |
569 ;;; This could be considered to be the wrong thing. I decided to keep it | |
570 ;;; simple, and not make the user worry about regexps. This, of course, | |
571 ;;; limits functionality. | |
572 | |
573 ;;; These commands were deemed non-winning and have been commented out. | |
574 ;;; Feel free to re-enable them if you like. -Olin 3/91 | |
575 | |
576 ;(defun comint-psearch-input () | |
577 ; "Search forwards for next occurrence of prompt and skip to end of line. | |
578 ;\(prompt is anything matching regexp comint-prompt-regexp)" | |
579 ; (interactive) | |
580 ; (if (re-search-forward comint-prompt-regexp (point-max) t) | |
581 ; (end-of-line) | |
582 ; (error "No occurrence of prompt found"))) | |
583 ; | |
584 ;(defun comint-msearch-input () | |
585 ; "Search backwards for previous occurrence of prompt and skip to end of line. | |
586 ;Search starts from beginning of current line." | |
587 ; (interactive) | |
588 ; (let ((p (save-excursion | |
589 ; (beginning-of-line) | |
590 ; (cond ((re-search-backward comint-prompt-regexp (point-min) t) | |
591 ; (end-of-line) | |
592 ; (point)) | |
593 ; (t nil))))) | |
594 ; (if p (goto-char p) | |
595 ; (error "No occurrence of prompt found")))) | |
596 ; | |
597 ;(defun comint-msearch-input-matching (str) | |
598 ; "Search backwards for occurrence of prompt followed by STRING. | |
599 ;STRING is prompted for, and is NOT a regular expression." | |
600 ; (interactive (let ((s (read-from-minibuffer | |
601 ; (format "Command (default %s): " | |
602 ; comint-last-input-match)))) | |
603 ; (list (if (string= s "") comint-last-input-match s)))) | |
604 ;; (interactive "sCommand: ") | |
605 ; (setq comint-last-input-match str) ; update default | |
606 ; (let* ((r (concat comint-prompt-regexp (regexp-quote str))) | |
607 ; (p (save-excursion | |
608 ; (beginning-of-line) | |
609 ; (cond ((re-search-backward r (point-min) t) | |
610 ; (end-of-line) | |
611 ; (point)) | |
612 ; (t nil))))) | |
613 ; (if p (goto-char p) | |
614 ; (error "No match")))) | |
114 | 615 |
616 ;;; | |
617 ;;; Similar input -- contributed by ccm and highly winning. | |
618 ;;; | |
619 ;;; Reenter input, removing back to the last insert point if it exists. | |
620 ;;; | |
584 | 621 (defvar comint-last-similar-string "" |
622 "The string last used in a similar string search.") | |
114 | 623 (defun comint-previous-similar-input (arg) |
624 "Reenters the last input that matches the string typed so far. If repeated | |
625 successively older inputs are reentered. If arg is 1, it will go back | |
626 in the history, if -1 it will go forward." | |
627 (interactive "p") | |
584 | 628 (if (not (comint-after-pmark-p)) |
114 | 629 (error "Not after process mark")) |
630 (if (not (eq last-command 'comint-previous-similar-input)) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
631 (setq comint-input-ring-index -1 |
584 | 632 comint-last-similar-string |
633 (buffer-substring | |
634 (process-mark (get-buffer-process (current-buffer))) | |
635 (point)))) | |
114 | 636 (let* ((size (length comint-last-similar-string)) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
637 (len (ring-length comint-input-ring)) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
638 (n (+ comint-input-ring-index arg)) |
114 | 639 entry) |
640 (while (and (< n len) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
641 (or (< (length (setq entry (ring-ref comint-input-ring n))) size) |
114 | 642 (not (equal comint-last-similar-string |
643 (substring entry 0 size))))) | |
644 (setq n (+ n arg))) | |
645 (cond ((< n len) | |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
646 (setq comint-input-ring-index n) |
114 | 647 (if (eq last-command 'comint-previous-similar-input) |
584 | 648 (delete-region (mark) (point)) ; repeat |
649 (push-mark (point))) ; 1st time | |
114 | 650 (insert (substring entry size))) |
584 | 651 (t (message "Not found.") (ding) (sit-for 1))) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
652 (message "%d" (1+ comint-input-ring-index)))) |
584 | 653 |
114 | 654 |
584 | 655 (defun comint-send-input () |
656 "Send input to process. After the process output mark, sends all text | |
657 from the process mark to point as input to the process. Before the process | |
658 output mark, calls value of variable comint-get-old-input to retrieve old | |
659 input, copies it to the process mark, and sends it. A terminal newline is | |
660 also inserted into the buffer and sent to the process. In either case, value | |
661 of variable comint-input-sentinel is called on the input before sending it. | |
662 The input is entered into the input history ring, if the value of variable | |
663 comint-input-filter returns non-nil when called on the input. | |
114 | 664 |
584 | 665 If variable comint-eol-on-send is non-nil, then point is moved to the end of |
666 line before sending the input. | |
114 | 667 |
668 comint-get-old-input, comint-input-sentinel, and comint-input-filter are chosen | |
584 | 669 according to the command interpreter running in the buffer. E.g., |
114 | 670 If the interpreter is the csh, |
584 | 671 comint-get-old-input is the default: take the current line, discard any |
672 initial string matching regexp comint-prompt-regexp. | |
673 comint-input-sentinel monitors input for \"cd\", \"pushd\", and \"popd\" | |
674 commands. When it sees one, it cd's the buffer. | |
675 comint-input-filter is the default: returns T if the input isn't all white | |
676 space. | |
114 | 677 |
678 If the comint is Lucid Common Lisp, | |
584 | 679 comint-get-old-input snarfs the sexp ending at point. |
680 comint-input-sentinel does nothing. | |
681 comint-input-filter returns NIL if the input matches input-filter-regexp, | |
114 | 682 which matches (1) all whitespace (2) :a, :c, etc. |
683 | |
584 | 684 Similarly for Soar, Scheme, etc.." |
114 | 685 (interactive) |
686 ;; Note that the input string does not include its terminal newline. | |
584 | 687 (let ((proc (get-buffer-process (current-buffer)))) |
688 (if (not proc) (error "Current buffer has no process") | |
689 (let* ((pmark (process-mark proc)) | |
690 (pmark-val (marker-position pmark)) | |
691 (input (if (>= (point) pmark-val) | |
692 (progn (if comint-eol-on-send (end-of-line)) | |
693 (buffer-substring pmark (point))) | |
705 | 694 (let ((copy (funcall comint-get-old-input))) |
695 (goto-char pmark) | |
696 (insert copy) | |
697 copy)))) | |
584 | 698 (insert ?\n) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
699 (if (funcall comint-input-filter input) |
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
700 (ring-insert comint-input-ring input)) |
584 | 701 (funcall comint-input-sentinel input) |
702 (funcall comint-input-sender proc input) | |
705 | 703 (set-marker comint-last-input-start pmark) |
704 (set-marker comint-last-input-end (point)) | |
705 (set-marker (process-mark proc) (point)))))) | |
114 | 706 |
707 (defun comint-get-old-input-default () | |
584 | 708 "Default for comint-get-old-input: take the current line, and discard |
709 any initial text matching comint-prompt-regexp." | |
114 | 710 (save-excursion |
584 | 711 (beginning-of-line) |
712 (comint-skip-prompt) | |
713 (let ((beg (point))) | |
714 (end-of-line) | |
715 (buffer-substring beg (point))))) | |
716 | |
717 (defun comint-skip-prompt () | |
718 "Skip past the text matching regexp comint-prompt-regexp. | |
719 If this takes us past the end of the current line, don't skip at all." | |
720 (let ((eol (save-excursion (end-of-line) (point)))) | |
721 (if (and (looking-at comint-prompt-regexp) | |
722 (<= (match-end 0) eol)) | |
723 (goto-char (match-end 0))))) | |
724 | |
725 | |
726 (defun comint-after-pmark-p () | |
727 "Is point after the process output marker?" | |
728 ;; Since output could come into the buffer after we looked at the point | |
729 ;; but before we looked at the process marker's value, we explicitly | |
730 ;; serialise. This is just because I don't know whether or not emacs | |
731 ;; services input during execution of lisp commands. | |
732 (let ((proc-pos (marker-position | |
733 (process-mark (get-buffer-process (current-buffer)))))) | |
734 (<= proc-pos (point)))) | |
735 | |
736 (defun comint-simple-send (proc string) | |
737 "Default function for sending to PROC input STRING. | |
738 This just sends STRING plus a newline. To override this, | |
739 set the hook COMINT-INPUT-SENDER." | |
740 (comint-send-string proc string) | |
741 (comint-send-string proc "\n")) | |
114 | 742 |
743 (defun comint-bol (arg) | |
744 "Goes to the beginning of line, then skips past the prompt, if any. | |
584 | 745 If a prefix argument is given (\\[universal-argument]), then no prompt skip |
746 -- go straight to column 0. | |
114 | 747 |
584 | 748 The prompt skip is done by skipping text matching the regular expression |
749 comint-prompt-regexp, a buffer local variable. | |
750 | |
751 If you don't like this command, reset c-a to beginning-of-line | |
752 in your hook, comint-mode-hook." | |
114 | 753 (interactive "P") |
754 (beginning-of-line) | |
584 | 755 (if (null arg) (comint-skip-prompt))) |
114 | 756 |
757 ;;; These two functions are for entering text you don't want echoed or | |
758 ;;; saved -- typically passwords to ftp, telnet, or somesuch. | |
584 | 759 ;;; Just enter m-x send-invisible and type in your line. |
760 | |
705 | 761 (defun comint-read-noecho (prompt &optional stars) |
584 | 762 "Prompt the user with argument PROMPT. Read a single line of text |
763 without echoing, and return it. Note that the keystrokes comprising | |
764 the text can still be recovered (temporarily) with \\[view-lossage]. This | |
705 | 765 may be a security bug for some applications. Optional argument STARS |
766 causes input to be echoed with '*' characters on the prompt line." | |
114 | 767 (let ((echo-keystrokes 0) |
705 | 768 (cursor-in-echo-area t) |
114 | 769 (answ "") |
770 tem) | |
705 | 771 (if (not (stringp prompt)) (setq prompt "")) |
772 (message prompt) | |
584 | 773 (while (not(or (= (setq tem (read-char)) ?\^m) |
114 | 774 (= tem ?\n))) |
705 | 775 (setq answ (concat answ (char-to-string tem))) |
776 (if stars (setq prompt (concat prompt "*"))) | |
777 (message prompt)) | |
114 | 778 (message "") |
779 answ)) | |
780 | |
705 | 781 |
114 | 782 (defun send-invisible (str) |
584 | 783 "Read a string without echoing, and send it to the process running |
784 in the current buffer. A new-line is additionally sent. String is not | |
785 saved on comint input history list. | |
786 Security bug: your string can still be temporarily recovered with | |
787 \\[view-lossage]." | |
114 | 788 ; (interactive (list (comint-read-noecho "Enter non-echoed text"))) |
789 (interactive "P") ; Defeat snooping via C-x esc | |
790 (let ((proc (get-buffer-process (current-buffer)))) | |
791 (if (not proc) (error "Current buffer has no process") | |
792 (comint-send-string proc | |
793 (if (stringp str) str | |
705 | 794 (comint-read-noecho "Non-echoed text: " t))) |
114 | 795 (comint-send-string proc "\n")))) |
796 | |
797 | |
798 ;;; Low-level process communication | |
799 | |
800 (defvar comint-input-chunk-size 512 | |
801 "*Long inputs send to comint processes are broken up into chunks of this size. | |
802 If your process is choking on big inputs, try lowering the value.") | |
803 | |
804 (defun comint-send-string (proc str) | |
805 "Send PROCESS the contents of STRING as input. | |
806 This is equivalent to process-send-string, except that long input strings | |
807 are broken up into chunks of size comint-input-chunk-size. Processes | |
808 are given a chance to output between chunks. This can help prevent processes | |
809 from hanging when you send them long inputs on some OS's." | |
810 (let* ((len (length str)) | |
811 (i (min len comint-input-chunk-size))) | |
812 (process-send-string proc (substring str 0 i)) | |
813 (while (< i len) | |
814 (let ((next-i (+ i comint-input-chunk-size))) | |
815 (accept-process-output) | |
816 (process-send-string proc (substring str i (min len next-i))) | |
817 (setq i next-i))))) | |
818 | |
819 (defun comint-send-region (proc start end) | |
820 "Sends to PROC the region delimited by START and END. | |
821 This is a replacement for process-send-region that tries to keep | |
822 your process from hanging on long inputs. See comint-send-string." | |
823 (comint-send-string proc (buffer-substring start end))) | |
824 | |
825 | |
826 ;;; Random input hackage | |
827 | |
584 | 828 (defun comint-kill-output () |
114 | 829 "Kill all output from interpreter since last input." |
830 (interactive) | |
584 | 831 (let ((pmark (process-mark (get-buffer-process (current-buffer))))) |
832 (kill-region comint-last-input-end pmark) | |
833 (goto-char pmark) | |
834 (insert "*** output flushed ***\n") | |
835 (set-marker pmark (point)))) | |
114 | 836 |
837 (defun comint-show-output () | |
584 | 838 "Display start of this batch of interpreter output at top of window. |
839 Also put cursor there." | |
114 | 840 (interactive) |
841 (goto-char comint-last-input-end) | |
584 | 842 (backward-char) |
114 | 843 (beginning-of-line) |
844 (set-window-start (selected-window) (point)) | |
584 | 845 (end-of-line)) |
114 | 846 |
847 (defun comint-interrupt-subjob () | |
584 | 848 "Interrupt the current subjob." |
114 | 849 (interactive) |
584 | 850 (interrupt-process nil comint-ptyp)) |
114 | 851 |
852 (defun comint-kill-subjob () | |
584 | 853 "Send kill signal to the current subjob." |
114 | 854 (interactive) |
584 | 855 (kill-process nil comint-ptyp)) |
114 | 856 |
857 (defun comint-quit-subjob () | |
584 | 858 "Send quit signal to the current subjob." |
114 | 859 (interactive) |
584 | 860 (quit-process nil comint-ptyp)) |
114 | 861 |
862 (defun comint-stop-subjob () | |
584 | 863 "Stop the current subjob. |
114 | 864 WARNING: if there is no current subjob, you can end up suspending |
584 | 865 the top-level process running in the buffer. If you accidentally do |
866 this, use \\[comint-continue-subjob] to resume the process. (This | |
867 is not a problem with most shells, since they ignore this signal.)" | |
114 | 868 (interactive) |
584 | 869 (stop-process nil comint-ptyp)) |
114 | 870 |
871 (defun comint-continue-subjob () | |
584 | 872 "Send CONT signal to process buffer's process group. |
114 | 873 Useful if you accidentally suspend the top-level process." |
874 (interactive) | |
584 | 875 (continue-process nil comint-ptyp)) |
114 | 876 |
877 (defun comint-kill-input () | |
584 | 878 "Kill all text from last stuff output by interpreter to point." |
114 | 879 (interactive) |
584 | 880 (let* ((pmark (process-mark (get-buffer-process (current-buffer)))) |
881 (p-pos (marker-position pmark))) | |
882 (if (> (point) p-pos) | |
883 (kill-region pmark (point))))) | |
114 | 884 |
885 (defun comint-delchar-or-maybe-eof (arg) | |
886 "Delete ARG characters forward, or send an EOF to process if at end of buffer." | |
887 (interactive "p") | |
888 (if (eobp) | |
889 (process-send-eof) | |
584 | 890 (delete-char arg))) |
891 | |
892 | |
893 | |
114 | 894 |
895 ;;; Support for source-file processing commands. | |
896 ;;;============================================================================ | |
897 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have | |
898 ;;; commands that process files of source text (e.g. loading or compiling | |
899 ;;; files). So the corresponding process-in-a-buffer modes have commands | |
900 ;;; for doing this (e.g., lisp-load-file). The functions below are useful | |
901 ;;; for defining these commands. | |
902 ;;; | |
903 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme | |
904 ;;; and Soar, in that they don't know anything about file extensions. | |
905 ;;; So the compile/load interface gets the wrong default occasionally. | |
906 ;;; The load-file/compile-file default mechanism could be smarter -- it | |
907 ;;; doesn't know about the relationship between filename extensions and | |
908 ;;; whether the file is source or executable. If you compile foo.lisp | |
909 ;;; with compile-file, then the next load-file should use foo.bin for | |
910 ;;; the default, not foo.lisp. This is tricky to do right, particularly | |
911 ;;; because the extension for executable files varies so much (.o, .bin, | |
912 ;;; .lbin, .mo, .vo, .ao, ...). | |
913 | |
914 | |
915 ;;; COMINT-SOURCE-DEFAULT -- determines defaults for source-file processing | |
916 ;;; commands. | |
917 ;;; | |
918 ;;; COMINT-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you | |
919 ;;; want to save the buffer before issuing any process requests to the command | |
920 ;;; interpreter. | |
921 ;;; | |
922 ;;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt | |
923 ;;; for the file to process. | |
924 | |
925 ;;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes) | |
926 ;;;============================================================================ | |
927 ;;; This function computes the defaults for the load-file and compile-file | |
584 | 928 ;;; commands for tea, soar, cmulisp, and cmuscheme modes. |
114 | 929 ;;; |
930 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last | |
931 ;;; source-file processing command. NIL if there hasn't been one yet. | |
932 ;;; - SOURCE-MODES is a list used to determine what buffers contain source | |
933 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source. | |
934 ;;; Typically, (lisp-mode) or (scheme-mode). | |
935 ;;; | |
936 ;;; If the command is given while the cursor is inside a string, *and* | |
937 ;;; the string is an existing filename, *and* the filename is not a directory, | |
938 ;;; then the string is taken as default. This allows you to just position | |
939 ;;; your cursor over a string that's a filename and have it taken as default. | |
940 ;;; | |
941 ;;; If the command is given in a file buffer whose major mode is in | |
942 ;;; SOURCE-MODES, then the the filename is the default file, and the | |
943 ;;; file's directory is the default directory. | |
944 ;;; | |
945 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer), | |
946 ;;; then the default directory & file are what was used in the last source-file | |
947 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time | |
948 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory | |
949 ;;; is the cwd, with no default file. (\"no default file\" = nil) | |
950 ;;; | |
951 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode) | |
952 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode) | |
953 ;;; for Soar programs, etc. | |
954 ;;; | |
955 ;;; The function returns a pair: (default-directory . default-file). | |
956 | |
957 (defun comint-source-default (previous-dir/file source-modes) | |
958 (cond ((and buffer-file-name (memq major-mode source-modes)) | |
959 (cons (file-name-directory buffer-file-name) | |
960 (file-name-nondirectory buffer-file-name))) | |
961 (previous-dir/file) | |
962 (t | |
963 (cons default-directory nil)))) | |
964 | |
584 | 965 |
114 | 966 ;;; (COMINT-CHECK-SOURCE fname) |
967 ;;;============================================================================ | |
584 | 968 ;;; Prior to loading or compiling (or otherwise processing) a file (in the CMU |
114 | 969 ;;; process-in-a-buffer modes), this function can be called on the filename. |
970 ;;; If the file is loaded into a buffer, and the buffer is modified, the user | |
971 ;;; is queried to see if he wants to save the buffer before proceeding with | |
972 ;;; the load or compile. | |
973 | |
974 (defun comint-check-source (fname) | |
975 (let ((buff (get-file-buffer fname))) | |
976 (if (and buff | |
977 (buffer-modified-p buff) | |
978 (y-or-n-p (format "Save buffer %s first? " | |
979 (buffer-name buff)))) | |
980 ;; save BUFF. | |
981 (let ((old-buffer (current-buffer))) | |
982 (set-buffer buff) | |
983 (save-buffer) | |
984 (set-buffer old-buffer))))) | |
985 | |
584 | 986 |
114 | 987 ;;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p) |
988 ;;;============================================================================ | |
989 ;;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter | |
990 ;;; commands that process source files (like loading or compiling a file). | |
991 ;;; It prompts for the filename, provides a default, if there is one, | |
992 ;;; and returns the result filename. | |
993 ;;; | |
994 ;;; See COMINT-SOURCE-DEFAULT for more on determining defaults. | |
995 ;;; | |
996 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair | |
997 ;;; from the last source processing command. SOURCE-MODES is a list of major | |
998 ;;; modes used to determine what file buffers contain source files. (These | |
999 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true, | |
1000 ;;; then the filename reader will only accept a file that exists. | |
1001 ;;; | |
1002 ;;; A typical use: | |
1003 ;;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file | |
1004 ;;; '(lisp-mode) t)) | |
1005 | |
1006 ;;; This is pretty stupid about strings. It decides we're in a string | |
1007 ;;; if there's a quote on both sides of point on the current line. | |
1008 (defun comint-extract-string () | |
1009 "Returns string around point that starts the current line or nil." | |
1010 (save-excursion | |
1011 (let* ((point (point)) | |
1012 (bol (progn (beginning-of-line) (point))) | |
1013 (eol (progn (end-of-line) (point))) | |
1014 (start (progn (goto-char point) | |
1015 (and (search-backward "\"" bol t) | |
1016 (1+ (point))))) | |
1017 (end (progn (goto-char point) | |
1018 (and (search-forward "\"" eol t) | |
1019 (1- (point)))))) | |
1020 (and start end | |
1021 (buffer-substring start end))))) | |
1022 | |
1023 (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p) | |
1024 (let* ((def (comint-source-default prev-dir/file source-modes)) | |
1025 (stringfile (comint-extract-string)) | |
1026 (sfile-p (and stringfile | |
584 | 1027 (condition-case () |
1028 (file-exists-p stringfile) | |
1029 (error nil)) | |
114 | 1030 (not (file-directory-p stringfile)))) |
1031 (defdir (if sfile-p (file-name-directory stringfile) | |
1032 (car def))) | |
1033 (deffile (if sfile-p (file-name-nondirectory stringfile) | |
1034 (cdr def))) | |
1035 (ans (read-file-name (if deffile (format "%s(default %s) " | |
1036 prompt deffile) | |
1037 prompt) | |
1038 defdir | |
1039 (concat defdir deffile) | |
1040 mustmatch-p))) | |
1041 (list (expand-file-name (substitute-in-file-name ans))))) | |
1042 | |
584 | 1043 ;;; I am somewhat divided on this string-default feature. It seems |
1044 ;;; to violate the principle-of-least-astonishment, in that it makes | |
1045 ;;; the default harder to predict, so you actually have to look and see | |
1046 ;;; what the default really is before choosing it. This can trip you up. | |
1047 ;;; On the other hand, it can be useful, I guess. I would appreciate feedback | |
1048 ;;; on this. | |
1049 ;;; -Olin | |
1050 | |
114 | 1051 |
1052 ;;; Simple process query facility. | |
1053 ;;; =========================================================================== | |
1054 ;;; This function is for commands that want to send a query to the process | |
1055 ;;; and show the response to the user. For example, a command to get the | |
1056 ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query | |
1057 ;;; to an inferior Common Lisp process. | |
1058 ;;; | |
1059 ;;; This simple facility just sends strings to the inferior process and pops | |
1060 ;;; up a window for the process buffer so you can see what the process | |
1061 ;;; responds with. We don't do anything fancy like try to intercept what the | |
1062 ;;; process responds with and put it in a pop-up window or on the message | |
1063 ;;; line. We just display the buffer. Low tech. Simple. Works good. | |
1064 | |
1065 ;;; Send to the inferior process PROC the string STR. Pop-up but do not select | |
1066 ;;; a window for the inferior process so that its response can be seen. | |
1067 (defun comint-proc-query (proc str) | |
1068 (let* ((proc-buf (process-buffer proc)) | |
1069 (proc-mark (process-mark proc))) | |
1070 (display-buffer proc-buf) | |
1071 (set-buffer proc-buf) ; but it's not the selected *window* | |
1072 (let ((proc-win (get-buffer-window proc-buf)) | |
1073 (proc-pt (marker-position proc-mark))) | |
1074 (comint-send-string proc str) ; send the query | |
1075 (accept-process-output proc) ; wait for some output | |
1076 ;; Try to position the proc window so you can see the answer. | |
1077 ;; This is bogus code. If you delete the (sit-for 0), it breaks. | |
1078 ;; I don't know why. Wizards invited to improve it. | |
1079 (if (not (pos-visible-in-window-p proc-pt proc-win)) | |
1080 (let ((opoint (window-point proc-win))) | |
1081 (set-window-point proc-win proc-mark) (sit-for 0) | |
1082 (if (not (pos-visible-in-window-p opoint proc-win)) | |
1083 (push-mark opoint) | |
1084 (set-window-point proc-win opoint))))))) | |
1085 | |
1086 | |
1087 ;;; Filename completion in a buffer | |
1088 ;;; =========================================================================== | |
1089 ;;; Useful completion functions, courtesy of the Ergo group. | |
1090 ;;; M-<Tab> will complete the filename at the cursor as much as possible | |
1091 ;;; M-? will display a list of completions in the help buffer. | |
1092 | |
1093 ;;; Three commands: | |
1094 ;;; comint-dynamic-complete Complete filename at point. | |
1095 ;;; comint-dynamic-list-completions List completions in help buffer. | |
1096 ;;; comint-replace-by-expanded-filename Expand and complete filename at point; | |
1097 ;;; replace with expanded/completed name. | |
1098 | |
1099 ;;; These are not installed in the comint-mode keymap. But they are | |
584 | 1100 ;;; available for people who want them. Shell-mode installs them: |
1101 ;;; (define-key cmushell-mode-map "\M-\t" 'comint-dynamic-complete) | |
1102 ;;; (define-key cmushell-mode-map "\M-?" 'comint-dynamic-list-completions))) | |
1103 ;;; | |
1104 ;;; Commands like this are fine things to put in load hooks if you | |
1105 ;;; want them present in specific modes. Example: | |
1106 ;;; (setq cmushell-load-hook | |
1107 ;;; '((lambda () (define-key lisp-mode-map "\M-\t" | |
1108 ;;; 'comint-replace-by-expanded-filename)))) | |
1109 ;;; | |
1110 | |
114 | 1111 |
1112 (defun comint-match-partial-pathname () | |
584 | 1113 "Returns the filename at point or causes an error." |
1114 (save-excursion | |
1115 (if (re-search-backward "[^~/A-Za-z0-9---_.$#,=]" nil 'move) | |
1116 (forward-char 1)) | |
1117 ;; Anchor the search forwards. | |
1118 (if (not (looking-at "[~/A-Za-z0-9---_.$#,=]")) (error "")) | |
1119 (re-search-forward "[~/A-Za-z0-9---_.$#,=]+") | |
1120 (substitute-in-file-name | |
1121 (buffer-substring (match-beginning 0) (match-end 0))))) | |
1122 | |
114 | 1123 |
1124 (defun comint-replace-by-expanded-filename () | |
584 | 1125 "Replace the filename at point with an expanded, canonicalised, and |
1126 completed replacement. | |
114 | 1127 \"Expanded\" means environment variables (e.g., $HOME) and ~'s are |
1128 replaced with the corresponding directories. \"Canonicalised\" means .. | |
584 | 1129 and \. are removed, and the filename is made absolute instead of relative. |
1130 See functions expand-file-name and substitute-in-file-name. See also | |
114 | 1131 comint-dynamic-complete." |
1132 (interactive) | |
1133 (let* ((pathname (comint-match-partial-pathname)) | |
1134 (pathdir (file-name-directory pathname)) | |
1135 (pathnondir (file-name-nondirectory pathname)) | |
1136 (completion (file-name-completion pathnondir | |
1137 (or pathdir default-directory)))) | |
1138 (cond ((null completion) | |
584 | 1139 (message "No completions of %s." pathname) |
1140 (ding)) | |
114 | 1141 ((eql completion t) |
584 | 1142 (message "Unique completion.")) |
114 | 1143 (t ; this means a string was returned. |
1144 (delete-region (match-beginning 0) (match-end 0)) | |
1145 (insert (expand-file-name (concat pathdir completion))))))) | |
1146 | |
584 | 1147 |
114 | 1148 (defun comint-dynamic-complete () |
584 | 1149 "Dynamically complete the filename at point. |
114 | 1150 This function is similar to comint-replace-by-expanded-filename, except |
1151 that it won't change parts of the filename already entered in the buffer; | |
1152 it just adds completion characters to the end of the filename." | |
1153 (interactive) | |
1154 (let* ((pathname (comint-match-partial-pathname)) | |
1155 (pathdir (file-name-directory pathname)) | |
1156 (pathnondir (file-name-nondirectory pathname)) | |
584 | 1157 (completion (file-name-completion pathnondir |
114 | 1158 (or pathdir default-directory)))) |
1159 (cond ((null completion) | |
584 | 1160 (message "No completions of %s." pathname) |
1161 (ding)) | |
114 | 1162 ((eql completion t) |
584 | 1163 (message "Unique completion.")) |
114 | 1164 (t ; this means a string was returned. |
1165 (goto-char (match-end 0)) | |
1166 (insert (substring completion (length pathnondir))))))) | |
1167 | |
1168 (defun comint-dynamic-list-completions () | |
584 | 1169 "List in help buffer all possible completions of the filename at point." |
114 | 1170 (interactive) |
1171 (let* ((pathname (comint-match-partial-pathname)) | |
1172 (pathdir (file-name-directory pathname)) | |
1173 (pathnondir (file-name-nondirectory pathname)) | |
1174 (completions | |
1175 (file-name-all-completions pathnondir | |
1176 (or pathdir default-directory)))) | |
1177 (cond ((null completions) | |
584 | 1178 (message "No completions of %s." pathname) |
1179 (ding)) | |
114 | 1180 (t |
1181 (let ((conf (current-window-configuration))) | |
584 | 1182 (with-output-to-temp-buffer "*Help*" |
114 | 1183 (display-completion-list completions)) |
1184 (sit-for 0) | |
1185 (message "Hit space to flush.") | |
1186 (let ((ch (read-char))) | |
1187 (if (= ch ?\ ) | |
1188 (set-window-configuration conf) | |
1189 (setq unread-command-char ch)))))))) | |
1190 | |
584 | 1191 ; Ergo bindings |
1192 ; (global-set-key "\M-\t" 'comint-replace-by-expanded-filename) | |
1193 ; (global-set-key "\M-?" 'comint-dynamic-list-completions) | |
1194 ; (define-key shell-mode-map "\M-\t" 'comint-dynamic-complete) | |
114 | 1195 |
1196 ;;; Converting process modes to use comint mode | |
1197 ;;; =========================================================================== | |
768
4abf65b235d9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
705
diff
changeset
|
1198 ;;; The code in the Emacs 19 distribution has all been modified to use comint |
4abf65b235d9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
705
diff
changeset
|
1199 ;;; where needed. However, there are `third-party' packages out there that |
4abf65b235d9
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
705
diff
changeset
|
1200 ;;; still use the old shell mode. Here's a guide to conversion. |
584 | 1201 ;;; |
114 | 1202 ;;; Renaming variables |
584 | 1203 ;;; Most of the work is renaming variables and functions. These are the common |
1204 ;;; ones: | |
1205 ;;; Local variables: | |
705 | 1206 ;;; last-input-start comint-last-input-start |
584 | 1207 ;;; last-input-end comint-last-input-end |
1208 ;;; shell-prompt-pattern comint-prompt-regexp | |
1209 ;;; shell-set-directory-error-hook <no equivalent> | |
1210 ;;; Miscellaneous: | |
114 | 1211 ;;; shell-set-directory <unnecessary> |
1212 ;;; shell-mode-map comint-mode-map | |
584 | 1213 ;;; Commands: |
114 | 1214 ;;; shell-send-input comint-send-input |
1215 ;;; shell-send-eof comint-delchar-or-maybe-eof | |
1216 ;;; kill-shell-input comint-kill-input | |
1217 ;;; interrupt-shell-subjob comint-interrupt-subjob | |
1218 ;;; stop-shell-subjob comint-stop-subjob | |
1219 ;;; quit-shell-subjob comint-quit-subjob | |
1220 ;;; kill-shell-subjob comint-kill-subjob | |
1221 ;;; kill-output-from-shell comint-kill-output | |
1222 ;;; show-output-from-shell comint-show-output | |
1223 ;;; copy-last-shell-input Use comint-previous-input/comint-next-input | |
1224 ;;; | |
705 | 1225 ;;; SHELL-SET-DIRECTORY is gone, its functionality taken over by |
1226 ;;; SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-sentinel. | |
1227 ;;; Comint mode does not provide functionality equivalent to | |
114 | 1228 ;;; shell-set-directory-error-hook; it is gone. |
705 | 1229 ;;; |
1230 ;;; comint-last-input-start is provided for modes which want to munge | |
1231 ;;; the buffer after input is sent, perhaps because the inferior | |
1232 ;;; insists on echoing the input. The LAST-INPUT-START variable in | |
1233 ;;; the old shell package was used to implement a history mechanism, | |
1234 ;;; but you should think twice before using comint-last-input-start | |
1235 ;;; for this; the input history ring often does the job better. | |
114 | 1236 ;;; |
1237 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do | |
1238 ;;; *not* create the comint-mode local variables in your foo-mode function. | |
1239 ;;; This is not modular. Instead, call comint-mode, and let *it* create the | |
1240 ;;; necessary comint-specific local variables. Then create the | |
1241 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to | |
1242 ;;; be foo-mode-map, and its mode to be foo-mode. Set the comint-mode hooks | |
1243 ;;; (comint-prompt-regexp, comint-input-filter, comint-input-sentinel, | |
1244 ;;; comint-get-old-input) that need to be different from the defaults. Call | |
1245 ;;; foo-mode-hook, and you're done. Don't run the comint-mode hook yourself; | |
584 | 1246 ;;; comint-mode will take care of it. The following example, from cmushell.el, |
1247 ;;; is typical: | |
1248 ;;; | |
1249 ;;; (defun shell-mode () | |
1250 ;;; (interactive) | |
1251 ;;; (comint-mode) | |
1252 ;;; (setq comint-prompt-regexp shell-prompt-pattern) | |
1253 ;;; (setq major-mode 'shell-mode) | |
1254 ;;; (setq mode-name "Shell") | |
1255 ;;; (cond ((not shell-mode-map) | |
1256 ;;; (setq shell-mode-map (full-copy-sparse-keymap comint-mode-map)) | |
1257 ;;; (define-key shell-mode-map "\M-\t" 'comint-dynamic-complete) | |
1258 ;;; (define-key shell-mode-map "\M-?" | |
1259 ;;; 'comint-dynamic-list-completions))) | |
1260 ;;; (use-local-map shell-mode-map) | |
1261 ;;; (make-local-variable 'shell-directory-stack) | |
1262 ;;; (setq shell-directory-stack nil) | |
1263 ;;; (setq comint-input-sentinel 'shell-directory-tracker) | |
1264 ;;; (run-hooks 'shell-mode-hook)) | |
1265 ;;; | |
114 | 1266 ;;; |
1267 ;;; Note that make-comint is different from make-shell in that it | |
1268 ;;; doesn't have a default program argument. If you give make-shell | |
1269 ;;; a program name of NIL, it cleverly chooses one of explicit-shell-name, | |
1270 ;;; $ESHELL, $SHELL, or /bin/sh. If you give make-comint a program argument | |
1271 ;;; of NIL, it barfs. Adjust your code accordingly... | |
584 | 1272 ;;; |
1273 | |
1274 ;;; Do the user's customisation... | |
1275 | |
1276 (defvar comint-load-hook nil | |
1277 "This hook is run when comint is loaded in. | |
1278 This is a good place to put keybindings.") | |
1279 | |
1280 (run-hooks 'comint-load-hook) | |
1281 | |
1282 ;;; Change log: | |
1283 ;;; 9/12/89 | |
1284 ;;; - Souped up the filename expansion procedures. | |
1285 ;;; Doc strings are much clearer and more detailed. | |
1286 ;;; Fixed a bug where doing a filename completion when the point | |
1287 ;;; was in the middle of the filename instead of at the end would lose. | |
1288 ;;; | |
1289 ;;; 2/17/90 | |
1290 ;;; - Souped up the command history stuff so that text inserted | |
1291 ;;; by comint-previous-input-matching is removed by following | |
1292 ;;; command history recalls. comint-next/previous-input-matching | |
1293 ;;; is now much more smoothly integrated w/the command history stuff. | |
1294 ;;; - Added comint-eol-on-send flag and comint-input-sender hook. | |
1295 ;;; Comint-input-sender based on code contributed by Jeff Peck | |
1296 ;;; (peck@sun.com). | |
1297 ;;; | |
1298 ;;; 3/13/90 ccm@cmu.cs.edu | |
1299 ;;; - Added comint-previous-similar-input for looking up similar inputs. | |
1300 ;;; - Added comint-send-and-get-output to allow snarfing input from | |
1301 ;;; buffer. | |
1302 ;;; - Added the ability to pick up a source file by positioning over | |
1303 ;;; a string in comint-get-source. | |
1304 ;;; - Added add-hook to make it a little easier for the user to use | |
1305 ;;; multiple hooks. | |
1306 ;;; | |
1307 ;;; 5/22/90 shivers | |
1308 ;;; - Moved Chris' multiplexed ipc stuff to comint-ipc.el. | |
1309 ;;; - Altered Chris' comint-get-source string feature. The string | |
1310 ;;; is only offered as a default if it names an existing file. | |
1311 ;;; - Changed comint-exec to directly crank up the process, instead | |
1312 ;;; of calling the env program. This made background.el happy. | |
1313 ;;; - Added new buffer-local var comint-ptyp. The problem is that | |
1314 ;;; the signalling functions don't work as advertised. If you are | |
1315 ;;; communicating via pipes, the CURRENT-GROUP arg is supposed to | |
1316 ;;; be ignored, but, unfortunately it seems to be the case that you | |
1317 ;;; must pass a NIL for this arg in the pipe case. COMINT-PTYP | |
1318 ;;; is a flag that tells whether the process is communicating | |
1319 ;;; via pipes or a pty. The comint signalling functions use it | |
1320 ;;; to determine the necessary CURRENT-GROUP arg value. The bug | |
1321 ;;; has been reported to the Gnu folks. | |
1322 ;;; - comint-dynamic-complete flushes the help window if you hit space | |
1323 ;;; after you execute it. | |
1324 ;;; - Added functions comint-send-string, comint-send-region and var | |
1325 ;;; comint-input-chunk-size. comint-send-string tries to prevent processes | |
1326 ;;; from hanging when you send them long strings by breaking them into | |
1327 ;;; chunks and allowing process output between chunks. I got the idea from | |
1328 ;;; Eero Simoncelli's Common Lisp package. Note that using | |
1329 ;;; comint-send-string means that the process buffer's contents can change | |
1330 ;;; during a call! If you depend on process output only happening between | |
1331 ;;; toplevel commands, this could be a problem. In such a case, use | |
1332 ;;; process-send-string instead. If this is a problem for people, I'd like | |
1333 ;;; to hear about it. | |
1334 ;;; - Added comint-proc-query as a simple mechanism for commands that | |
1335 ;;; want to query an inferior process and display its response. For a | |
1336 ;;; typical use, see lisp-show-arglist in cmulisp.el. | |
1337 ;;; - Added constant comint-version, which is now "2.01". | |
1338 ;;; | |
1339 ;;; 6/14/90 shivers | |
1340 ;;; - Had comint-update-env defined twice. Removed extra copy. Also | |
1341 ;;; renamed mem to be comint-mem, for modularity. The duplication | |
1342 ;;; was reported by Michael Meissner. | |
1343 ;;; 6/16/90 shivers | |
1344 ;;; - Emacs has two different mechanisms for maintaining the process | |
1345 ;;; environment, determined at compile time by the MAINTAIN-ENVIRONMENT | |
1346 ;;; #define. One uses the process-environment global variable, and | |
1347 ;;; one uses a getenv/setenv interface. comint-exec assumed the | |
1348 ;;; process-environment interface; it has been generalised (with | |
1349 ;;; comint-exec-1) to handle both cases. Pretty bogus. We could, | |
1350 ;;; of course, skip all this and just use the etc/env program to | |
1351 ;;; handle the environment tweaking, but that obscures process | |
1352 ;;; queries that other modules (like background.el) depend on. etc/env | |
1353 ;;; is also fairly bogus. This bug, and some of the fix code was | |
1354 ;;; reported by Dan Pierson. | |
1355 ;;; | |
1356 ;;; 9/5/90 shivers | |
1357 ;;; - Changed make-variable-buffer-local's to make-local-variable's. | |
1358 ;;; This leaves non-comint-mode buffers alone. Stephane Payrard | |
1359 ;;; reported the sloppy useage. | |
1360 ;;; - You can now go from comint-previous-similar-input to | |
1361 ;;; comint-previous-input with no problem. | |
1362 ;;; | |
1363 ;;; 12/21/90 shivers | |
1364 ;;; - Added a condition-case to comint-get-source. Bogus strings | |
1365 ;;; beginning with ~ were making the file-exists-p barf. | |
1366 ;;; - Added "=" to the set of chars recognised by file completion | |
1367 ;;; as constituting a filename. | |
1368 ;;; | |
1369 ;;; 1/90 shivers | |
1370 ;;; These changes comprise release 2.02: | |
1371 ;;; - Removed the kill-all-local-variables in comint-mode. This | |
1372 ;;; made it impossible for client modes to set things before calling | |
1373 ;;; comint-mode. (In particular, it messed up ilisp.el) In general, | |
1374 ;;; the client mode should be responsible for a k-a-l-v's. | |
1375 ;;; - Fixed comint-match-partial-pathname so that it works in | |
1376 ;;; more cases: if the filename begins at the start-of-buffer; | |
1377 ;;; if point is on the first char of the filename. Just a question | |
1378 ;;; of getting the tricky bits right. | |
1379 ;;; - Added a hook, comint-exec-hook that is run each time a process | |
1380 ;;; is cranked up. Useful for things like process-kill-without-query. | |
1381 ;;; | |
705 | 1382 ;;; These two were pointed out by tale: |
584 | 1383 ;;; - Improved the doc string in comint-send-input a little bit. |
1384 ;;; - Tweaked make-comint to check process status with comint-check-proc | |
1385 ;;; instead of equivalent inline code. | |
705 | 1386 ;;; |
584 | 1387 ;;; - Prompt-search history commands have been commented out. I never |
1388 ;;; liked them; I don't think anyone used them. | |
705 | 1389 ;;; - Made comint-exec-hook a local var, as it should have been. |
1390 ;;; (This way, for instance, you can have cmushell procs kill-w/o-query, | |
1391 ;;; but let Scheme procs be default.) | |
1392 ;;; | |
1393 ;;; 7/91 Shivers | |
1394 ;;; - Souped up comint-read-noecho with an optional argument, STARS. | |
1395 ;;; Suggested by mjlx@EAGLE.CNSF.CORNELL.EDU. | |
1396 ;;; - Moved comint-previous-input-matching from C-c r to C-M-r. | |
1397 ;;; C-c <letter> bindings are reserved for the user. | |
1398 ;;; These bindings were done by Jim Blandy. | |
1399 ;;; These changes comprise version 2.03. | |
584 | 1400 |
1401 (provide 'comint) | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
1402 |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
638
diff
changeset
|
1403 ;;; comint.el ends here |