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