1 ;;; comint.el --- general command interpreter in a window stuff
2 ;; Copyright (C) 1988, 1990, 1992 Free Software Foundation, Inc.
4 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;;; The changelog is at the end of this file.
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)
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.).
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).
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.
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.
60 ;;; For hints on converting existing process modes (e.g., tex-mode,
61 ;;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode
62 ;;; instead of shell-mode, see the notes at the end of this file.
65 ;;; Brief Command Documentation:
66 ;;;============================================================================
67 ;;; Comint Mode Commands: (common to all derived modes, like cmushell & cmulisp
70 ;;; m-p comint-previous-input Cycle backwards in input history
71 ;;; m-n comint-next-input Cycle forwards
72 ;;; m-r comint-previous-similar-input Previous similar input
73 ;;; m-s comint-next-similar-input Next similar input
74 ;;; c-m-r comint-previous-input-matching Search backwards in input history
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
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.
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).
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
104 ;;; comint-mode-hook is the comint mode hook. Basically for your keybindings.
105 ;;; comint-load-hook is run after loading in this package.
109 (defconst comint-version "2.03")
113 ;;; Buffer Local Variables:
114 ;;;============================================================================
115 ;;; Comint mode buffer local variables:
116 ;;; comint-prompt-regexp - string comint-bol uses to match prompt.
117 ;;; comint-last-input-start - marker Handy if inferior always echos
118 ;;; comint-last-input-end - marker For comint-kill-output command
119 ;;; comint-input-ring-size - integer For the input history
120 ;;; comint-input-ring - ring mechanism
121 ;;; comint-input-ring-index - marker ...
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
129 (defvar comint-prompt-regexp "^"
130 "Regexp to recognise prompts in the inferior process.
131 Defaults to \"^\", the null string at BOL.
134 Canonical Lisp: \"^[^> ]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
135 Lucid Common Lisp: \"^\\(>\\|\\(->\\)+\\) *\"
136 franz: \"^\\(->\\|<[0-9]*>:\\) *\"
138 shell: \"^[^#$%>]*[#$%>] *\"
141 This is a good thing to set in mode hooks.")
143 (defvar comint-input-ring-size 30
144 "Size of input history ring.")
146 ;;; Here are the per-interpreter hooks.
147 (defvar comint-get-old-input (function comint-get-old-input-default)
148 "Function that submits old text in comint mode.
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
152 leading text matching comint-prompt-regexp")
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.")
158 (defvar comint-input-filter
159 (function (lambda (str) (not (string-match "\\`\\s *\\'" str))))
160 "Predicate for filtering additions to input history.
161 Only inputs answering true to this function are saved on the input
162 history list. Default is to save anything that isn't all whitespace")
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.")
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")
175 (defvar comint-mode-hook '()
176 "Called upon entry into comint-mode
177 This is run before the process is cranked up.")
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.")
186 (defvar comint-mode-map nil)
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.")
192 (defvar comint-last-input-match ""
193 "Last string searched for by comint input history search, for defaulting.
194 Buffer local variable.")
196 (defvar comint-input-ring nil)
197 (defvar comint-last-input-start)
198 (defvar comint-last-input-end)
199 (defvar comint-input-ring-index)
200 (put 'comint-input-ring 'permanent-local t)
201 (put 'comint-ptyp 'permanent-local t)
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.
208 Setting mode variable comint-eol-on-send means jump to the end of the line
209 before submitting new input.
211 This mode is typically customised to create inferior-lisp-mode,
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.
217 An input history is maintained of size comint-input-ring-size, and
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.
223 If you accidentally suspend your process, use \\[comint-continue-subjob]
228 Entry to this mode runs the hooks on comint-mode-hook"
230 ;; Do not remove this. All major modes must do this.
231 (kill-all-local-variables)
232 (setq major-mode 'comint-mode)
233 (setq mode-name "Comint")
234 (setq mode-line-process '(": %s"))
235 (use-local-map comint-mode-map)
236 (make-local-variable 'comint-last-input-start)
237 (setq comint-last-input-start (make-marker))
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
243 (make-local-variable 'comint-input-ring-size) ; ...to global val.
244 (make-local-variable 'comint-input-ring)
245 (make-local-variable 'comint-input-ring-index)
246 (setq comint-input-ring-index 0)
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)
253 (make-local-variable 'comint-exec-hook)
254 (run-hooks 'comint-mode-hook)
255 (or comint-input-ring
256 (setq comint-input-ring (make-ring comint-input-ring-size))))
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)
263 (define-key comint-mode-map "\er" 'comint-previous-similar-input)
264 (define-key comint-mode-map "\es" 'comint-next-similar-input)
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)
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"
289 (cons (full-copy-sparse-keymap (car km))
290 (full-copy-sparse-keymap (cdr km))))
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
297 (let ((proc (get-buffer-process buffer)))
298 (and proc (memq (process-status proc) '(run stop)))))
300 ;;; Note that this guy, unlike shell.el's make-shell, barfs if you pass it ()
301 ;;; for the second argument (program).
303 (defun make-comint (name program &optional startfile &rest switches)
304 (let ((buffer (get-buffer-create (concat "*" name "*"))))
305 ;; If no process, or nuked process, crank up a new one and put buffer in
306 ;; comint mode. Otherwise, leave buffer and existing process alone.
307 (cond ((not (comint-check-proc buffer))
310 (comint-mode)) ; Install local vars, mode, keymap, ...
311 (comint-exec buffer name program startfile switches)))
314 (defun comint-exec (buffer name command startfile switches)
315 "Fires up a process in buffer for comint modes.
316 Blasts any old process running in the buffer. Doesn't set the buffer mode.
317 You can use this to cheaply run a series of processes in the same comint
318 buffer. The hook comint-exec-hook is run after each exec."
321 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
322 (if proc (delete-process proc)))
323 ;; Crank up a new process
324 (let ((proc (comint-exec-1 name buffer command switches)))
325 (make-local-variable 'comint-ptyp)
326 (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe.
327 ;; Jump to the end, and set the process mark.
328 (goto-char (point-max))
329 (set-marker (process-mark proc) (point))
330 ;; Feed it the startfile.
332 ;;This is guaranteed to wait long enough
333 ;;but has bad results if the comint does not prompt at all
334 ;; (while (= size (buffer-size))
336 ;;I hope 1 second is enough!
338 (goto-char (point-max))
339 (insert-file-contents startfile)
340 (setq startfile (buffer-substring (point) (point-max)))
341 (delete-region (point) (point-max))
342 (comint-send-string proc startfile)))
343 (run-hooks 'comint-exec-hook)
346 ;;; This auxiliary function cranks up the process for comint-exec in
347 ;;; the appropriate environment.
349 (defun comint-exec-1 (name buffer command switches)
350 (let ((process-environment
351 (comint-update-env process-environment
352 (list (format "TERMCAP=emacs:co#%d:tc=unknown"
356 (apply 'start-process name buffer command switches)))
360 ;; This is just (append new old-env) that compresses out shadowed entries.
361 ;; It's also pretty ugly, mostly due to lisp's horrible iteration structures.
362 (defun comint-update-env (old-env new)
363 (let ((ans (reverse new))
364 (vars (mapcar (function (lambda (vv)
365 (and (string-match "^[^=]*=" vv)
366 (substring vv 0 (match-end 0)))))
369 (let* ((vv (car old-env)) ; vv is var=value
370 (var (and (string-match "^[^=]*=" vv)
371 (substring vv 0 (match-end 0)))))
372 (setq old-env (cdr old-env))
373 (cond ((not (and var (comint-mem var vars)))
374 (if var (setq var (cons var vars)))
375 (setq ans (cons vv ans))))))
378 ;;; This should be in emacs, but it isn't.
379 (defun comint-mem (item list &optional elt=)
380 "Test to see if ITEM is equal to an item in LIST.
381 Option comparison function ELT= defaults to equal."
382 (let ((elt= (or elt= (function equal)))
384 (while (and list (not done))
385 (if (funcall elt= item (car list))
387 (setq list (cdr list))))
391 ;;; Input history retrieval commands
392 ;;; M-p -- previous input M-n -- next input
393 ;;; M-C-r -- previous input matching
394 ;;; ===========================================================================
396 (defun comint-previous-input (arg)
397 "Cycle backwards through input history."
399 (let ((len (ring-length comint-input-ring)))
401 (message "Empty input ring")
403 ((not (comint-after-pmark-p))
404 (message "Not after process mark")
407 (delete-region (point)
408 (process-mark (get-buffer-process (current-buffer))))
409 ;; Initialize the index on the first use of this command
410 ;; so that the first M-p gets index 0, and the first M-n gets
412 (if (null comint-input-ring-index)
413 (setq comint-input-ring-index
415 (if (< arg 0) 1 0))))
416 (setq comint-input-ring-index
417 (comint-mod (+ comint-input-ring-index arg) len))
418 (message "%d" (1+ comint-input-ring-index))
419 (insert (ring-ref comint-input-ring comint-input-ring-index))))))
421 (defun comint-mod (n m)
422 "Returns N mod M. M is positive.
423 Answer is guaranteed to be non-negative, and less than m."
427 (if (>= m 0) m (- m)))))) ; (abs m)
429 (defun comint-next-input (arg)
430 "Cycle forwards through input history."
432 (comint-previous-input (- arg)))
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
438 (format "Command substring (default %s): "
439 comint-last-input-match))))
440 (list (if (string= s "") comint-last-input-match s))))
441 ; (interactive "sCommand substring: ")
442 (setq comint-last-input-match str) ; update default
443 (if (null comint-input-ring-index)
444 (setq comint-input-ring-index -1))
445 (let ((str (regexp-quote str))
446 (len (ring-length comint-input-ring))
447 (n (+ comint-input-ring-index 1)))
448 (while (and (< n len) (not (string-match str (ring-ref comint-input-ring n))))
451 (comint-previous-input (- n comint-input-ring-index)))
452 (t (error "Not found")))))
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...
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.
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
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)"
473 ; (if (re-search-forward comint-prompt-regexp (point-max) t)
475 ; (error "No occurrence of prompt found")))
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."
481 ; (let ((p (save-excursion
482 ; (beginning-of-line)
483 ; (cond ((re-search-backward comint-prompt-regexp (point-min) t)
487 ; (if p (goto-char p)
488 ; (error "No occurrence of prompt found"))))
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)))
501 ; (beginning-of-line)
502 ; (cond ((re-search-backward r (point-min) t)
506 ; (if p (goto-char p)
507 ; (error "No match"))))
510 ;;; Similar input -- contributed by ccm and highly winning.
512 ;;; Reenter input, removing back to the last insert point if it exists.
514 (defvar comint-last-similar-string ""
515 "The string last used in a similar string search.")
516 (defun comint-previous-similar-input (arg)
517 "Fetch the previous (older) input that matches the string typed so far.
518 Successive repetitions find successively older matching inputs.
519 A prefix argument serves as a repeat count; a negative argument
520 fetches following (more recent) inputs."
522 (if (not (comint-after-pmark-p))
523 (error "Not after process mark"))
524 (if (null comint-input-ring-index)
525 (setq comint-input-ring-index
527 (if (< arg 0) 1 0))))
528 (if (not (or (eq last-command 'comint-previous-similar-input)
529 (eq last-command 'comint-next-similar-input)))
530 (setq comint-last-similar-string
532 (process-mark (get-buffer-process (current-buffer)))
534 (let* ((size (length comint-last-similar-string))
535 (len (ring-length comint-input-ring))
536 (n (+ comint-input-ring-index arg))
538 (while (and (< n len)
539 (or (< (length (setq entry (ring-ref comint-input-ring n))) size)
540 (not (equal comint-last-similar-string
541 (substring entry 0 size)))))
544 (setq comint-input-ring-index n)
545 (if (or (eq last-command 'comint-previous-similar-input)
546 (eq last-command 'comint-next-similar-input))
547 (delete-region (mark) (point)) ; repeat
548 (push-mark (point))) ; 1st time
549 (insert (substring entry size)))
550 (t (error "Not found")))
551 (message "%d" (1+ comint-input-ring-index))))
553 (defun comint-next-similar-input (arg)
554 "Fetch the next (newer) input that matches the string typed so far.
555 Successive repetitions find successively newer matching inputs.
556 A prefix argument serves as a repeat count; a negative argument
557 fetches previous (older) inputs."
559 (comint-previous-similar-input (- arg)))
561 (defun comint-send-input ()
562 "Send input to process.
563 After the process output mark, sends all text from the process mark to
564 point as input to the process. Before the process output mark, calls value
565 of variable comint-get-old-input to retrieve old input, copies it to the
566 process mark, and sends it. A terminal newline is also inserted into the
567 buffer and sent to the process. In either case, value of variable
568 comint-input-sentinel is called on the input before sending it. The input
569 is entered into the input history ring, if the value of variable
570 comint-input-filter returns non-nil when called on the input.
572 If variable comint-eol-on-send is non-nil, then point is moved to the end of
573 line before sending the input.
575 comint-get-old-input, comint-input-sentinel, and comint-input-filter are chosen
576 according to the command interpreter running in the buffer. E.g.,
577 If the interpreter is the csh,
578 comint-get-old-input is the default: take the current line, discard any
579 initial string matching regexp comint-prompt-regexp.
580 comint-input-sentinel monitors input for \"cd\", \"pushd\", and \"popd\"
581 commands. When it sees one, it cd's the buffer.
582 comint-input-filter is the default: returns T if the input isn't all white
585 If the comint is Lucid Common Lisp,
586 comint-get-old-input snarfs the sexp ending at point.
587 comint-input-sentinel does nothing.
588 comint-input-filter returns NIL if the input matches input-filter-regexp,
589 which matches (1) all whitespace (2) :a, :c, etc.
591 Similarly for Soar, Scheme, etc."
593 ;; Note that the input string does not include its terminal newline.
594 (let ((proc (get-buffer-process (current-buffer))))
595 (if (not proc) (error "Current buffer has no process")
596 (let* ((pmark (process-mark proc))
597 (pmark-val (marker-position pmark))
598 (input (if (>= (point) pmark-val)
599 (progn (if comint-eol-on-send (end-of-line))
600 (buffer-substring pmark (point)))
601 (let ((copy (funcall comint-get-old-input)))
606 (if (funcall comint-input-filter input)
607 (ring-insert comint-input-ring input))
608 (funcall comint-input-sentinel input)
609 (funcall comint-input-sender proc input)
610 (setq comint-input-ring-index nil)
611 (set-marker comint-last-input-start pmark)
612 (set-marker comint-last-input-end (point))
613 (set-marker (process-mark proc) (point))))))
615 (defun comint-get-old-input-default ()
616 "Default for comint-get-old-input.
617 Take the current line, and discard any initial text matching
618 comint-prompt-regexp."
624 (buffer-substring beg (point)))))
626 (defun comint-skip-prompt ()
627 "Skip past the text matching regexp comint-prompt-regexp.
628 If this takes us past the end of the current line, don't skip at all."
629 (let ((eol (save-excursion (end-of-line) (point))))
630 (if (and (looking-at comint-prompt-regexp)
631 (<= (match-end 0) eol))
632 (goto-char (match-end 0)))))
635 (defun comint-after-pmark-p ()
636 "Is point after the process output marker?"
637 ;; Since output could come into the buffer after we looked at the point
638 ;; but before we looked at the process marker's value, we explicitly
639 ;; serialise. This is just because I don't know whether or not emacs
640 ;; services input during execution of lisp commands.
641 (let ((proc-pos (marker-position
642 (process-mark (get-buffer-process (current-buffer))))))
643 (<= proc-pos (point))))
645 (defun comint-simple-send (proc string)
646 "Default function for sending to PROC input STRING.
647 This just sends STRING plus a newline. To override this,
648 set the hook COMINT-INPUT-SENDER."
649 (comint-send-string proc string)
650 (comint-send-string proc "\n"))
652 (defun comint-bol (arg)
653 "Goes to the beginning of line, then skips past the prompt, if any.
654 If a prefix argument is given (\\[universal-argument]), then no prompt skip
655 -- go straight to column 0.
657 The prompt skip is done by skipping text matching the regular expression
658 comint-prompt-regexp, a buffer local variable.
660 If you don't like this command, reset c-a to beginning-of-line
661 in your hook, comint-mode-hook."
664 (if (null arg) (comint-skip-prompt)))
666 ;;; These two functions are for entering text you don't want echoed or
667 ;;; saved -- typically passwords to ftp, telnet, or somesuch.
668 ;;; Just enter m-x send-invisible and type in your line.
670 (defun comint-read-noecho (prompt &optional stars)
671 "Prompt the user with argument PROMPT.
672 Read a single line of text without echoing, and return it. Note that
673 the keystrokes comprising the text can still be recovered (temporarily)
674 with \\[view-lossage]. This may be a security bug for some applications.
675 Optional argument STARS causes input to be echoed with '*' characters
677 (let ((echo-keystrokes 0)
678 (cursor-in-echo-area t)
681 (if (not (stringp prompt)) (setq prompt ""))
683 (while (not(or (= (setq tem (read-char)) ?\^m)
685 (setq answ (concat answ (char-to-string tem)))
686 (if stars (setq prompt (concat prompt "*")))
692 (defun send-invisible (str)
693 "Read a string without echoing.
694 Then send it to the process running in the current buffer. A new-line
695 is additionally sent. String is not saved on comint input history list.
696 Security bug: your string can still be temporarily recovered with
698 ; (interactive (list (comint-read-noecho "Enter non-echoed text")))
699 (interactive "P") ; Defeat snooping via C-x esc
700 (let ((proc (get-buffer-process (current-buffer))))
701 (if (not proc) (error "Current buffer has no process")
702 (comint-send-string proc
703 (if (stringp str) str
704 (comint-read-noecho "Non-echoed text: " t)))
705 (comint-send-string proc "\n"))))
708 ;;; Low-level process communication
710 (defvar comint-input-chunk-size 512
711 "*Long inputs send to comint processes are broken up into chunks of this size.
712 If your process is choking on big inputs, try lowering the value.")
714 (defun comint-send-string (proc str)
715 "Send PROCESS the contents of STRING as input.
716 This is equivalent to process-send-string, except that long input strings
717 are broken up into chunks of size comint-input-chunk-size. Processes
718 are given a chance to output between chunks. This can help prevent processes
719 from hanging when you send them long inputs on some OS's."
720 (let* ((len (length str))
721 (i (min len comint-input-chunk-size)))
722 (process-send-string proc (substring str 0 i))
724 (let ((next-i (+ i comint-input-chunk-size)))
725 (accept-process-output)
726 (process-send-string proc (substring str i (min len next-i)))
729 (defun comint-send-region (proc start end)
730 "Sends to PROC the region delimited by START and END.
731 This is a replacement for process-send-region that tries to keep
732 your process from hanging on long inputs. See comint-send-string."
733 (comint-send-string proc (buffer-substring start end)))
736 ;;; Random input hackage
738 (defun comint-kill-output ()
739 "Kill all output from interpreter since last input."
741 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
742 (kill-region comint-last-input-end pmark)
744 (insert "*** output flushed ***\n")
745 (set-marker pmark (point))))
747 (defun comint-show-output ()
748 "Display start of this batch of interpreter output at top of window.
749 Also put cursor there."
751 (goto-char comint-last-input-end)
754 (set-window-start (selected-window) (point))
757 (defun comint-interrupt-subjob ()
758 "Interrupt the current subjob."
760 (interrupt-process nil comint-ptyp))
762 (defun comint-kill-subjob ()
763 "Send kill signal to the current subjob."
765 (kill-process nil comint-ptyp))
767 (defun comint-quit-subjob ()
768 "Send quit signal to the current subjob."
770 (quit-process nil comint-ptyp))
772 (defun comint-stop-subjob ()
773 "Stop the current subjob.
774 WARNING: if there is no current subjob, you can end up suspending
775 the top-level process running in the buffer. If you accidentally do
776 this, use \\[comint-continue-subjob] to resume the process. (This
777 is not a problem with most shells, since they ignore this signal.)"
779 (stop-process nil comint-ptyp))
781 (defun comint-continue-subjob ()
782 "Send CONT signal to process buffer's process group.
783 Useful if you accidentally suspend the top-level process."
785 (continue-process nil comint-ptyp))
787 (defun comint-kill-input ()
788 "Kill all text from last stuff output by interpreter to point."
790 (let* ((pmark (process-mark (get-buffer-process (current-buffer))))
791 (p-pos (marker-position pmark)))
792 (if (> (point) p-pos)
793 (kill-region pmark (point)))))
795 (defun comint-delchar-or-maybe-eof (arg)
796 "Delete ARG characters forward, or send an EOF to process if at end of buffer."
805 ;;; Support for source-file processing commands.
806 ;;;============================================================================
807 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
808 ;;; commands that process files of source text (e.g. loading or compiling
809 ;;; files). So the corresponding process-in-a-buffer modes have commands
810 ;;; for doing this (e.g., lisp-load-file). The functions below are useful
811 ;;; for defining these commands.
813 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme
814 ;;; and Soar, in that they don't know anything about file extensions.
815 ;;; So the compile/load interface gets the wrong default occasionally.
816 ;;; The load-file/compile-file default mechanism could be smarter -- it
817 ;;; doesn't know about the relationship between filename extensions and
818 ;;; whether the file is source or executable. If you compile foo.lisp
819 ;;; with compile-file, then the next load-file should use foo.bin for
820 ;;; the default, not foo.lisp. This is tricky to do right, particularly
821 ;;; because the extension for executable files varies so much (.o, .bin,
822 ;;; .lbin, .mo, .vo, .ao, ...).
825 ;;; COMINT-SOURCE-DEFAULT -- determines defaults for source-file processing
828 ;;; COMINT-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you
829 ;;; want to save the buffer before issuing any process requests to the command
832 ;;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt
833 ;;; for the file to process.
835 ;;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes)
836 ;;;============================================================================
837 ;;; This function computes the defaults for the load-file and compile-file
838 ;;; commands for tea, soar, cmulisp, and cmuscheme modes.
840 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
841 ;;; source-file processing command. NIL if there hasn't been one yet.
842 ;;; - SOURCE-MODES is a list used to determine what buffers contain source
843 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
844 ;;; Typically, (lisp-mode) or (scheme-mode).
846 ;;; If the command is given while the cursor is inside a string, *and*
847 ;;; the string is an existing filename, *and* the filename is not a directory,
848 ;;; then the string is taken as default. This allows you to just position
849 ;;; your cursor over a string that's a filename and have it taken as default.
851 ;;; If the command is given in a file buffer whose major mode is in
852 ;;; SOURCE-MODES, then the the filename is the default file, and the
853 ;;; file's directory is the default directory.
855 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
856 ;;; then the default directory & file are what was used in the last source-file
857 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
858 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
859 ;;; is the cwd, with no default file. (\"no default file\" = nil)
861 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode)
862 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
863 ;;; for Soar programs, etc.
865 ;;; The function returns a pair: (default-directory . default-file).
867 (defun comint-source-default (previous-dir/file source-modes)
868 (cond ((and buffer-file-name (memq major-mode source-modes))
869 (cons (file-name-directory buffer-file-name)
870 (file-name-nondirectory buffer-file-name)))
873 (cons default-directory nil))))
876 ;;; (COMINT-CHECK-SOURCE fname)
877 ;;;============================================================================
878 ;;; Prior to loading or compiling (or otherwise processing) a file (in the CMU
879 ;;; process-in-a-buffer modes), this function can be called on the filename.
880 ;;; If the file is loaded into a buffer, and the buffer is modified, the user
881 ;;; is queried to see if he wants to save the buffer before proceeding with
882 ;;; the load or compile.
884 (defun comint-check-source (fname)
885 (let ((buff (get-file-buffer fname)))
887 (buffer-modified-p buff)
888 (y-or-n-p (format "Save buffer %s first? "
889 (buffer-name buff))))
891 (let ((old-buffer (current-buffer)))
894 (set-buffer old-buffer)))))
897 ;;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
898 ;;;============================================================================
899 ;;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter
900 ;;; commands that process source files (like loading or compiling a file).
901 ;;; It prompts for the filename, provides a default, if there is one,
902 ;;; and returns the result filename.
904 ;;; See COMINT-SOURCE-DEFAULT for more on determining defaults.
906 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
907 ;;; from the last source processing command. SOURCE-MODES is a list of major
908 ;;; modes used to determine what file buffers contain source files. (These
909 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
910 ;;; then the filename reader will only accept a file that exists.
913 ;;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file
916 ;;; This is pretty stupid about strings. It decides we're in a string
917 ;;; if there's a quote on both sides of point on the current line.
918 (defun comint-extract-string ()
919 "Returns string around POINT that starts the current line or nil."
921 (let* ((point (point))
922 (bol (progn (beginning-of-line) (point)))
923 (eol (progn (end-of-line) (point)))
924 (start (progn (goto-char point)
925 (and (search-backward "\"" bol t)
927 (end (progn (goto-char point)
928 (and (search-forward "\"" eol t)
931 (buffer-substring start end)))))
933 (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p)
934 (let* ((def (comint-source-default prev-dir/file source-modes))
935 (stringfile (comint-extract-string))
936 (sfile-p (and stringfile
938 (file-exists-p stringfile)
940 (not (file-directory-p stringfile))))
941 (defdir (if sfile-p (file-name-directory stringfile)
943 (deffile (if sfile-p (file-name-nondirectory stringfile)
945 (ans (read-file-name (if deffile (format "%s(default %s) "
949 (concat defdir deffile)
951 (list (expand-file-name (substitute-in-file-name ans)))))
953 ;;; I am somewhat divided on this string-default feature. It seems
954 ;;; to violate the principle-of-least-astonishment, in that it makes
955 ;;; the default harder to predict, so you actually have to look and see
956 ;;; what the default really is before choosing it. This can trip you up.
957 ;;; On the other hand, it can be useful, I guess. I would appreciate feedback
962 ;;; Simple process query facility.
963 ;;; ===========================================================================
964 ;;; This function is for commands that want to send a query to the process
965 ;;; and show the response to the user. For example, a command to get the
966 ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
967 ;;; to an inferior Common Lisp process.
969 ;;; This simple facility just sends strings to the inferior process and pops
970 ;;; up a window for the process buffer so you can see what the process
971 ;;; responds with. We don't do anything fancy like try to intercept what the
972 ;;; process responds with and put it in a pop-up window or on the message
973 ;;; line. We just display the buffer. Low tech. Simple. Works good.
975 ;;; Send to the inferior process PROC the string STR. Pop-up but do not select
976 ;;; a window for the inferior process so that its response can be seen.
977 (defun comint-proc-query (proc str)
978 (let* ((proc-buf (process-buffer proc))
979 (proc-mark (process-mark proc)))
980 (display-buffer proc-buf)
981 (set-buffer proc-buf) ; but it's not the selected *window*
982 (let ((proc-win (get-buffer-window proc-buf))
983 (proc-pt (marker-position proc-mark)))
984 (comint-send-string proc str) ; send the query
985 (accept-process-output proc) ; wait for some output
986 ;; Try to position the proc window so you can see the answer.
987 ;; This is bogus code. If you delete the (sit-for 0), it breaks.
988 ;; I don't know why. Wizards invited to improve it.
989 (if (not (pos-visible-in-window-p proc-pt proc-win))
990 (let ((opoint (window-point proc-win)))
991 (set-window-point proc-win proc-mark) (sit-for 0)
992 (if (not (pos-visible-in-window-p opoint proc-win))
994 (set-window-point proc-win opoint)))))))
997 ;;; Filename completion in a buffer
998 ;;; ===========================================================================
999 ;;; Useful completion functions, courtesy of the Ergo group.
1002 ;;; comint-dynamic-complete Complete filename at point.
1003 ;;; comint-dynamic-list-completions List completions in help buffer.
1004 ;;; comint-replace-by-expanded-filename Expand and complete filename at point;
1005 ;;; replace with expanded/completed name.
1007 ;;; These are not installed in the comint-mode keymap. But they are
1008 ;;; available for people who want them. Shell-mode installs them:
1009 ;;; (define-key cmushell-mode-map "\t" 'comint-dynamic-complete)
1010 ;;; (define-key cmushell-mode-map "\M-?" 'comint-dynamic-list-completions)))
1012 ;;; Commands like this are fine things to put in load hooks if you
1013 ;;; want them present in specific modes.
1016 (defun comint-match-partial-pathname ()
1017 "Returns the filename at point or causes an error."
1019 (if (re-search-backward "[^~/A-Za-z0-9---_.$#,=]" nil 'move)
1021 ;; Anchor the search forwards.
1022 (if (not (looking-at "[~/A-Za-z0-9---_.$#,=]")) (error ""))
1023 (re-search-forward "[~/A-Za-z0-9---_.$#,=]+")
1024 (substitute-in-file-name
1025 (buffer-substring (match-beginning 0) (match-end 0)))))
1028 (defun comint-replace-by-expanded-filename ()
1029 "Expand the filename at point.
1030 Replace the filename with an expanded, canonicalised, and completed
1032 \"Expanded\" means environment variables (e.g., $HOME) and ~'s are
1033 replaced with the corresponding directories. \"Canonicalised\" means ..
1034 and \. are removed, and the filename is made absolute instead of relative.
1035 See functions expand-file-name and substitute-in-file-name. See also
1036 comint-dynamic-complete."
1038 (let* ((pathname (comint-match-partial-pathname))
1039 (pathdir (file-name-directory pathname))
1040 (pathnondir (file-name-nondirectory pathname))
1041 (completion (file-name-completion pathnondir
1042 (or pathdir default-directory))))
1043 (cond ((null completion)
1044 (message "No completions of %s" pathname)
1047 (message "Unique completion"))
1048 (t ; this means a string was returned.
1049 (delete-region (match-beginning 0) (match-end 0))
1050 (insert (expand-file-name (concat pathdir completion)))))))
1053 (defun comint-dynamic-complete ()
1054 "Dynamically complete the filename at point.
1055 This function is similar to `comint-replace-by-expanded-filename', except
1056 that it won't change parts of the filename already entered in the buffer;
1057 it just adds completion characters to the end of the filename."
1059 (let* ((pathname (comint-match-partial-pathname))
1060 (pathdir (file-name-directory pathname))
1061 (pathnondir (file-name-nondirectory pathname))
1062 (completion (file-name-completion pathnondir
1063 (or pathdir default-directory))))
1064 (cond ((null completion)
1065 (message "No completions of %s" pathname)
1068 (message "Unique completion"))
1069 (t ; this means a string was returned.
1070 (goto-char (match-end 0))
1071 (insert (substring completion (length pathnondir)))))))
1073 (defun comint-dynamic-list-completions ()
1074 "List in help buffer all possible completions of the filename at point."
1076 (let* ((pathname (comint-match-partial-pathname))
1077 (pathdir (file-name-directory pathname))
1078 (pathnondir (file-name-nondirectory pathname))
1080 (file-name-all-completions pathnondir
1081 (or pathdir default-directory))))
1082 (cond ((null completions)
1083 (message "No completions of %s" pathname)
1086 (let ((conf (current-window-configuration)))
1087 (with-output-to-temp-buffer "*Help*"
1088 (display-completion-list completions))
1090 (message "Hit space to flush")
1091 (let ((ch (read-char)))
1093 (set-window-configuration conf)
1094 (setq unread-command-char ch))))))))
1096 ;;; Converting process modes to use comint mode
1097 ;;; ===========================================================================
1098 ;;; The code in the Emacs 19 distribution has all been modified to use comint
1099 ;;; where needed. However, there are `third-party' packages out there that
1100 ;;; still use the old shell mode. Here's a guide to conversion.
1102 ;;; Renaming variables
1103 ;;; Most of the work is renaming variables and functions. These are the common
1105 ;;; Local variables:
1106 ;;; last-input-start comint-last-input-start
1107 ;;; last-input-end comint-last-input-end
1108 ;;; shell-prompt-pattern comint-prompt-regexp
1109 ;;; shell-set-directory-error-hook <no equivalent>
1111 ;;; shell-set-directory <unnecessary>
1112 ;;; shell-mode-map comint-mode-map
1114 ;;; shell-send-input comint-send-input
1115 ;;; shell-send-eof comint-delchar-or-maybe-eof
1116 ;;; kill-shell-input comint-kill-input
1117 ;;; interrupt-shell-subjob comint-interrupt-subjob
1118 ;;; stop-shell-subjob comint-stop-subjob
1119 ;;; quit-shell-subjob comint-quit-subjob
1120 ;;; kill-shell-subjob comint-kill-subjob
1121 ;;; kill-output-from-shell comint-kill-output
1122 ;;; show-output-from-shell comint-show-output
1123 ;;; copy-last-shell-input Use comint-previous-input/comint-next-input
1125 ;;; SHELL-SET-DIRECTORY is gone, its functionality taken over by
1126 ;;; SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-sentinel.
1127 ;;; Comint mode does not provide functionality equivalent to
1128 ;;; shell-set-directory-error-hook; it is gone.
1130 ;;; comint-last-input-start is provided for modes which want to munge
1131 ;;; the buffer after input is sent, perhaps because the inferior
1132 ;;; insists on echoing the input. The LAST-INPUT-START variable in
1133 ;;; the old shell package was used to implement a history mechanism,
1134 ;;; but you should think twice before using comint-last-input-start
1135 ;;; for this; the input history ring often does the job better.
1137 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do
1138 ;;; *not* create the comint-mode local variables in your foo-mode function.
1139 ;;; This is not modular. Instead, call comint-mode, and let *it* create the
1140 ;;; necessary comint-specific local variables. Then create the
1141 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to
1142 ;;; be foo-mode-map, and its mode to be foo-mode. Set the comint-mode hooks
1143 ;;; (comint-prompt-regexp, comint-input-filter, comint-input-sentinel,
1144 ;;; comint-get-old-input) that need to be different from the defaults. Call
1145 ;;; foo-mode-hook, and you're done. Don't run the comint-mode hook yourself;
1146 ;;; comint-mode will take care of it. The following example, from cmushell.el,
1149 ;;; (defun shell-mode ()
1152 ;;; (setq comint-prompt-regexp shell-prompt-pattern)
1153 ;;; (setq major-mode 'shell-mode)
1154 ;;; (setq mode-name "Shell")
1155 ;;; (cond ((not shell-mode-map)
1156 ;;; (setq shell-mode-map (full-copy-sparse-keymap comint-mode-map))
1157 ;;; (define-key shell-mode-map "\M-\t" 'comint-dynamic-complete)
1158 ;;; (define-key shell-mode-map "\M-?"
1159 ;;; 'comint-dynamic-list-completions)))
1160 ;;; (use-local-map shell-mode-map)
1161 ;;; (make-local-variable 'shell-directory-stack)
1162 ;;; (setq shell-directory-stack nil)
1163 ;;; (setq comint-input-sentinel 'shell-directory-tracker)
1164 ;;; (run-hooks 'shell-mode-hook))
1167 ;;; Note that make-comint is different from make-shell in that it
1168 ;;; doesn't have a default program argument. If you give make-shell
1169 ;;; a program name of NIL, it cleverly chooses one of explicit-shell-name,
1170 ;;; $ESHELL, $SHELL, or /bin/sh. If you give make-comint a program argument
1171 ;;; of NIL, it barfs. Adjust your code accordingly...
1174 ;;; Do the user's customisation...
1176 (defvar comint-load-hook nil
1177 "This hook is run when comint is loaded in.
1178 This is a good place to put keybindings.")
1180 (run-hooks 'comint-load-hook)
1184 ;;; - Souped up the filename expansion procedures.
1185 ;;; Doc strings are much clearer and more detailed.
1186 ;;; Fixed a bug where doing a filename completion when the point
1187 ;;; was in the middle of the filename instead of at the end would lose.
1190 ;;; - Souped up the command history stuff so that text inserted
1191 ;;; by comint-previous-input-matching is removed by following
1192 ;;; command history recalls. comint-next/previous-input-matching
1193 ;;; is now much more smoothly integrated w/the command history stuff.
1194 ;;; - Added comint-eol-on-send flag and comint-input-sender hook.
1195 ;;; Comint-input-sender based on code contributed by Jeff Peck
1198 ;;; 3/13/90 ccm@cmu.cs.edu
1199 ;;; - Added comint-previous-similar-input for looking up similar inputs.
1200 ;;; - Added comint-send-and-get-output to allow snarfing input from
1202 ;;; - Added the ability to pick up a source file by positioning over
1203 ;;; a string in comint-get-source.
1204 ;;; - Added add-hook to make it a little easier for the user to use
1208 ;;; - Moved Chris' multiplexed ipc stuff to comint-ipc.el.
1209 ;;; - Altered Chris' comint-get-source string feature. The string
1210 ;;; is only offered as a default if it names an existing file.
1211 ;;; - Changed comint-exec to directly crank up the process, instead
1212 ;;; of calling the env program. This made background.el happy.
1213 ;;; - Added new buffer-local var comint-ptyp. The problem is that
1214 ;;; the signalling functions don't work as advertised. If you are
1215 ;;; communicating via pipes, the CURRENT-GROUP arg is supposed to
1216 ;;; be ignored, but, unfortunately it seems to be the case that you
1217 ;;; must pass a NIL for this arg in the pipe case. COMINT-PTYP
1218 ;;; is a flag that tells whether the process is communicating
1219 ;;; via pipes or a pty. The comint signalling functions use it
1220 ;;; to determine the necessary CURRENT-GROUP arg value. The bug
1221 ;;; has been reported to the Gnu folks.
1222 ;;; - comint-dynamic-complete flushes the help window if you hit space
1223 ;;; after you execute it.
1224 ;;; - Added functions comint-send-string, comint-send-region and var
1225 ;;; comint-input-chunk-size. comint-send-string tries to prevent processes
1226 ;;; from hanging when you send them long strings by breaking them into
1227 ;;; chunks and allowing process output between chunks. I got the idea from
1228 ;;; Eero Simoncelli's Common Lisp package. Note that using
1229 ;;; comint-send-string means that the process buffer's contents can change
1230 ;;; during a call! If you depend on process output only happening between
1231 ;;; toplevel commands, this could be a problem. In such a case, use
1232 ;;; process-send-string instead. If this is a problem for people, I'd like
1233 ;;; to hear about it.
1234 ;;; - Added comint-proc-query as a simple mechanism for commands that
1235 ;;; want to query an inferior process and display its response. For a
1236 ;;; typical use, see lisp-show-arglist in cmulisp.el.
1237 ;;; - Added constant comint-version, which is now "2.01".
1240 ;;; - Had comint-update-env defined twice. Removed extra copy. Also
1241 ;;; renamed mem to be comint-mem, for modularity. The duplication
1242 ;;; was reported by Michael Meissner.
1244 ;;; - Emacs has two different mechanisms for maintaining the process
1245 ;;; environment, determined at compile time by the MAINTAIN-ENVIRONMENT
1246 ;;; #define. One uses the process-environment global variable, and
1247 ;;; one uses a getenv/setenv interface. comint-exec assumed the
1248 ;;; process-environment interface; it has been generalised (with
1249 ;;; comint-exec-1) to handle both cases. Pretty bogus. We could,
1250 ;;; of course, skip all this and just use the etc/env program to
1251 ;;; handle the environment tweaking, but that obscures process
1252 ;;; queries that other modules (like background.el) depend on. etc/env
1253 ;;; is also fairly bogus. This bug, and some of the fix code was
1254 ;;; reported by Dan Pierson.
1257 ;;; - Changed make-variable-buffer-local's to make-local-variable's.
1258 ;;; This leaves non-comint-mode buffers alone. Stephane Payrard
1259 ;;; reported the sloppy useage.
1260 ;;; - You can now go from comint-previous-similar-input to
1261 ;;; comint-previous-input with no problem.
1263 ;;; 12/21/90 shivers
1264 ;;; - Added a condition-case to comint-get-source. Bogus strings
1265 ;;; beginning with ~ were making the file-exists-p barf.
1266 ;;; - Added "=" to the set of chars recognised by file completion
1267 ;;; as constituting a filename.
1270 ;;; These changes comprise release 2.02:
1271 ;;; - Removed the kill-all-local-variables in comint-mode. This
1272 ;;; made it impossible for client modes to set things before calling
1273 ;;; comint-mode. (In particular, it messed up ilisp.el) In general,
1274 ;;; the client mode should be responsible for a k-a-l-v's.
1275 ;;; - Fixed comint-match-partial-pathname so that it works in
1276 ;;; more cases: if the filename begins at the start-of-buffer;
1277 ;;; if point is on the first char of the filename. Just a question
1278 ;;; of getting the tricky bits right.
1279 ;;; - Added a hook, comint-exec-hook that is run each time a process
1280 ;;; is cranked up. Useful for things like process-kill-without-query.
1282 ;;; These two were pointed out by tale:
1283 ;;; - Improved the doc string in comint-send-input a little bit.
1284 ;;; - Tweaked make-comint to check process status with comint-check-proc
1285 ;;; instead of equivalent inline code.
1287 ;;; - Prompt-search history commands have been commented out. I never
1288 ;;; liked them; I don't think anyone used them.
1289 ;;; - Made comint-exec-hook a local var, as it should have been.
1290 ;;; (This way, for instance, you can have cmushell procs kill-w/o-query,
1291 ;;; but let Scheme procs be default.)
1294 ;;; - Souped up comint-read-noecho with an optional argument, STARS.
1295 ;;; Suggested by mjlx@EAGLE.CNSF.CORNELL.EDU.
1296 ;;; - Moved comint-previous-input-matching from C-c r to C-M-r.
1297 ;;; C-c <letter> bindings are reserved for the user.
1298 ;;; These bindings were done by Jim Blandy.
1299 ;;; These changes comprise version 2.03.
1303 ;;; comint.el ends here