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