Comment change.
[emacs.git] / lisp / comint.el
blob2be96265d02ef28da8515c9e19c886cd863849ac
1 ;;; comint.el --- general command interpreter in a window stuff
3 ;; Copyright (C) 1988, 90, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
5 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
6 ;; Adapted-by: Simon Marshall <simon@gnu.ai.mit.edu>
7 ;; Keywords: processes
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;; Please send me bug reports, bug fixes, and extensions, so that I can
29 ;; merge them into the master source.
30 ;; - Olin Shivers (shivers@cs.cmu.edu)
31 ;; - Simon Marshall (simon@gnu.ai.mit.edu)
33 ;; This file defines a general command-interpreter-in-a-buffer package
34 ;; (comint mode). The idea is that you can build specific process-in-a-buffer
35 ;; modes on top of comint mode -- e.g., lisp, shell, scheme, T, soar, ....
36 ;; This way, all these specific packages share a common base functionality,
37 ;; and a common set of bindings, which makes them easier to use (and
38 ;; saves code, implementation time, etc., etc.).
40 ;; Several packages are already defined using comint mode:
41 ;; - shell.el defines a shell-in-a-buffer mode.
42 ;; - cmulisp.el defines a simple lisp-in-a-buffer mode.
44 ;; - The file cmuscheme.el defines a scheme-in-a-buffer mode.
45 ;; - The file tea.el tunes scheme and inferior-scheme modes for T.
46 ;; - The file soar.el tunes lisp and inferior-lisp modes for Soar.
47 ;; - cmutex.el defines tex and latex modes that invoke tex, latex, bibtex,
48 ;; previewers, and printers from within emacs.
49 ;; - background.el allows csh-like job control inside emacs.
50 ;; It is pretty easy to make new derived modes for other processes.
52 ;; For documentation on the functionality provided by comint mode, and
53 ;; the hooks available for customising it, see the comments below.
54 ;; For further information on the standard derived modes (shell,
55 ;; inferior-lisp, inferior-scheme, ...), see the relevant source files.
57 ;; For hints on converting existing process modes (e.g., tex-mode,
58 ;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode
59 ;; instead of shell-mode, see the notes at the end of this file.
62 ;; Brief Command Documentation:
63 ;;============================================================================
64 ;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp
65 ;; mode)
67 ;; m-p comint-previous-input Cycle backwards in input history
68 ;; m-n comint-next-input Cycle forwards
69 ;; m-r comint-previous-matching-input Previous input matching a regexp
70 ;; m-s comint-next-matching-input Next input that matches
71 ;; m-c-l comint-show-output Show last batch of process output
72 ;; return comint-send-input
73 ;; c-d comint-delchar-or-maybe-eof Delete char unless at end of buff
74 ;; c-c c-a comint-bol Beginning of line; skip prompt
75 ;; c-c c-u comint-kill-input ^u
76 ;; c-c c-w backward-kill-word ^w
77 ;; c-c c-c comint-interrupt-subjob ^c
78 ;; c-c c-z comint-stop-subjob ^z
79 ;; c-c c-\ comint-quit-subjob ^\
80 ;; c-c c-o comint-kill-output Delete last batch of process output
81 ;; c-c c-r comint-show-output Show last batch of process output
82 ;; c-c c-l comint-dynamic-list-input-ring List input history
84 ;; Not bound by default in comint-mode (some are in shell mode)
85 ;; comint-run Run a program under comint-mode
86 ;; send-invisible Read a line w/o echo, and send to proc
87 ;; comint-dynamic-complete-filename Complete filename at point.
88 ;; comint-dynamic-complete-variable Complete variable name at point.
89 ;; comint-dynamic-list-filename-completions List completions in help buffer.
90 ;; comint-replace-by-expanded-filename Expand and complete filename at point;
91 ;; replace with expanded/completed name.
92 ;; comint-replace-by-expanded-history Expand history at point;
93 ;; replace with expanded name.
94 ;; comint-magic-space Expand history and add (a) space(s).
95 ;; comint-kill-subjob No mercy.
96 ;; comint-show-maximum-output Show as much output as possible.
97 ;; comint-continue-subjob Send CONT signal to buffer's process
98 ;; group. Useful if you accidentally
99 ;; suspend your process (with C-c C-z).
101 ;; comint-mode-hook is the comint mode hook. Basically for your keybindings.
103 ;;; Code:
105 (require 'ring)
107 ;; Buffer Local Variables:
108 ;;============================================================================
109 ;; Comint mode buffer local variables:
110 ;; comint-prompt-regexp string comint-bol uses to match prompt
111 ;; comint-delimiter-argument-list list For delimiters and arguments
112 ;; comint-last-input-start marker Handy if inferior always echoes
113 ;; comint-last-input-end marker For comint-kill-output command
114 ;; comint-input-ring-size integer For the input history
115 ;; comint-input-ring ring mechanism
116 ;; comint-input-ring-index number ...
117 ;; comint-input-autoexpand symbol ...
118 ;; comint-input-ignoredups boolean ...
119 ;; comint-last-input-match string ...
120 ;; comint-dynamic-complete-functions hook For the completion mechanism
121 ;; comint-completion-fignore list ...
122 ;; comint-file-name-chars string ...
123 ;; comint-file-name-quote-list list ...
124 ;; comint-get-old-input function Hooks for specific
125 ;; comint-input-filter-functions hook process-in-a-buffer
126 ;; comint-output-filter-functions hook function modes.
127 ;; comint-input-filter function ...
128 ;; comint-input-sender function ...
129 ;; comint-eol-on-send boolean ...
130 ;; comint-process-echoes boolean ...
131 ;; comint-scroll-to-bottom-on-input symbol For scroll behavior
132 ;; comint-scroll-to-bottom-on-output symbol ...
133 ;; comint-scroll-show-maximum-output boolean ...
135 ;; Comint mode non-buffer local variables:
136 ;; comint-completion-addsuffix boolean/cons For file name
137 ;; comint-completion-autolist boolean completion behavior
138 ;; comint-completion-recexact boolean ...
140 (defvar comint-prompt-regexp "^"
141 "Regexp to recognise prompts in the inferior process.
142 Defaults to \"^\", the null string at BOL.
144 Good choices:
145 Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
146 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
147 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
148 kcl: \"^>+ *\"
149 shell: \"^[^#$%>\\n]*[#$%>] *\"
150 T: \"^>+ *\"
152 This is a good thing to set in mode hooks.")
154 (defvar comint-delimiter-argument-list ()
155 "List of characters to recognise as separate arguments in input.
156 Strings comprising a character in this list will separate the arguments
157 surrounding them, and also be regarded as arguments in their own right (unlike
158 whitespace). See `comint-arguments'.
159 Defaults to the empty list.
161 For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?;).
163 This is a good thing to set in mode hooks.")
165 (defvar comint-input-autoexpand nil
166 "*If non-nil, expand input command history references on completion.
167 This mirrors the optional behavior of tcsh (its autoexpand and histlit).
169 If the value is `input', then the expansion is seen on input.
170 If the value is `history', then the expansion is only when inserting
171 into the buffer's input ring. See also `comint-magic-space' and
172 `comint-dynamic-complete'.
174 This variable is buffer-local.")
176 (defvar comint-input-ignoredups nil
177 "*If non-nil, don't add input matching the last on the input ring.
178 This mirrors the optional behavior of bash.
180 This variable is buffer-local.")
182 (defvar comint-input-ring-file-name nil
183 "*If non-nil, name of the file to read/write input history.
184 See also `comint-read-input-ring' and `comint-write-input-ring'.
186 This variable is buffer-local, and is a good thing to set in mode hooks.")
188 (defvar comint-scroll-to-bottom-on-input nil
189 "*Controls whether input to interpreter causes window to scroll.
190 If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
191 If `this', scroll only the selected window.
193 The default is nil.
195 See `comint-preinput-scroll-to-bottom'. This variable is buffer-local.")
197 (defvar comint-scroll-to-bottom-on-output nil
198 "*Controls whether interpreter output causes window to scroll.
199 If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
200 If `this', scroll only the selected window.
201 If `others', scroll only those that are not the selected window.
203 The default is nil.
205 See variable `comint-scroll-show-maximum-output' and function
206 `comint-postoutput-scroll-to-bottom'. This variable is buffer-local.")
208 (defvar comint-scroll-show-maximum-output nil
209 "*Controls how interpreter output causes window to scroll.
210 If non-nil, then show the maximum output when the window is scrolled.
212 See variable `comint-scroll-to-bottom-on-output' and function
213 `comint-postoutput-scroll-to-bottom'. This variable is buffer-local.")
215 (defvar comint-buffer-maximum-size 1024
216 "*The maximum size in lines for comint buffers.
217 Comint buffers are truncated from the top to be no greater than this number, if
218 the function `comint-truncate-buffer' is on `comint-output-filter-functions'.")
220 (defvar comint-input-ring-size 32
221 "Size of input history ring.")
223 (defvar comint-process-echoes nil
224 "*If non-nil, assume that the subprocess echoes any input.
225 If so, delete one copy of the input so that only one copy eventually
226 appears in the buffer.
228 This variable is buffer-local.")
230 (defvar comint-password-prompt-regexp
231 "\\(\\([Oo]ld \\|[Nn]ew \\|'s \\|^\\)[Pp]assword\\|pass phrase\\):\\s *\\'"
232 "*Regexp matching prompts for passwords in the inferior process.
233 This is used by `comint-watch-for-password-prompt'.")
235 ;; Here are the per-interpreter hooks.
236 (defvar comint-get-old-input (function comint-get-old-input-default)
237 "Function that returns old text in comint mode.
238 This function is called when return is typed while the point is in old text.
239 It returns the text to be submitted as process input. The default is
240 `comint-get-old-input-default', which grabs the current line, and strips off
241 leading text matching `comint-prompt-regexp'.")
243 (defvar comint-dynamic-complete-functions
244 '(comint-replace-by-expanded-history comint-dynamic-complete-filename)
245 "List of functions called to perform completion.
246 Functions should return non-nil if completion was performed.
247 See also `comint-dynamic-complete'.
249 This is a good thing to set in mode hooks.")
251 (defvar comint-input-filter
252 (function (lambda (str) (not (string-match "\\`\\s *\\'" str))))
253 "Predicate for filtering additions to input history.
254 Takes one argument, the input. If non-nil, the input may be saved on the input
255 history list. Default is to save anything that isn't all whitespace.")
257 (defvar comint-input-filter-functions '()
258 "Functions to call before input is sent to the process.
259 These functions get one argument, a string containing the text to send.
261 This variable is buffer-local.")
263 (defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom)
264 "Functions to call after output is inserted into the buffer.
265 One possible function is `comint-postoutput-scroll-to-bottom'.
266 These functions get one argument, a string containing the text as originally
267 inserted. Note that this might not be the same as the buffer contents between
268 `comint-last-output-start' and the buffer's `process-mark', if other filter
269 functions have already modified the buffer.
271 This variable is buffer-local.")
273 (defvar comint-input-sender (function comint-simple-send)
274 "Function to actually send to PROCESS the STRING submitted by user.
275 Usually this is just `comint-simple-send', but if your mode needs to
276 massage the input string, put a different function here.
277 `comint-simple-send' just sends the string plus a newline.
278 This is called from the user command `comint-send-input'.")
280 (defvar comint-eol-on-send t
281 "*Non-nil means go to the end of the line before sending input.
282 See `comint-send-input'.")
284 (defvar comint-mode-hook '()
285 "Called upon entry into comint-mode
286 This is run before the process is cranked up.")
288 (defvar comint-exec-hook '()
289 "Called each time a process is exec'd by `comint-exec'.
290 This is called after the process is cranked up. It is useful for things that
291 must be done each time a process is executed in a comint mode buffer (e.g.,
292 `(process-kill-without-query)'). In contrast, the `comint-mode-hook' is only
293 executed once when the buffer is created.")
295 (defvar comint-mode-map nil)
297 (defvar comint-ptyp t
298 "Non-nil if communications via pty; false if by pipe. Buffer local.
299 This is to work around a bug in Emacs process signaling.")
301 (defvar comint-input-ring nil)
302 (defvar comint-last-input-start)
303 (defvar comint-last-input-end)
304 (defvar comint-last-output-start)
305 (defvar comint-input-ring-index nil
306 "Index of last matched history element.")
307 (defvar comint-matching-input-from-input-string ""
308 "Input previously used to match input history.")
310 (put 'comint-replace-by-expanded-history 'menu-enable 'comint-input-autoexpand)
311 (put 'comint-input-ring 'permanent-local t)
312 (put 'comint-input-ring-index 'permanent-local t)
313 (put 'comint-input-autoexpand 'permanent-local t)
314 (put 'comint-input-filter-functions 'permanent-local t)
315 (put 'comint-output-filter-functions 'permanent-local t)
316 (put 'comint-scroll-to-bottom-on-input 'permanent-local t)
317 (put 'comint-scroll-to-bottom-on-output 'permanent-local t)
318 (put 'comint-scroll-show-maximum-output 'permanent-local t)
319 (put 'comint-ptyp 'permanent-local t)
321 (defun comint-mode ()
322 "Major mode for interacting with an inferior interpreter.
323 Interpreter name is same as buffer name, sans the asterisks.
324 Return at end of buffer sends line as input.
325 Return not at end copies rest of line to end and sends it.
326 Setting variable `comint-eol-on-send' means jump to the end of the line
327 before submitting new input.
329 This mode is customised to create major modes such as Inferior Lisp
330 mode, Shell mode, etc. This can be done by setting the hooks
331 `comint-input-filter-functions', `comint-input-filter', `comint-input-sender'
332 and `comint-get-old-input' to appropriate functions, and the variable
333 `comint-prompt-regexp' to the appropriate regular expression.
335 An input history is maintained of size `comint-input-ring-size', and
336 can be accessed with the commands \\[comint-next-input], \\[comint-previous-input], and \\[comint-dynamic-list-input-ring].
337 Input ring history expansion can be achieved with the commands
338 \\[comint-replace-by-expanded-history] or \\[comint-magic-space].
339 Input ring expansion is controlled by the variable `comint-input-autoexpand',
340 and addition is controlled by the variable `comint-input-ignoredups'.
342 Commands with no default key bindings include `send-invisible',
343 `comint-dynamic-complete', `comint-dynamic-list-filename-completions', and
344 `comint-magic-space'.
346 Input to, and output from, the subprocess can cause the window to scroll to
347 the end of the buffer. See variables `comint-output-filter-functions',
348 `comint-scroll-to-bottom-on-input', and `comint-scroll-to-bottom-on-output'.
350 If you accidentally suspend your process, use \\[comint-continue-subjob]
351 to continue it.
353 \\{comint-mode-map}
355 Entry to this mode runs the hooks on `comint-mode-hook'."
356 (interactive)
357 ;; Do not remove this. All major modes must do this.
358 (kill-all-local-variables)
359 (setq major-mode 'comint-mode)
360 (setq mode-name "Comint")
361 (setq mode-line-process '(":%s"))
362 (use-local-map comint-mode-map)
363 (make-local-variable 'comint-last-input-start)
364 (setq comint-last-input-start (make-marker))
365 (set-marker comint-last-input-start (point-min))
366 (make-local-variable 'comint-last-input-end)
367 (setq comint-last-input-end (make-marker))
368 (set-marker comint-last-input-end (point-min))
369 (make-local-variable 'comint-last-output-start)
370 (setq comint-last-output-start (make-marker))
371 (make-local-variable 'comint-prompt-regexp) ; Don't set; default
372 (make-local-variable 'comint-input-ring-size) ; ...to global val.
373 (make-local-variable 'comint-input-ring)
374 (make-local-variable 'comint-input-ring-file-name)
375 (or (and (boundp 'comint-input-ring) comint-input-ring)
376 (setq comint-input-ring (make-ring comint-input-ring-size)))
377 (make-local-variable 'comint-input-ring-index)
378 (or (and (boundp 'comint-input-ring-index) comint-input-ring-index)
379 (setq comint-input-ring-index nil))
380 (make-local-variable 'comint-matching-input-from-input-string)
381 (make-local-variable 'comint-input-autoexpand)
382 (make-local-variable 'comint-input-ignoredups)
383 (make-local-variable 'comint-delimiter-argument-list)
384 (make-local-hook 'comint-dynamic-complete-functions)
385 (make-local-variable 'comint-completion-fignore)
386 (make-local-variable 'comint-get-old-input)
387 (make-local-hook 'comint-input-filter-functions)
388 (make-local-variable 'comint-input-filter)
389 (make-local-variable 'comint-input-sender)
390 (make-local-variable 'comint-eol-on-send)
391 (make-local-variable 'comint-scroll-to-bottom-on-input)
392 (make-local-variable 'comint-scroll-to-bottom-on-output)
393 (make-local-variable 'comint-scroll-show-maximum-output)
394 (make-local-variable 'pre-command-hook)
395 (add-hook 'pre-command-hook 'comint-preinput-scroll-to-bottom)
396 (make-local-hook 'comint-output-filter-functions)
397 (make-local-variable 'comint-ptyp)
398 (make-local-variable 'comint-exec-hook)
399 (make-local-variable 'comint-process-echoes)
400 (make-local-variable 'comint-file-name-chars)
401 (make-local-variable 'comint-file-name-quote-list)
402 (run-hooks 'comint-mode-hook))
404 (if comint-mode-map
406 ;; Keys:
407 (setq comint-mode-map (make-sparse-keymap))
408 (define-key comint-mode-map "\ep" 'comint-previous-input)
409 (define-key comint-mode-map "\en" 'comint-next-input)
410 (define-key comint-mode-map [C-up] 'comint-previous-input)
411 (define-key comint-mode-map [C-down] 'comint-next-input)
412 (define-key comint-mode-map "\er" 'comint-previous-matching-input)
413 (define-key comint-mode-map "\es" 'comint-next-matching-input)
414 (define-key comint-mode-map [?\A-\M-r] 'comint-previous-matching-input-from-input)
415 (define-key comint-mode-map [?\A-\M-s] 'comint-next-matching-input-from-input)
416 (define-key comint-mode-map "\e\C-l" 'comint-show-output)
417 (define-key comint-mode-map "\C-m" 'comint-send-input)
418 (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
419 (define-key comint-mode-map "\C-c\C-a" 'comint-bol)
420 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input)
421 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word)
422 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob)
423 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob)
424 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob)
425 (define-key comint-mode-map "\C-c\C-m" 'comint-copy-old-input)
426 (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output)
427 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
428 (define-key comint-mode-map "\C-c\C-e" 'comint-show-maximum-output)
429 (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring)
430 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt)
431 (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt)
432 (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof)
433 ;; Menu bars:
434 ;; completion:
435 (define-key comint-mode-map [menu-bar completion]
436 (cons "Complete" (make-sparse-keymap "Complete")))
437 (define-key comint-mode-map [menu-bar completion complete-expand]
438 '("Expand File Name" . comint-replace-by-expanded-filename))
439 (define-key comint-mode-map [menu-bar completion complete-listing]
440 '("File Completion Listing" . comint-dynamic-list-filename-completions))
441 (define-key comint-mode-map [menu-bar completion complete-file]
442 '("Complete File Name" . comint-dynamic-complete-filename))
443 (define-key comint-mode-map [menu-bar completion complete]
444 '("Complete Before Point" . comint-dynamic-complete))
445 ;; Input history:
446 (define-key comint-mode-map [menu-bar inout]
447 (cons "In/Out" (make-sparse-keymap "In/Out")))
448 (define-key comint-mode-map [menu-bar inout kill-output]
449 '("Kill Current Output Group" . comint-kill-output))
450 (define-key comint-mode-map [menu-bar inout next-prompt]
451 '("Forward Output Group" . comint-next-prompt))
452 (define-key comint-mode-map [menu-bar inout previous-prompt]
453 '("Backward Output Group" . comint-previous-prompt))
454 (define-key comint-mode-map [menu-bar inout show-maximum-output]
455 '("Show Maximum Output" . comint-show-maximum-output))
456 (define-key comint-mode-map [menu-bar inout show-output]
457 '("Show Current Output Group" . comint-show-output))
458 (define-key comint-mode-map [menu-bar inout kill-input]
459 '("Kill Current Input" . comint-kill-input))
460 (define-key comint-mode-map [menu-bar inout copy-input]
461 '("Copy Old Input" . comint-copy-old-input))
462 (define-key comint-mode-map [menu-bar inout forward-matching-history]
463 '("Forward Matching Input..." . comint-forward-matching-input))
464 (define-key comint-mode-map [menu-bar inout backward-matching-history]
465 '("Backward Matching Input..." . comint-backward-matching-input))
466 (define-key comint-mode-map [menu-bar inout next-matching-history]
467 '("Next Matching Input..." . comint-next-matching-input))
468 (define-key comint-mode-map [menu-bar inout previous-matching-history]
469 '("Previous Matching Input..." . comint-previous-matching-input))
470 (define-key comint-mode-map [menu-bar inout next-matching-history-from-input]
471 '("Next Matching Current Input" . comint-next-matching-input-from-input))
472 (define-key comint-mode-map [menu-bar inout previous-matching-history-from-input]
473 '("Previous Matching Current Input" . comint-previous-matching-input-from-input))
474 (define-key comint-mode-map [menu-bar inout next-history]
475 '("Next Input" . comint-next-input))
476 (define-key comint-mode-map [menu-bar inout previous-history]
477 '("Previous Input" . comint-previous-input))
478 (define-key comint-mode-map [menu-bar inout list-history]
479 '("List Input History" . comint-dynamic-list-input-ring))
480 (define-key comint-mode-map [menu-bar inout expand-history]
481 '("Expand History Before Point" . comint-replace-by-expanded-history))
482 ;; Signals
483 (define-key comint-mode-map [menu-bar signals]
484 (cons "Signals" (make-sparse-keymap "Signals")))
485 (define-key comint-mode-map [menu-bar signals eof]
486 '("EOF" . comint-send-eof))
487 (define-key comint-mode-map [menu-bar signals kill]
488 '("KILL" . comint-kill-subjob))
489 (define-key comint-mode-map [menu-bar signals quit]
490 '("QUIT" . comint-quit-subjob))
491 (define-key comint-mode-map [menu-bar signals cont]
492 '("CONT" . comint-continue-subjob))
493 (define-key comint-mode-map [menu-bar signals stop]
494 '("STOP" . comint-stop-subjob))
495 (define-key comint-mode-map [menu-bar signals break]
496 '("BREAK" . comint-interrupt-subjob))
497 ;; Put them in the menu bar:
498 (setq menu-bar-final-items (append '(completion inout signals)
499 menu-bar-final-items))
502 (defun comint-check-proc (buffer)
503 "Return t if there is a living process associated w/buffer BUFFER.
504 Living means the status is `open', `run', or `stop'.
505 BUFFER can be either a buffer or the name of one."
506 (let ((proc (get-buffer-process buffer)))
507 (and proc (memq (process-status proc) '(open run stop)))))
509 ;;;###autoload
510 (defun make-comint (name program &optional startfile &rest switches)
511 "Make a comint process NAME in a buffer, running PROGRAM.
512 The name of the buffer is made by surrounding NAME with `*'s.
513 PROGRAM should be either a string denoting an executable program to create
514 via `start-process', or a cons pair of the form (HOST . SERVICE) denoting a TCP
515 connection to be opened via `open-network-stream'. If there is already a
516 running process in that buffer, it is not restarted. Optional third arg
517 STARTFILE is the name of a file to send the contents of to the process.
519 If PROGRAM is a string, any more args are arguments to PROGRAM."
520 (or (fboundp 'start-process)
521 (error "Multi-processing is not supported for this system"))
522 (let ((buffer (get-buffer-create (concat "*" name "*"))))
523 ;; If no process, or nuked process, crank up a new one and put buffer in
524 ;; comint mode. Otherwise, leave buffer and existing process alone.
525 (cond ((not (comint-check-proc buffer))
526 (save-excursion
527 (set-buffer buffer)
528 (comint-mode)) ; Install local vars, mode, keymap, ...
529 (comint-exec buffer name program startfile switches)))
530 buffer))
532 ;;;###autoload
533 (defun comint-run (program)
534 "Run PROGRAM in a comint buffer and switch to it.
535 The buffer name is made by surrounding the file name of PROGRAM with `*'s.
536 The file name is used to make a symbol name, such as `comint-sh-hook', and any
537 hooks on this symbol are run in the buffer.
538 See `make-comint' and `comint-exec'."
539 (interactive "sRun program: ")
540 (let ((name (file-name-nondirectory program)))
541 (switch-to-buffer (make-comint name program))
542 (run-hooks (intern-soft (concat "comint-" name "-hook")))))
544 (defun comint-exec (buffer name command startfile switches)
545 "Start up a process in buffer BUFFER for comint modes.
546 Blasts any old process running in the buffer. Doesn't set the buffer mode.
547 You can use this to cheaply run a series of processes in the same comint
548 buffer. The hook `comint-exec-hook' is run after each exec."
549 (save-excursion
550 (set-buffer buffer)
551 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
552 (if proc (delete-process proc)))
553 ;; Crank up a new process
554 (let ((proc
555 (if (consp command)
556 (open-network-stream name buffer (car command) (cdr command))
557 (comint-exec-1 name buffer command switches))))
558 (set-process-filter proc 'comint-output-filter)
559 (make-local-variable 'comint-ptyp)
560 (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe.
561 ;; Jump to the end, and set the process mark.
562 (goto-char (point-max))
563 (set-marker (process-mark proc) (point))
564 ;; Feed it the startfile.
565 (cond (startfile
566 ;;This is guaranteed to wait long enough
567 ;;but has bad results if the comint does not prompt at all
568 ;; (while (= size (buffer-size))
569 ;; (sleep-for 1))
570 ;;I hope 1 second is enough!
571 (sleep-for 1)
572 (goto-char (point-max))
573 (insert-file-contents startfile)
574 (setq startfile (buffer-substring (point) (point-max)))
575 (delete-region (point) (point-max))
576 (comint-send-string proc startfile)))
577 (run-hooks 'comint-exec-hook)
578 buffer)))
580 ;; This auxiliary function cranks up the process for comint-exec in
581 ;; the appropriate environment.
583 (defun comint-exec-1 (name buffer command switches)
584 (let ((process-environment
585 (nconc
586 ;; If using termcap, we specify `emacs' as the terminal type
587 ;; because that lets us specify a width.
588 ;; If using terminfo, we specify `dumb' because that is
589 ;; a defined terminal type. `emacs' is not a defined terminal type
590 ;; and there is no way for us to define it here.
591 ;; Some programs that use terminfo get very confused
592 ;; if TERM is not a valid terminal type.
593 (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
594 (list "TERM=dumb" "TERMCAP="
595 (format "COLUMNS=%d" (frame-width)))
596 (list "TERM=emacs"
597 (format "TERMCAP=emacs:co#%d:tc=unknown:" (frame-width))))
598 (if (getenv "EMACS") nil (list "EMACS=t"))
599 process-environment))
600 (default-directory
601 (if (file-accessible-directory-p default-directory)
602 default-directory
603 "/")))
604 (apply 'start-process name buffer command switches)))
606 ;; Input history processing in a buffer
607 ;; ===========================================================================
608 ;; Useful input history functions, courtesy of the Ergo group.
610 ;; Eleven commands:
611 ;; comint-dynamic-list-input-ring List history in help buffer.
612 ;; comint-previous-input Previous input...
613 ;; comint-previous-matching-input ...matching a string.
614 ;; comint-previous-matching-input-from-input ... matching the current input.
615 ;; comint-next-input Next input...
616 ;; comint-next-matching-input ...matching a string.
617 ;; comint-next-matching-input-from-input ... matching the current input.
618 ;; comint-backward-matching-input Backwards input...
619 ;; comint-forward-matching-input ...matching a string.
620 ;; comint-replace-by-expanded-history Expand history at point;
621 ;; replace with expanded history.
622 ;; comint-magic-space Expand history and insert space.
624 ;; Three functions:
625 ;; comint-read-input-ring Read into comint-input-ring...
626 ;; comint-write-input-ring Write to comint-input-ring-file-name.
627 ;; comint-replace-by-expanded-history-before-point Workhorse function.
629 (defun comint-read-input-ring (&optional silent)
630 "Sets the buffer's `comint-input-ring' from a history file.
631 The name of the file is given by the variable `comint-input-ring-file-name'.
632 The history ring is of size `comint-input-ring-size', regardless of file size.
633 If `comint-input-ring-file-name' is nil this function does nothing.
635 If the optional argument SILENT is non-nil, we say nothing about a
636 failure to read the history file.
638 This function is useful for major mode commands and mode hooks.
640 The structure of the history file should be one input command per line,
641 with the most recent command last.
642 See also `comint-input-ignoredups' and `comint-write-input-ring'."
643 (cond ((or (null comint-input-ring-file-name)
644 (equal comint-input-ring-file-name ""))
645 nil)
646 ((not (file-readable-p comint-input-ring-file-name))
647 (or silent
648 (message "Cannot read history file %s"
649 comint-input-ring-file-name)))
651 (let ((history-buf (get-buffer-create " *temp*"))
652 (file comint-input-ring-file-name)
653 (count 0)
654 (ring (make-ring comint-input-ring-size)))
655 (unwind-protect
656 (save-excursion
657 (set-buffer history-buf)
658 (widen)
659 (erase-buffer)
660 (insert-file-contents file)
661 ;; Save restriction in case file is already visited...
662 ;; Watch for those date stamps in history files!
663 (goto-char (point-max))
664 (while (and (< count comint-input-ring-size)
665 (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$"
666 nil t))
667 (let ((history (buffer-substring (match-beginning 1)
668 (match-end 1))))
669 (if (or (null comint-input-ignoredups)
670 (ring-empty-p ring)
671 (not (string-equal (ring-ref ring 0) history)))
672 (ring-insert-at-beginning ring history)))
673 (setq count (1+ count))))
674 (kill-buffer history-buf))
675 (setq comint-input-ring ring
676 comint-input-ring-index nil)))))
678 (defun comint-write-input-ring ()
679 "Writes the buffer's `comint-input-ring' to a history file.
680 The name of the file is given by the variable `comint-input-ring-file-name'.
681 The original contents of the file are lost if `comint-input-ring' is not empty.
682 If `comint-input-ring-file-name' is nil this function does nothing.
684 Useful within process sentinels.
686 See also `comint-read-input-ring'."
687 (cond ((or (null comint-input-ring-file-name)
688 (equal comint-input-ring-file-name "")
689 (null comint-input-ring) (ring-empty-p comint-input-ring))
690 nil)
691 ((not (file-writable-p comint-input-ring-file-name))
692 (message "Cannot write history file %s" comint-input-ring-file-name))
694 (let* ((history-buf (get-buffer-create " *Temp Input History*"))
695 (ring comint-input-ring)
696 (file comint-input-ring-file-name)
697 (index (ring-length ring)))
698 ;; Write it all out into a buffer first. Much faster, but messier,
699 ;; than writing it one line at a time.
700 (save-excursion
701 (set-buffer history-buf)
702 (erase-buffer)
703 (while (> index 0)
704 (setq index (1- index))
705 (insert (ring-ref ring index) ?\n))
706 (write-region (buffer-string) nil file nil 'no-message)
707 (kill-buffer nil))))))
710 (defun comint-dynamic-list-input-ring ()
711 "List in help buffer the buffer's input history."
712 (interactive)
713 (if (or (not (ring-p comint-input-ring))
714 (ring-empty-p comint-input-ring))
715 (message "No history")
716 (let ((history nil)
717 (history-buffer " *Input History*")
718 (index (1- (ring-length comint-input-ring)))
719 (conf (current-window-configuration)))
720 ;; We have to build up a list ourselves from the ring vector.
721 (while (>= index 0)
722 (setq history (cons (ring-ref comint-input-ring index) history)
723 index (1- index)))
724 ;; Change "completion" to "history reference"
725 ;; to make the display accurate.
726 (with-output-to-temp-buffer history-buffer
727 (display-completion-list history)
728 (set-buffer history-buffer)
729 (forward-line 3)
730 (while (search-backward "completion" nil 'move)
731 (replace-match "history reference")))
732 (sit-for 0)
733 (message "Hit space to flush")
734 (let ((ch (read-event)))
735 (if (eq ch ?\ )
736 (set-window-configuration conf)
737 (setq unread-command-events (list ch)))))))
740 (defun comint-regexp-arg (prompt)
741 ;; Return list of regexp and prefix arg using PROMPT.
742 (let* ((minibuffer-history-sexp-flag nil)
743 ;; Don't clobber this.
744 (last-command last-command)
745 (regexp (read-from-minibuffer prompt nil nil nil
746 'minibuffer-history-search-history)))
747 (list (if (string-equal regexp "")
748 (setcar minibuffer-history-search-history
749 (nth 1 minibuffer-history-search-history))
750 regexp)
751 (prefix-numeric-value current-prefix-arg))))
753 (defun comint-search-arg (arg)
754 ;; First make sure there is a ring and that we are after the process mark
755 (cond ((not (comint-after-pmark-p))
756 (error "Not at command line"))
757 ((or (null comint-input-ring)
758 (ring-empty-p comint-input-ring))
759 (error "Empty input ring"))
760 ((zerop arg)
761 ;; arg of zero resets search from beginning, and uses arg of 1
762 (setq comint-input-ring-index nil)
765 arg)))
767 (defun comint-search-start (arg)
768 ;; Index to start a directional search, starting at comint-input-ring-index
769 (if comint-input-ring-index
770 ;; If a search is running, offset by 1 in direction of arg
771 (mod (+ comint-input-ring-index (if (> arg 0) 1 -1))
772 (ring-length comint-input-ring))
773 ;; For a new search, start from beginning or end, as appropriate
774 (if (>= arg 0)
775 0 ; First elt for forward search
776 (1- (ring-length comint-input-ring))))) ; Last elt for backward search
778 (defun comint-previous-input-string (arg)
779 "Return the string ARG places along the input ring.
780 Moves relative to `comint-input-ring-index'."
781 (ring-ref comint-input-ring (if comint-input-ring-index
782 (mod (+ arg comint-input-ring-index)
783 (ring-length comint-input-ring))
784 arg)))
786 (defun comint-previous-input (arg)
787 "Cycle backwards through input history."
788 (interactive "*p")
789 (comint-previous-matching-input "." arg))
791 (defun comint-next-input (arg)
792 "Cycle forwards through input history."
793 (interactive "*p")
794 (comint-previous-input (- arg)))
796 (defun comint-previous-matching-input-string (regexp arg)
797 "Return the string matching REGEXP ARG places along the input ring.
798 Moves relative to `comint-input-ring-index'."
799 (let* ((pos (comint-previous-matching-input-string-position regexp arg)))
800 (if pos (ring-ref comint-input-ring pos))))
802 (defun comint-previous-matching-input-string-position (regexp arg &optional start)
803 "Return the index matching REGEXP ARG places along the input ring.
804 Moves relative to START, or `comint-input-ring-index'."
805 (if (or (not (ring-p comint-input-ring))
806 (ring-empty-p comint-input-ring))
807 (error "No history"))
808 (let* ((len (ring-length comint-input-ring))
809 (motion (if (> arg 0) 1 -1))
810 (n (mod (- (or start (comint-search-start arg)) motion) len))
811 (tried-each-ring-item nil)
812 (prev nil))
813 ;; Do the whole search as many times as the argument says.
814 (while (and (/= arg 0) (not tried-each-ring-item))
815 ;; Step once.
816 (setq prev n
817 n (mod (+ n motion) len))
818 ;; If we haven't reached a match, step some more.
819 (while (and (< n len) (not tried-each-ring-item)
820 (not (string-match regexp (ring-ref comint-input-ring n))))
821 (setq n (mod (+ n motion) len)
822 ;; If we have gone all the way around in this search.
823 tried-each-ring-item (= n prev)))
824 (setq arg (if (> arg 0) (1- arg) (1+ arg))))
825 ;; Now that we know which ring element to use, if we found it, return that.
826 (if (string-match regexp (ring-ref comint-input-ring n))
827 n)))
829 (defun comint-previous-matching-input (regexp arg)
830 "Search backwards through input history for match for REGEXP.
831 \(Previous history elements are earlier commands.)
832 With prefix argument N, search for Nth previous match.
833 If N is negative, find the next or Nth next match."
834 (interactive (comint-regexp-arg "Previous input matching (regexp): "))
835 (setq arg (comint-search-arg arg))
836 (let ((pos (comint-previous-matching-input-string-position regexp arg)))
837 ;; Has a match been found?
838 (if (null pos)
839 (error "Not found")
840 (setq comint-input-ring-index pos)
841 (message "History item: %d" (1+ pos))
842 (delete-region
843 ;; Can't use kill-region as it sets this-command
844 (process-mark (get-buffer-process (current-buffer))) (point))
845 (insert (ring-ref comint-input-ring pos)))))
847 (defun comint-next-matching-input (regexp arg)
848 "Search forwards through input history for match for REGEXP.
849 \(Later history elements are more recent commands.)
850 With prefix argument N, search for Nth following match.
851 If N is negative, find the previous or Nth previous match."
852 (interactive (comint-regexp-arg "Next input matching (regexp): "))
853 (comint-previous-matching-input regexp (- arg)))
855 (defun comint-previous-matching-input-from-input (arg)
856 "Search backwards through input history for match for current input.
857 \(Previous history elements are earlier commands.)
858 With prefix argument N, search for Nth previous match.
859 If N is negative, search forwards for the -Nth following match."
860 (interactive "p")
861 (if (not (memq last-command '(comint-previous-matching-input-from-input
862 comint-next-matching-input-from-input)))
863 ;; Starting a new search
864 (setq comint-matching-input-from-input-string
865 (buffer-substring
866 (process-mark (get-buffer-process (current-buffer)))
867 (point))
868 comint-input-ring-index nil))
869 (comint-previous-matching-input
870 (concat "^" (regexp-quote comint-matching-input-from-input-string))
871 arg))
873 (defun comint-next-matching-input-from-input (arg)
874 "Search forwards through input history for match for current input.
875 \(Following history elements are more recent commands.)
876 With prefix argument N, search for Nth following match.
877 If N is negative, search backwards for the -Nth previous match."
878 (interactive "p")
879 (comint-previous-matching-input-from-input (- arg)))
882 (defun comint-replace-by-expanded-history (&optional silent)
883 "Expand input command history references before point.
884 Expansion is dependent on the value of `comint-input-autoexpand'.
886 This function depends on the buffer's idea of the input history, which may not
887 match the command interpreter's idea, assuming it has one.
889 Assumes history syntax is like typical Un*x shells'. However, since emacs
890 cannot know the interpreter's idea of input line numbers, assuming it has one,
891 it cannot expand absolute input line number references.
893 If the optional argument SILENT is non-nil, never complain
894 even if history reference seems erroneous.
896 See `comint-magic-space' and `comint-replace-by-expanded-history-before-point'.
898 Returns t if successful."
899 (interactive)
900 (if (and comint-input-autoexpand
901 (string-match "!\\|^\\^" (funcall comint-get-old-input))
902 (save-excursion (beginning-of-line)
903 (looking-at comint-prompt-regexp)))
904 ;; Looks like there might be history references in the command.
905 (let ((previous-modified-tick (buffer-modified-tick)))
906 (message "Expanding history references...")
907 (comint-replace-by-expanded-history-before-point silent)
908 (/= previous-modified-tick (buffer-modified-tick)))))
911 (defun comint-replace-by-expanded-history-before-point (silent)
912 "Expand directory stack reference before point.
913 See `comint-replace-by-expanded-history'. Returns t if successful."
914 (save-excursion
915 (let ((toend (- (save-excursion (end-of-line nil) (point)) (point)))
916 (start (progn (comint-bol nil) (point))))
917 (while (progn
918 (skip-chars-forward "^!^"
919 (save-excursion
920 (end-of-line nil) (- (point) toend)))
921 (< (point)
922 (save-excursion
923 (end-of-line nil) (- (point) toend))))
924 ;; This seems a bit complex. We look for references such as !!, !-num,
925 ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^.
926 ;; If that wasn't enough, the plings can be suffixed with argument
927 ;; range specifiers.
928 ;; Argument ranges are complex too, so we hive off the input line,
929 ;; referenced with plings, with the range string to `comint-args'.
930 (setq comint-input-ring-index nil)
931 (cond ((or (= (preceding-char) ?\\)
932 (comint-within-quotes start (point)))
933 ;; The history is quoted, or we're in quotes.
934 (goto-char (1+ (point))))
935 ((looking-at "![0-9]+\\($\\|[^-]\\)")
936 ;; We cannot know the interpreter's idea of input line numbers.
937 (goto-char (match-end 0))
938 (message "Absolute reference cannot be expanded"))
939 ((looking-at "!-\\([0-9]+\\)\\(:?[0-9^$*-]+\\)?")
940 ;; Just a number of args from `number' lines backward.
941 (let ((number (1- (string-to-number
942 (buffer-substring (match-beginning 1)
943 (match-end 1))))))
944 (if (<= number (ring-length comint-input-ring))
945 (progn
946 (replace-match
947 (comint-args (comint-previous-input-string number)
948 (match-beginning 2) (match-end 2))
949 t t)
950 (setq comint-input-ring-index number)
951 (message "History item: %d" (1+ number)))
952 (goto-char (match-end 0))
953 (message "Relative reference exceeds input history size"))))
954 ((or (looking-at "!!?:?\\([0-9^$*-]+\\)") (looking-at "!!"))
955 ;; Just a number of args from the previous input line.
956 (replace-match
957 (comint-args (comint-previous-input-string 0)
958 (match-beginning 1) (match-end 1))
959 t t)
960 (message "History item: previous"))
961 ((looking-at
962 "!\\??\\({\\(.+\\)}\\|\\(\\sw+\\)\\)\\(:?[0-9^$*-]+\\)?")
963 ;; Most recent input starting with or containing (possibly
964 ;; protected) string, maybe just a number of args. Phew.
965 (let* ((mb1 (match-beginning 1)) (me1 (match-end 1))
966 (mb2 (match-beginning 2)) (me2 (match-end 2))
967 (exp (buffer-substring (or mb2 mb1) (or me2 me1)))
968 (pref (if (save-match-data (looking-at "!\\?")) "" "^"))
969 (pos (save-match-data
970 (comint-previous-matching-input-string-position
971 (concat pref (regexp-quote exp)) 1))))
972 (if (null pos)
973 (progn
974 (goto-char (match-end 0))
975 (or silent
976 (progn (message "Not found")
977 (ding))))
978 (setq comint-input-ring-index pos)
979 (replace-match
980 (comint-args (ring-ref comint-input-ring pos)
981 (match-beginning 4) (match-end 4))
982 t t)
983 (message "History item: %d" (1+ pos)))))
984 ((looking-at "\\^\\([^^]+\\)\\^?\\([^^]*\\)\\^?")
985 ;; Quick substitution on the previous input line.
986 (let ((old (buffer-substring (match-beginning 1) (match-end 1)))
987 (new (buffer-substring (match-beginning 2) (match-end 2)))
988 (pos nil))
989 (replace-match (comint-previous-input-string 0) t t)
990 (setq pos (point))
991 (goto-char (match-beginning 0))
992 (if (not (search-forward old pos t))
993 (or silent
994 (error "Not found"))
995 (replace-match new t t)
996 (message "History item: substituted"))))
998 (goto-char (match-end 0))))))))
1001 (defun comint-magic-space (arg)
1002 "Expand input history references before point and insert ARG spaces.
1003 A useful command to bind to SPC. See `comint-replace-by-expanded-history'."
1004 (interactive "p")
1005 (comint-replace-by-expanded-history)
1006 (self-insert-command arg))
1008 (defun comint-within-quotes (beg end)
1009 "Return t if the number of quotes between BEG and END is odd.
1010 Quotes are single and double."
1011 (let ((countsq (comint-how-many-region "\\(^\\|[^\\\\]\\)\'" beg end))
1012 (countdq (comint-how-many-region "\\(^\\|[^\\\\]\\)\"" beg end)))
1013 (or (= (mod countsq 2) 1) (= (mod countdq 2) 1))))
1015 (defun comint-how-many-region (regexp beg end)
1016 "Return number of matches for REGEXP from BEG to END."
1017 (let ((count 0))
1018 (save-excursion
1019 (save-match-data
1020 (goto-char beg)
1021 (while (re-search-forward regexp end t)
1022 (setq count (1+ count)))))
1023 count))
1025 (defun comint-args (string begin end)
1026 ;; From STRING, return the args depending on the range specified in the text
1027 ;; from BEGIN to END. If BEGIN is nil, assume all args. Ignore leading `:'.
1028 ;; Range can be x-y, x-, -y, where x/y can be [0-9], *, ^, $.
1029 (save-match-data
1030 (if (null begin)
1031 (comint-arguments string 0 nil)
1032 (let* ((range (buffer-substring
1033 (if (eq (char-after begin) ?:) (1+ begin) begin) end))
1034 (nth (cond ((string-match "^[*^]" range) 1)
1035 ((string-match "^-" range) 0)
1036 ((string-equal range "$") nil)
1037 (t (string-to-number range))))
1038 (mth (cond ((string-match "[-*$]$" range) nil)
1039 ((string-match "-" range)
1040 (string-to-number (substring range (match-end 0))))
1041 (t nth))))
1042 (comint-arguments string nth mth)))))
1044 ;; Return a list of arguments from ARG. Break it up at the
1045 ;; delimiters in comint-delimiter-argument-list. Returned list is backwards.
1046 (defun comint-delim-arg (arg)
1047 (if (null comint-delimiter-argument-list)
1048 (list arg)
1049 (let ((args nil)
1050 (pos 0)
1051 (len (length arg)))
1052 (while (< pos len)
1053 (let ((char (aref arg pos))
1054 (start pos))
1055 (if (memq char comint-delimiter-argument-list)
1056 (while (and (< pos len) (eq (aref arg pos) char))
1057 (setq pos (1+ pos)))
1058 (while (and (< pos len)
1059 (not (memq (aref arg pos)
1060 comint-delimiter-argument-list)))
1061 (setq pos (1+ pos))))
1062 (setq args (cons (substring arg start pos) args))))
1063 args)))
1065 (defun comint-arguments (string nth mth)
1066 "Return from STRING the NTH to MTH arguments.
1067 NTH and/or MTH can be nil, which means the last argument.
1068 Returned arguments are separated by single spaces.
1069 We assume whitespace separates arguments, except within quotes.
1070 Also, a run of one or more of a single character
1071 in `comint-delimiter-argument-list' is a separate argument.
1072 Argument 0 is the command name."
1073 (let ((argpart "[^ \n\t\"'`]+\\|\\(\"[^\"]*\"\\|'[^']*'\\|`[^`]*`\\)")
1074 (args ()) (pos 0)
1075 (count 0)
1076 beg str value quotes)
1077 ;; Build a list of all the args until we have as many as we want.
1078 (while (and (or (null mth) (<= count mth))
1079 (string-match argpart string pos))
1080 (if (and beg (= pos (match-beginning 0)))
1081 ;; It's contiguous, part of the same arg.
1082 (setq pos (match-end 0)
1083 quotes (or quotes (match-beginning 1)))
1084 ;; It's a new separate arg.
1085 (if beg
1086 ;; Put the previous arg, if there was one, onto ARGS.
1087 (setq str (substring string beg pos)
1088 args (if quotes (cons str args)
1089 (nconc (comint-delim-arg str) args))
1090 count (1+ count)))
1091 (setq quotes (match-beginning 1))
1092 (setq beg (match-beginning 0))
1093 (setq pos (match-end 0))))
1094 (if beg
1095 (setq str (substring string beg pos)
1096 args (if quotes (cons str args)
1097 (nconc (comint-delim-arg str) args))
1098 count (1+ count)))
1099 (let ((n (or nth (1- count)))
1100 (m (if mth (1- (- count mth)) 0)))
1101 (mapconcat
1102 (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " "))))
1105 ;; Input processing stuff
1108 (defun comint-send-input ()
1109 "Send input to process.
1110 After the process output mark, sends all text from the process mark to
1111 point as input to the process. Before the process output mark, calls value
1112 of variable `comint-get-old-input' to retrieve old input, copies it to the
1113 process mark, and sends it. If variable `comint-process-echoes' is nil,
1114 a terminal newline is also inserted into the buffer and sent to the process
1115 \(if it is non-nil, all text from the process mark to point is deleted,
1116 since it is assumed the remote process will re-echo it).
1118 Any history reference may be expanded depending on the value of the variable
1119 `comint-input-autoexpand'. The list of function names contained in the value
1120 of `comint-input-filter-functions' is called on the input before sending it.
1121 The input is entered into the input history ring, if the value of variable
1122 `comint-input-filter' returns non-nil when called on the input.
1124 If variable `comint-eol-on-send' is non-nil, then point is moved to the
1125 end of line before sending the input.
1127 The values of `comint-get-old-input', `comint-input-filter-functions', and
1128 `comint-input-filter' are chosen according to the command interpreter running
1129 in the buffer. E.g.,
1131 If the interpreter is the csh,
1132 comint-get-old-input is the default: take the current line, discard any
1133 initial string matching regexp comint-prompt-regexp.
1134 comint-input-filter-functions monitors input for \"cd\", \"pushd\", and
1135 \"popd\" commands. When it sees one, it cd's the buffer.
1136 comint-input-filter is the default: returns t if the input isn't all white
1137 space.
1139 If the comint is Lucid Common Lisp,
1140 comint-get-old-input snarfs the sexp ending at point.
1141 comint-input-filter-functions does nothing.
1142 comint-input-filter returns nil if the input matches input-filter-regexp,
1143 which matches (1) all whitespace (2) :a, :c, etc.
1145 Similarly for Soar, Scheme, etc."
1146 (interactive)
1147 ;; Note that the input string does not include its terminal newline.
1148 (let ((proc (get-buffer-process (current-buffer))))
1149 (if (not proc) (error "Current buffer has no process")
1150 (let* ((pmark (process-mark proc))
1151 (intxt (if (>= (point) (marker-position pmark))
1152 (progn (if comint-eol-on-send (end-of-line))
1153 (buffer-substring pmark (point)))
1154 (let ((copy (funcall comint-get-old-input)))
1155 (goto-char pmark)
1156 (insert copy)
1157 copy)))
1158 (input (if (not (eq comint-input-autoexpand 'input))
1159 ;; Just whatever's already there
1160 intxt
1161 ;; Expand and leave it visible in buffer
1162 (comint-replace-by-expanded-history t)
1163 (buffer-substring pmark (point))))
1164 (history (if (not (eq comint-input-autoexpand 'history))
1165 input
1166 ;; This is messy 'cos ultimately the original
1167 ;; functions used do insertion, rather than return
1168 ;; strings. We have to expand, then insert back.
1169 (comint-replace-by-expanded-history t)
1170 (let ((copy (buffer-substring pmark (point))))
1171 (delete-region pmark (point))
1172 (insert-before-markers input)
1173 copy))))
1174 (if comint-process-echoes
1175 (delete-region pmark (point))
1176 (insert-before-markers ?\n))
1177 (if (and (funcall comint-input-filter history)
1178 (or (null comint-input-ignoredups)
1179 (not (ring-p comint-input-ring))
1180 (ring-empty-p comint-input-ring)
1181 (not (string-equal (ring-ref comint-input-ring 0)
1182 history))))
1183 (ring-insert comint-input-ring history))
1184 (run-hook-with-args 'comint-input-filter-functions
1185 (concat input "\n"))
1186 (setq comint-input-ring-index nil)
1187 ;; Update the markers before we send the input
1188 ;; in case we get output amidst sending the input.
1189 (set-marker comint-last-input-start pmark)
1190 (set-marker comint-last-input-end (point))
1191 (set-marker (process-mark proc) (point))
1192 (funcall comint-input-sender proc input)
1193 ;; This used to call comint-output-filter-functions,
1194 ;; but that scrolled the buffer in undesirable ways.
1195 (run-hook-with-args 'comint-output-filter-functions "")))))
1197 ;; The purpose of using this filter for comint processes
1198 ;; is to keep comint-last-input-end from moving forward
1199 ;; when output is inserted.
1200 (defun comint-output-filter (process string)
1201 ;; First check for killed buffer
1202 (let ((oprocbuf (process-buffer process)))
1203 (if (and oprocbuf (buffer-name oprocbuf))
1204 (let ((obuf (current-buffer))
1205 (opoint nil) (obeg nil) (oend nil))
1206 (set-buffer oprocbuf)
1207 (setq opoint (point))
1208 (setq obeg (point-min))
1209 (setq oend (point-max))
1210 (let ((buffer-read-only nil)
1211 (nchars (length string))
1212 (ostart nil))
1213 (widen)
1214 (goto-char (process-mark process))
1215 (setq ostart (point))
1216 (if (<= (point) opoint)
1217 (setq opoint (+ opoint nchars)))
1218 ;; Insert after old_begv, but before old_zv.
1219 (if (< (point) obeg)
1220 (setq obeg (+ obeg nchars)))
1221 (if (<= (point) oend)
1222 (setq oend (+ oend nchars)))
1223 (insert-before-markers string)
1224 ;; Don't insert initial prompt outside the top of the window.
1225 (if (= (window-start (selected-window)) (point))
1226 (set-window-start (selected-window) (- (point) (length string))))
1227 (if (and comint-last-input-end
1228 (marker-buffer comint-last-input-end)
1229 (= (point) comint-last-input-end))
1230 (set-marker comint-last-input-end (- comint-last-input-end nchars)))
1231 (set-marker comint-last-output-start ostart)
1232 (set-marker (process-mark process) (point))
1233 (force-mode-line-update))
1235 (narrow-to-region obeg oend)
1236 (goto-char opoint)
1237 (run-hook-with-args 'comint-output-filter-functions string)
1238 (set-buffer obuf)))))
1240 (defun comint-preinput-scroll-to-bottom ()
1241 "Go to the end of buffer in all windows showing it.
1242 Movement occurs if point in the selected window is not after the process mark,
1243 and `this-command' is an insertion command. Insertion commands recognised
1244 are `self-insert-command', `comint-magic-space', `yank', and `hilit-yank'.
1245 Depends on the value of `comint-scroll-to-bottom-on-input'.
1247 This function should be a pre-command hook."
1248 (if (and comint-scroll-to-bottom-on-input
1249 (memq this-command '(self-insert-command comint-magic-space yank
1250 hilit-yank)))
1251 (let* ((selected (selected-window))
1252 (current (current-buffer))
1253 (process (get-buffer-process current))
1254 (scroll comint-scroll-to-bottom-on-input))
1255 (if (and process (< (point) (process-mark process)))
1256 (if (eq scroll 'this)
1257 (goto-char (point-max))
1258 (walk-windows
1259 (function (lambda (window)
1260 (if (and (eq (window-buffer window) current)
1261 (or (eq scroll t) (eq scroll 'all)))
1262 (progn
1263 (select-window window)
1264 (goto-char (point-max))
1265 (select-window selected)))))
1266 nil t))))))
1268 (defun comint-postoutput-scroll-to-bottom (string)
1269 "Go to the end of buffer in all windows showing it.
1270 Does not scroll if the current line is the last line in the buffer.
1271 Depends on the value of `comint-scroll-to-bottom-on-output' and
1272 `comint-scroll-show-maximum-output'.
1274 This function should be in the list `comint-output-filter-functions'."
1275 (let* ((selected (selected-window))
1276 (current (current-buffer))
1277 (process (get-buffer-process current))
1278 (scroll comint-scroll-to-bottom-on-output))
1279 (unwind-protect
1280 (if process
1281 (walk-windows
1282 (function (lambda (window)
1283 (if (eq (window-buffer window) current)
1284 (progn
1285 (select-window window)
1286 (if (and (< (point) (process-mark process))
1287 (or (eq scroll t) (eq scroll 'all)
1288 ;; Maybe user wants point to jump to end.
1289 (and (eq scroll 'this) (eq selected window))
1290 (and (eq scroll 'others) (not (eq selected window)))
1291 ;; If point was at the end, keep it at end.
1292 (>= (point) comint-last-output-start)))
1293 (goto-char (process-mark process)))
1294 ;; Optionally scroll so that the text
1295 ;; ends at the bottom of the window.
1296 (if (and comint-scroll-show-maximum-output
1297 (>= (point) (process-mark process)))
1298 (save-excursion
1299 (goto-char (point-max))
1300 (recenter -1)))
1301 (select-window selected)))))
1302 nil t))
1303 (set-buffer current))))
1305 (defun comint-truncate-buffer (&optional string)
1306 "Truncate the buffer to `comint-buffer-maximum-size'.
1307 This function could be on `comint-output-filter-functions' or bound to a key."
1308 (interactive)
1309 (save-excursion
1310 (goto-char (process-mark (get-buffer-process (current-buffer))))
1311 (forward-line (- comint-buffer-maximum-size))
1312 (beginning-of-line)
1313 (delete-region (point-min) (point))))
1315 (defun comint-strip-ctrl-m (&optional string)
1316 "Strip trailing `^M' characters from the current output group.
1317 This function could be on `comint-output-filter-functions' or bound to a key."
1318 (interactive)
1319 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
1320 (save-excursion
1321 (goto-char
1322 (if (interactive-p) comint-last-input-end comint-last-output-start))
1323 (while (re-search-forward "\r+$" pmark t)
1324 (replace-match "" t t)))))
1325 (defalias 'shell-strip-ctrl-m 'comint-strip-ctrl-m)
1327 (defun comint-show-maximum-output ()
1328 "Put the end of the buffer at the bottom of the window."
1329 (interactive)
1330 (goto-char (point-max))
1331 (recenter -1))
1333 (defun comint-get-old-input-default ()
1334 "Default for `comint-get-old-input'.
1335 Take the current line, and discard any initial text matching
1336 `comint-prompt-regexp'."
1337 (save-excursion
1338 (beginning-of-line)
1339 (comint-skip-prompt)
1340 (let ((beg (point)))
1341 (end-of-line)
1342 (buffer-substring beg (point)))))
1344 (defun comint-copy-old-input ()
1345 "Insert after prompt old input at point as new input to be edited.
1346 Calls `comint-get-old-input' to get old input."
1347 (interactive)
1348 (let ((input (funcall comint-get-old-input))
1349 (process (get-buffer-process (current-buffer))))
1350 (if (not process)
1351 (error "Current buffer has no process")
1352 (goto-char (process-mark process))
1353 (insert input))))
1355 (defun comint-skip-prompt ()
1356 "Skip past the text matching regexp `comint-prompt-regexp'.
1357 If this takes us past the end of the current line, don't skip at all."
1358 (let ((eol (save-excursion (end-of-line) (point))))
1359 (if (and (looking-at comint-prompt-regexp)
1360 (<= (match-end 0) eol))
1361 (goto-char (match-end 0)))))
1363 (defun comint-after-pmark-p ()
1364 "Return t if point is after the process output marker."
1365 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
1366 (<= (marker-position pmark) (point))))
1368 (defun comint-simple-send (proc string)
1369 "Default function for sending to PROC input STRING.
1370 This just sends STRING plus a newline. To override this,
1371 set the hook `comint-input-sender'."
1372 (comint-send-string proc string)
1373 (comint-send-string proc "\n"))
1375 (defun comint-bol (arg)
1376 "Goes to the beginning of line, then skips past the prompt, if any.
1377 If prefix argument is given (\\[universal-argument]) the prompt is not skipped.
1379 The prompt skip is done by skipping text matching the regular expression
1380 `comint-prompt-regexp', a buffer local variable."
1381 (interactive "P")
1382 (beginning-of-line)
1383 (if (null arg) (comint-skip-prompt)))
1385 ;; These three functions are for entering text you don't want echoed or
1386 ;; saved -- typically passwords to ftp, telnet, or somesuch.
1387 ;; Just enter m-x send-invisible and type in your line, or add
1388 ;; `comint-watch-for-password-prompt' to `comint-output-filter-functions'.
1390 (defun comint-read-noecho (prompt &optional stars)
1391 "Read a single line of text from user without echoing, and return it.
1392 Prompt with argument PROMPT, a string. Optional argument STARS causes
1393 input to be echoed with '*' characters on the prompt line. Input ends with
1394 RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if
1395 `inhibit-quit' is set because e.g. this function was called from a process
1396 filter and C-g is pressed, this function returns nil rather than a string).
1398 Note that the keystrokes comprising the text can still be recovered
1399 \(temporarily) with \\[view-lossage]. Some people find this worrysome.
1400 Once the caller uses the password, it can erase the password
1401 by doing (fillarray STRING 0)."
1402 (let ((ans "")
1403 (newans nil)
1404 (c 0)
1405 (echo-keystrokes 0)
1406 (cursor-in-echo-area t)
1407 (message-log-max nil)
1408 (done nil))
1409 (while (not done)
1410 (if stars
1411 (message "%s%s" prompt (make-string (length ans) ?*))
1412 (message "%s" prompt))
1413 ;; Use this instead of `read-char' to avoid "Non-character input-event".
1414 (setq c (read-char-exclusive))
1415 (cond ((= c ?\C-g)
1416 ;; This function may get called from a process filter, where
1417 ;; inhibit-quit is set. In later versions of emacs read-char
1418 ;; may clear quit-flag itself and return C-g. That would make
1419 ;; it impossible to quit this loop in a simple way, so
1420 ;; re-enable it here (for backward-compatibility the check for
1421 ;; quit-flag below would still be necessary, so this seems
1422 ;; like the simplest way to do things).
1423 (setq quit-flag t
1424 done t))
1425 ((or (= c ?\r) (= c ?\n) (= c ?\e))
1426 (setq done t))
1427 ((= c ?\C-u)
1428 (fillarray ans 0)
1429 (setq ans ""))
1430 ((and (/= c ?\b) (/= c ?\177))
1431 (setq newans (concat ans (char-to-string c)))
1432 (fillarray ans 0)
1433 (setq ans newans))
1434 ((> (length ans) 0)
1435 (aset ans (1- (length ans)) 0)
1436 (setq ans (substring ans 0 -1)))))
1437 (if quit-flag
1438 ;; Emulate a true quit, except that we have to return a value.
1439 (prog1
1440 (setq quit-flag nil)
1441 (message "Quit")
1442 (beep t))
1443 (message "")
1444 ans)))
1446 (defun send-invisible (str)
1447 "Read a string without echoing.
1448 Then send it to the process running in the current buffer.
1449 The string is sent using `comint-input-sender'.
1450 Security bug: your string can still be temporarily recovered with
1451 \\[view-lossage]."
1452 (interactive "P") ; Defeat snooping via C-x ESC ESC
1453 (let ((proc (get-buffer-process (current-buffer))))
1454 (cond ((not proc)
1455 (error "Current buffer has no process"))
1456 ((stringp str)
1457 (funcall comint-input-sender proc str))
1459 (let ((str (comint-read-noecho "Non-echoed text: " t)))
1460 (if (stringp str)
1461 (send-invisible str)
1462 (message "Warning: text will be echoed")))))))
1464 (defun comint-watch-for-password-prompt (string)
1465 "Prompt in the minibuffer for password and send without echoing.
1466 This function uses `send-invisible' to read and send a password to the buffer's
1467 process if STRING contains a password prompt defined by
1468 `comint-password-prompt-regexp'.
1470 This function could be in the list `comint-output-filter-functions'."
1471 (if (string-match comint-password-prompt-regexp string)
1472 (send-invisible nil)))
1474 ;; Low-level process communication
1476 (defalias 'comint-send-string 'process-send-string)
1477 (defalias 'comint-send-region 'process-send-region)
1479 ;; Random input hackage
1481 (defun comint-kill-output ()
1482 "Kill all output from interpreter since last input.
1483 Does not delete the prompt."
1484 (interactive)
1485 (let ((proc (get-buffer-process (current-buffer)))
1486 (replacement nil))
1487 (save-excursion
1488 (let ((pmark (progn (goto-char (process-mark proc))
1489 (beginning-of-line nil)
1490 (point-marker))))
1491 (delete-region comint-last-input-end pmark)
1492 (goto-char (process-mark proc))
1493 (setq replacement (concat "*** output flushed ***\n"
1494 (buffer-substring pmark (point))))
1495 (delete-region pmark (point))))
1496 ;; Output message and put back prompt
1497 (comint-output-filter proc replacement)))
1499 (defun comint-show-output ()
1500 "Display start of this batch of interpreter output at top of window.
1501 Sets mark to the value of point when this command is run."
1502 (interactive)
1503 (push-mark)
1504 (let ((pos (point)))
1505 (goto-char (or (marker-position comint-last-input-end) (point-max)))
1506 (beginning-of-line 0)
1507 (set-window-start (selected-window) (point))
1508 (comint-skip-prompt)))
1510 (defun comint-interrupt-subjob ()
1511 "Interrupt the current subjob."
1512 (interactive)
1513 (interrupt-process nil comint-ptyp))
1515 (defun comint-kill-subjob ()
1516 "Send kill signal to the current subjob."
1517 (interactive)
1518 (kill-process nil comint-ptyp))
1520 (defun comint-quit-subjob ()
1521 "Send quit signal to the current subjob."
1522 (interactive)
1523 (quit-process nil comint-ptyp))
1525 (defun comint-stop-subjob ()
1526 "Stop the current subjob.
1527 WARNING: if there is no current subjob, you can end up suspending
1528 the top-level process running in the buffer. If you accidentally do
1529 this, use \\[comint-continue-subjob] to resume the process. (This
1530 is not a problem with most shells, since they ignore this signal.)"
1531 (interactive)
1532 (stop-process nil comint-ptyp))
1534 (defun comint-continue-subjob ()
1535 "Send CONT signal to process buffer's process group.
1536 Useful if you accidentally suspend the top-level process."
1537 (interactive)
1538 (continue-process nil comint-ptyp))
1540 (defun comint-kill-input ()
1541 "Kill all text from last stuff output by interpreter to point."
1542 (interactive)
1543 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
1544 (if (> (point) (marker-position pmark))
1545 (kill-region pmark (point)))))
1547 (defun comint-delchar-or-maybe-eof (arg)
1548 "Delete ARG characters forward or send an EOF to subprocess.
1549 Sends an EOF only if point is at the end of the buffer and there is no input."
1550 (interactive "p")
1551 (let ((proc (get-buffer-process (current-buffer))))
1552 (if (and (eobp) proc (= (point) (marker-position (process-mark proc))))
1553 (process-send-eof)
1554 (delete-char arg))))
1556 (defun comint-send-eof ()
1557 "Send an EOF to the current buffer's process."
1558 (interactive)
1559 (process-send-eof))
1562 (defun comint-backward-matching-input (regexp arg)
1563 "Search backward through buffer for match for REGEXP.
1564 Matches are searched for on lines that match `comint-prompt-regexp'.
1565 With prefix argument N, search for Nth previous match.
1566 If N is negative, find the next or Nth next match."
1567 (interactive (comint-regexp-arg "Backward input matching (regexp): "))
1568 (let* ((re (concat comint-prompt-regexp ".*" regexp))
1569 (pos (save-excursion (end-of-line (if (> arg 0) 0 1))
1570 (if (re-search-backward re nil t arg)
1571 (point)))))
1572 (if (null pos)
1573 (progn (message "Not found")
1574 (ding))
1575 (goto-char pos)
1576 (comint-bol nil))))
1578 (defun comint-forward-matching-input (regexp arg)
1579 "Search forward through buffer for match for REGEXP.
1580 Matches are searched for on lines that match `comint-prompt-regexp'.
1581 With prefix argument N, search for Nth following match.
1582 If N is negative, find the previous or Nth previous match."
1583 (interactive (comint-regexp-arg "Forward input matching (regexp): "))
1584 (comint-backward-matching-input regexp (- arg)))
1587 (defun comint-next-prompt (n)
1588 "Move to end of Nth next prompt in the buffer.
1589 See `comint-prompt-regexp'."
1590 (interactive "p")
1591 (let ((paragraph-start comint-prompt-regexp))
1592 (end-of-line (if (> n 0) 1 0))
1593 (forward-paragraph n)
1594 (comint-skip-prompt)))
1596 (defun comint-previous-prompt (n)
1597 "Move to end of Nth previous prompt in the buffer.
1598 See `comint-prompt-regexp'."
1599 (interactive "p")
1600 (comint-next-prompt (- n)))
1602 ;; Support for source-file processing commands.
1603 ;;============================================================================
1604 ;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
1605 ;; commands that process files of source text (e.g. loading or compiling
1606 ;; files). So the corresponding process-in-a-buffer modes have commands
1607 ;; for doing this (e.g., lisp-load-file). The functions below are useful
1608 ;; for defining these commands.
1610 ;; Alas, these guys don't do exactly the right thing for Lisp, Scheme
1611 ;; and Soar, in that they don't know anything about file extensions.
1612 ;; So the compile/load interface gets the wrong default occasionally.
1613 ;; The load-file/compile-file default mechanism could be smarter -- it
1614 ;; doesn't know about the relationship between filename extensions and
1615 ;; whether the file is source or executable. If you compile foo.lisp
1616 ;; with compile-file, then the next load-file should use foo.bin for
1617 ;; the default, not foo.lisp. This is tricky to do right, particularly
1618 ;; because the extension for executable files varies so much (.o, .bin,
1619 ;; .lbin, .mo, .vo, .ao, ...).
1622 ;; COMINT-SOURCE-DEFAULT -- determines defaults for source-file processing
1623 ;; commands.
1625 ;; COMINT-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you
1626 ;; want to save the buffer before issuing any process requests to the command
1627 ;; interpreter.
1629 ;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt
1630 ;; for the file to process.
1632 ;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes)
1633 ;;============================================================================
1634 ;; This function computes the defaults for the load-file and compile-file
1635 ;; commands for tea, soar, cmulisp, and cmuscheme modes.
1637 ;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
1638 ;; source-file processing command. NIL if there hasn't been one yet.
1639 ;; - SOURCE-MODES is a list used to determine what buffers contain source
1640 ;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
1641 ;; Typically, (lisp-mode) or (scheme-mode).
1643 ;; If the command is given while the cursor is inside a string, *and*
1644 ;; the string is an existing filename, *and* the filename is not a directory,
1645 ;; then the string is taken as default. This allows you to just position
1646 ;; your cursor over a string that's a filename and have it taken as default.
1648 ;; If the command is given in a file buffer whose major mode is in
1649 ;; SOURCE-MODES, then the the filename is the default file, and the
1650 ;; file's directory is the default directory.
1652 ;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
1653 ;; then the default directory & file are what was used in the last source-file
1654 ;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
1655 ;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
1656 ;; is the cwd, with no default file. (\"no default file\" = nil)
1658 ;; SOURCE-REGEXP is typically going to be something like (tea-mode)
1659 ;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
1660 ;; for Soar programs, etc.
1662 ;; The function returns a pair: (default-directory . default-file).
1664 (defun comint-source-default (previous-dir/file source-modes)
1665 (cond ((and buffer-file-name (memq major-mode source-modes))
1666 (cons (file-name-directory buffer-file-name)
1667 (file-name-nondirectory buffer-file-name)))
1668 (previous-dir/file)
1670 (cons default-directory nil))))
1673 ;; (COMINT-CHECK-SOURCE fname)
1674 ;;============================================================================
1675 ;; Prior to loading or compiling (or otherwise processing) a file (in the CMU
1676 ;; process-in-a-buffer modes), this function can be called on the filename.
1677 ;; If the file is loaded into a buffer, and the buffer is modified, the user
1678 ;; is queried to see if he wants to save the buffer before proceeding with
1679 ;; the load or compile.
1681 (defun comint-check-source (fname)
1682 (let ((buff (get-file-buffer fname)))
1683 (if (and buff
1684 (buffer-modified-p buff)
1685 (y-or-n-p (format "Save buffer %s first? " (buffer-name buff))))
1686 ;; save BUFF.
1687 (let ((old-buffer (current-buffer)))
1688 (set-buffer buff)
1689 (save-buffer)
1690 (set-buffer old-buffer)))))
1693 ;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
1694 ;;============================================================================
1695 ;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter
1696 ;; commands that process source files (like loading or compiling a file).
1697 ;; It prompts for the filename, provides a default, if there is one,
1698 ;; and returns the result filename.
1700 ;; See COMINT-SOURCE-DEFAULT for more on determining defaults.
1702 ;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
1703 ;; from the last source processing command. SOURCE-MODES is a list of major
1704 ;; modes used to determine what file buffers contain source files. (These
1705 ;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
1706 ;; then the filename reader will only accept a file that exists.
1708 ;; A typical use:
1709 ;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file
1710 ;; '(lisp-mode) t))
1712 ;; This is pretty stupid about strings. It decides we're in a string
1713 ;; if there's a quote on both sides of point on the current line.
1714 (defun comint-extract-string ()
1715 "Return string around POINT that starts the current line, or nil."
1716 (save-excursion
1717 (let* ((point (point))
1718 (bol (progn (beginning-of-line) (point)))
1719 (eol (progn (end-of-line) (point)))
1720 (start (progn (goto-char point)
1721 (and (search-backward "\"" bol t)
1722 (1+ (point)))))
1723 (end (progn (goto-char point)
1724 (and (search-forward "\"" eol t)
1725 (1- (point))))))
1726 (and start end
1727 (buffer-substring start end)))))
1729 (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p)
1730 (let* ((def (comint-source-default prev-dir/file source-modes))
1731 (stringfile (comint-extract-string))
1732 (sfile-p (and stringfile
1733 (condition-case ()
1734 (file-exists-p stringfile)
1735 (error nil))
1736 (not (file-directory-p stringfile))))
1737 (defdir (if sfile-p (file-name-directory stringfile)
1738 (car def)))
1739 (deffile (if sfile-p (file-name-nondirectory stringfile)
1740 (cdr def)))
1741 (ans (read-file-name (if deffile (format "%s(default %s) "
1742 prompt deffile)
1743 prompt)
1744 defdir
1745 (concat defdir deffile)
1746 mustmatch-p)))
1747 (list (expand-file-name (substitute-in-file-name ans)))))
1749 ;; I am somewhat divided on this string-default feature. It seems
1750 ;; to violate the principle-of-least-astonishment, in that it makes
1751 ;; the default harder to predict, so you actually have to look and see
1752 ;; what the default really is before choosing it. This can trip you up.
1753 ;; On the other hand, it can be useful, I guess. I would appreciate feedback
1754 ;; on this.
1755 ;; -Olin
1758 ;; Simple process query facility.
1759 ;; ===========================================================================
1760 ;; This function is for commands that want to send a query to the process
1761 ;; and show the response to the user. For example, a command to get the
1762 ;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
1763 ;; to an inferior Common Lisp process.
1765 ;; This simple facility just sends strings to the inferior process and pops
1766 ;; up a window for the process buffer so you can see what the process
1767 ;; responds with. We don't do anything fancy like try to intercept what the
1768 ;; process responds with and put it in a pop-up window or on the message
1769 ;; line. We just display the buffer. Low tech. Simple. Works good.
1771 ;; Send to the inferior process PROC the string STR. Pop-up but do not select
1772 ;; a window for the inferior process so that its response can be seen.
1773 (defun comint-proc-query (proc str)
1774 (let* ((proc-buf (process-buffer proc))
1775 (proc-mark (process-mark proc)))
1776 (display-buffer proc-buf)
1777 (set-buffer proc-buf) ; but it's not the selected *window*
1778 (let ((proc-win (get-buffer-window proc-buf))
1779 (proc-pt (marker-position proc-mark)))
1780 (comint-send-string proc str) ; send the query
1781 (accept-process-output proc) ; wait for some output
1782 ;; Try to position the proc window so you can see the answer.
1783 ;; This is bogus code. If you delete the (sit-for 0), it breaks.
1784 ;; I don't know why. Wizards invited to improve it.
1785 (if (not (pos-visible-in-window-p proc-pt proc-win))
1786 (let ((opoint (window-point proc-win)))
1787 (set-window-point proc-win proc-mark)
1788 (sit-for 0)
1789 (if (not (pos-visible-in-window-p opoint proc-win))
1790 (push-mark opoint)
1791 (set-window-point proc-win opoint)))))))
1794 ;; Filename/command/history completion in a buffer
1795 ;; ===========================================================================
1796 ;; Useful completion functions, courtesy of the Ergo group.
1798 ;; Six commands:
1799 ;; comint-dynamic-complete Complete or expand command, filename,
1800 ;; history at point.
1801 ;; comint-dynamic-complete-filename Complete filename at point.
1802 ;; comint-dynamic-list-filename-completions List completions in help buffer.
1803 ;; comint-replace-by-expanded-filename Expand and complete filename at point;
1804 ;; replace with expanded/completed name.
1805 ;; comint-dynamic-simple-complete Complete stub given candidates.
1807 ;; These are not installed in the comint-mode keymap. But they are
1808 ;; available for people who want them. Shell-mode installs them:
1809 ;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
1810 ;; (define-key shell-mode-map "\M-?"
1811 ;; 'comint-dynamic-list-filename-completions)))
1813 ;; Commands like this are fine things to put in load hooks if you
1814 ;; want them present in specific modes.
1816 (defvar comint-completion-autolist nil
1817 "*If non-nil, automatically list possibilities on partial completion.
1818 This mirrors the optional behavior of tcsh.")
1820 (defvar comint-completion-addsuffix t
1821 "*If non-nil, add a `/' to completed directories, ` ' to file names.
1822 If a cons pair, it should be of the form (DIRSUFFIX . FILESUFFIX) where
1823 DIRSUFFIX and FILESUFFIX are strings added on unambiguous or exact completion.
1824 This mirrors the optional behavior of tcsh.")
1826 (defvar comint-completion-recexact nil
1827 "*If non-nil, use shortest completion if characters cannot be added.
1828 This mirrors the optional behavior of tcsh.
1830 A non-nil value is useful if `comint-completion-autolist' is non-nil too.")
1832 (defvar comint-completion-fignore nil
1833 "*List of suffixes to be disregarded during file completion.
1834 This mirrors the optional behavior of bash and tcsh.
1836 Note that this applies to `comint-dynamic-complete-filename' only.")
1838 (defvar comint-file-name-prefix ""
1839 "Prefix prepended to absolute file names taken from process input.
1840 This is used by comint's and shell's completion functions, and by shell's
1841 directory tracking functions.")
1843 (defvar comint-file-name-chars
1844 (if (memq system-type '(ms-dos windows-nt))
1845 "~/A-Za-z0-9_^$!#%&{}@`'.()-"
1846 "~/A-Za-z0-9+@:_.$#%,={}-")
1847 "String of characters valid in a file name.
1849 This is a good thing to set in mode hooks.")
1851 (defvar comint-file-name-quote-list nil
1852 "List of characters to quote with `\\' when in a file name.
1854 This is a good thing to set in mode hooks.")
1857 (defun comint-directory (directory)
1858 ;; Return expanded DIRECTORY, with `comint-file-name-prefix' if absolute.
1859 (expand-file-name (if (file-name-absolute-p directory)
1860 (concat comint-file-name-prefix directory)
1861 directory)))
1864 (defun comint-word (word-chars)
1865 "Return the word of WORD-CHARS at point, or nil if non is found.
1866 Word constituents are considered to be those in WORD-CHARS, which is like the
1867 inside of a \"[...]\" (see `skip-chars-forward')."
1868 (save-excursion
1869 (let ((non-word-chars (concat "[^\\\\" word-chars "]")) (here (point)))
1870 (while (and (re-search-backward non-word-chars nil 'move)
1871 ;(memq (char-after (point)) shell-file-name-quote-list)
1872 (eq (preceding-char) ?\\))
1873 (backward-char 1))
1874 ;; Don't go forward over a word-char (this can happen if we're at bob).
1875 (if (or (not (bobp)) (looking-at non-word-chars))
1876 (forward-char 1))
1877 ;; Set match-data to match the entire string.
1878 (if (< (point) here)
1879 (progn (store-match-data (list (point) here))
1880 (match-string 0))))))
1882 (defun comint-substitute-in-file-name (filename)
1883 "Return FILENAME with environment variables substituted.
1884 Supports additional environment variable syntax of the command
1885 interpreter (e.g., the percent notation of cmd.exe on NT)."
1886 (let ((name (substitute-in-file-name filename)))
1887 (if (memq system-type '(ms-dos windows-nt))
1888 (let (env-var-name
1889 env-var-val)
1890 (save-match-data
1891 (while (string-match "%\\([^\\\\/]*\\)%" name)
1892 (setq env-var-name
1893 (substring name (match-beginning 1) (match-end 1)))
1894 (setq env-var-val (if (getenv env-var-name)
1895 (getenv env-var-name)
1896 ""))
1897 (setq name (replace-match env-var-val nil nil name))))))
1898 name))
1900 (defun comint-match-partial-filename ()
1901 "Return the filename at point, or nil if non is found.
1902 Environment variables are substituted. See `comint-word'."
1903 (let ((filename (comint-word comint-file-name-chars)))
1904 (and filename (comint-substitute-in-file-name
1905 (comint-unquote-filename filename)))))
1908 (defun comint-quote-filename (filename)
1909 "Return FILENAME with magic characters quoted.
1910 Magic characters are those in `comint-file-name-quote-list'."
1911 (if (null comint-file-name-quote-list)
1912 filename
1913 (let ((regexp
1914 (format "\\(^\\|[^\\]\\)\\([%s]\\)"
1915 (mapconcat 'char-to-string comint-file-name-quote-list ""))))
1916 (save-match-data
1917 (while (string-match regexp filename)
1918 (setq filename (replace-match "\\1\\\\\\2" nil nil filename)))
1919 filename))))
1921 (defun comint-unquote-filename (filename)
1922 "Return FILENAME with quoted characters unquoted."
1923 (if (null comint-file-name-quote-list)
1924 filename
1925 (save-match-data
1926 (let ((i 0))
1927 (while (string-match "\\\\\\(.\\)" filename i)
1928 (setq filename (replace-match "\\1" nil nil filename))
1929 (setq i (+ 1 (match-beginning 0)))))
1930 filename)))
1933 (defun comint-dynamic-complete ()
1934 "Dynamically perform completion at point.
1935 Calls the functions in `comint-dynamic-complete-functions' to perform
1936 completion until a function returns non-nil, at which point completion is
1937 assumed to have occurred."
1938 (interactive)
1939 (run-hook-with-args-until-success 'comint-dynamic-complete-functions))
1942 (defun comint-dynamic-complete-filename ()
1943 "Dynamically complete the filename at point.
1944 Completes if after a filename. See `comint-match-partial-filename' and
1945 `comint-dynamic-complete-as-filename'.
1946 This function is similar to `comint-replace-by-expanded-filename', except that
1947 it won't change parts of the filename already entered in the buffer; it just
1948 adds completion characters to the end of the filename. A completions listing
1949 may be shown in a help buffer if completion is ambiguous.
1951 Completion is dependent on the value of `comint-completion-addsuffix',
1952 `comint-completion-recexact' and `comint-completion-fignore', and the timing of
1953 completions listing is dependent on the value of `comint-completion-autolist'.
1955 Returns t if successful."
1956 (interactive)
1957 (if (comint-match-partial-filename)
1958 (let ((directory-sep-char (if (memq system-type '(ms-dos windows-nt))
1960 ?/)))
1961 (prog2 (or (window-minibuffer-p (selected-window))
1962 (message "Completing file name..."))
1963 (comint-dynamic-complete-as-filename)))))
1965 (defun comint-dynamic-complete-as-filename ()
1966 "Dynamically complete at point as a filename.
1967 See `comint-dynamic-complete-filename'. Returns t if successful."
1968 (let* ((completion-ignore-case (memq system-type '(ms-dos windows-nt)))
1969 (completion-ignored-extensions comint-completion-fignore)
1970 ;; If we bind this, it breaks remote directory tracking in rlogin.el.
1971 ;; I think it was originally bound to solve file completion problems,
1972 ;; but subsequent changes may have made this unnecessary. sm.
1973 ;;(file-name-handler-alist nil)
1974 (minibuffer-p (window-minibuffer-p (selected-window)))
1975 (success t)
1976 (dirsuffix (cond ((not comint-completion-addsuffix) "")
1977 ((not (consp comint-completion-addsuffix)) "/")
1978 (t (car comint-completion-addsuffix))))
1979 (filesuffix (cond ((not comint-completion-addsuffix) "")
1980 ((not (consp comint-completion-addsuffix)) " ")
1981 (t (cdr comint-completion-addsuffix))))
1982 (filename (or (comint-match-partial-filename) ""))
1983 (pathdir (file-name-directory filename))
1984 (pathnondir (file-name-nondirectory filename))
1985 (directory (if pathdir (comint-directory pathdir) default-directory))
1986 (completion (file-name-completion pathnondir directory)))
1987 (cond ((null completion)
1988 (message "No completions of %s" filename)
1989 (setq success nil))
1990 ((eq completion t) ; Means already completed "file".
1991 (insert filesuffix)
1992 (or minibuffer-p (message "Sole completion")))
1993 ((string-equal completion "") ; Means completion on "directory/".
1994 (comint-dynamic-list-filename-completions))
1995 (t ; Completion string returned.
1996 (let ((file (concat (file-name-as-directory directory) completion)))
1997 (insert (comint-quote-filename
1998 (substring (directory-file-name completion)
1999 (length pathnondir))))
2000 (cond ((symbolp (file-name-completion completion directory))
2001 ;; We inserted a unique completion.
2002 (insert (if (file-directory-p file) dirsuffix filesuffix))
2003 (or minibuffer-p (message "Completed")))
2004 ((and comint-completion-recexact comint-completion-addsuffix
2005 (string-equal pathnondir completion)
2006 (file-exists-p file))
2007 ;; It's not unique, but user wants shortest match.
2008 (insert (if (file-directory-p file) dirsuffix filesuffix))
2009 (or minibuffer-p (message "Completed shortest")))
2010 ((or comint-completion-autolist
2011 (string-equal pathnondir completion))
2012 ;; It's not unique, list possible completions.
2013 (comint-dynamic-list-filename-completions))
2015 (or minibuffer-p (message "Partially completed")))))))
2016 success))
2019 (defun comint-replace-by-expanded-filename ()
2020 "Dynamically expand and complete the filename at point.
2021 Replace the filename with an expanded, canonicalised and completed replacement.
2022 \"Expanded\" means environment variables (e.g., $HOME) and `~'s are replaced
2023 with the corresponding directories. \"Canonicalised\" means `..' and `.' are
2024 removed, and the filename is made absolute instead of relative. For expansion
2025 see `expand-file-name' and `substitute-in-file-name'. For completion see
2026 `comint-dynamic-complete-filename'."
2027 (interactive)
2028 (replace-match (expand-file-name (comint-match-partial-filename)) t t)
2029 (comint-dynamic-complete-filename))
2032 (defun comint-dynamic-simple-complete (stub candidates)
2033 "Dynamically complete STUB from CANDIDATES list.
2034 This function inserts completion characters at point by completing STUB from
2035 the strings in CANDIDATES. A completions listing may be shown in a help buffer
2036 if completion is ambiguous.
2038 Returns nil if no completion was inserted.
2039 Returns `sole' if completed with the only completion match.
2040 Returns `shortest' if completed with the shortest of the completion matches.
2041 Returns `partial' if completed as far as possible with the completion matches.
2042 Returns `listed' if a completion listing was shown.
2044 See also `comint-dynamic-complete-filename'."
2045 (let* ((completion-ignore-case (memq system-type '(ms-dos windows-nt)))
2046 (suffix (cond ((not comint-completion-addsuffix) "")
2047 ((not (consp comint-completion-addsuffix)) " ")
2048 (t (cdr comint-completion-addsuffix))))
2049 (candidates (mapcar (function (lambda (x) (list x))) candidates))
2050 (completions (all-completions stub candidates)))
2051 (cond ((null completions)
2052 (message "No completions of %s" stub)
2053 nil)
2054 ((= 1 (length completions)) ; Gotcha!
2055 (let ((completion (car completions)))
2056 (if (string-equal completion stub)
2057 (message "Sole completion")
2058 (insert (substring completion (length stub)))
2059 (message "Completed"))
2060 (insert suffix)
2061 'sole))
2062 (t ; There's no unique completion.
2063 (let ((completion (try-completion stub candidates)))
2064 ;; Insert the longest substring.
2065 (insert (substring completion (length stub)))
2066 (cond ((and comint-completion-recexact comint-completion-addsuffix
2067 (string-equal stub completion)
2068 (member completion completions))
2069 ;; It's not unique, but user wants shortest match.
2070 (insert suffix)
2071 (message "Completed shortest")
2072 'shortest)
2073 ((or comint-completion-autolist
2074 (string-equal stub completion))
2075 ;; It's not unique, list possible completions.
2076 (comint-dynamic-list-completions completions)
2077 'listed)
2079 (message "Partially completed")
2080 'partial)))))))
2083 (defun comint-dynamic-list-filename-completions ()
2084 "List in help buffer possible completions of the filename at point."
2085 (interactive)
2086 (let* ((completion-ignore-case (memq system-type '(ms-dos windows-nt)))
2087 ;; If we bind this, it breaks remote directory tracking in rlogin.el.
2088 ;; I think it was originally bound to solve file completion problems,
2089 ;; but subsequent changes may have made this unnecessary. sm.
2090 ;;(file-name-handler-alist nil)
2091 (filename (or (comint-match-partial-filename) ""))
2092 (pathdir (file-name-directory filename))
2093 (pathnondir (file-name-nondirectory filename))
2094 (directory (if pathdir (comint-directory pathdir) default-directory))
2095 (completions (file-name-all-completions pathnondir directory)))
2096 (if (not completions)
2097 (message "No completions of %s" filename)
2098 (comint-dynamic-list-completions
2099 (mapcar 'comint-quote-filename completions)))))
2102 (defun comint-dynamic-list-completions (completions)
2103 "List in help buffer sorted COMPLETIONS.
2104 Typing SPC flushes the help buffer."
2105 (let ((conf (current-window-configuration)))
2106 (with-output-to-temp-buffer "*Completions*"
2107 (display-completion-list (sort completions 'string-lessp)))
2108 (message "Hit space to flush")
2109 (let (key first)
2110 (if (save-excursion
2111 (set-buffer (get-buffer "*Completions*"))
2112 (setq key (read-key-sequence nil)
2113 first (aref key 0))
2114 (and (consp first) (consp (event-start first))
2115 (eq (window-buffer (posn-window (event-start first)))
2116 (get-buffer "*Completions*"))
2117 (eq (key-binding key) 'mouse-choose-completion)))
2118 ;; If the user does mouse-choose-completion with the mouse,
2119 ;; execute the command, then delete the completion window.
2120 (progn
2121 (mouse-choose-completion first)
2122 (set-window-configuration conf))
2123 (if (eq first ?\ )
2124 (set-window-configuration conf)
2125 (setq unread-command-events (listify-key-sequence key)))))))
2127 ;; Converting process modes to use comint mode
2128 ;; ===========================================================================
2129 ;; The code in the Emacs 19 distribution has all been modified to use comint
2130 ;; where needed. However, there are `third-party' packages out there that
2131 ;; still use the old shell mode. Here's a guide to conversion.
2133 ;; Renaming variables
2134 ;; Most of the work is renaming variables and functions. These are the common
2135 ;; ones:
2136 ;; Local variables:
2137 ;; last-input-start comint-last-input-start
2138 ;; last-input-end comint-last-input-end
2139 ;; shell-prompt-pattern comint-prompt-regexp
2140 ;; shell-set-directory-error-hook <no equivalent>
2141 ;; Miscellaneous:
2142 ;; shell-set-directory <unnecessary>
2143 ;; shell-mode-map comint-mode-map
2144 ;; Commands:
2145 ;; shell-send-input comint-send-input
2146 ;; shell-send-eof comint-delchar-or-maybe-eof
2147 ;; kill-shell-input comint-kill-input
2148 ;; interrupt-shell-subjob comint-interrupt-subjob
2149 ;; stop-shell-subjob comint-stop-subjob
2150 ;; quit-shell-subjob comint-quit-subjob
2151 ;; kill-shell-subjob comint-kill-subjob
2152 ;; kill-output-from-shell comint-kill-output
2153 ;; show-output-from-shell comint-show-output
2154 ;; copy-last-shell-input Use comint-previous-input/comint-next-input
2156 ;; SHELL-SET-DIRECTORY is gone, its functionality taken over by
2157 ;; SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-filter-functions.
2158 ;; Comint mode does not provide functionality equivalent to
2159 ;; shell-set-directory-error-hook; it is gone.
2161 ;; comint-last-input-start is provided for modes which want to munge
2162 ;; the buffer after input is sent, perhaps because the inferior
2163 ;; insists on echoing the input. The LAST-INPUT-START variable in
2164 ;; the old shell package was used to implement a history mechanism,
2165 ;; but you should think twice before using comint-last-input-start
2166 ;; for this; the input history ring often does the job better.
2168 ;; If you are implementing some process-in-a-buffer mode, called foo-mode, do
2169 ;; *not* create the comint-mode local variables in your foo-mode function.
2170 ;; This is not modular. Instead, call comint-mode, and let *it* create the
2171 ;; necessary comint-specific local variables. Then create the
2172 ;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to
2173 ;; be foo-mode-map, and its mode to be foo-mode. Set the comint-mode hooks
2174 ;; (comint-{prompt-regexp, input-filter, input-filter-functions,
2175 ;; get-old-input) that need to be different from the defaults. Call
2176 ;; foo-mode-hook, and you're done. Don't run the comint-mode hook yourself;
2177 ;; comint-mode will take care of it. The following example, from shell.el,
2178 ;; is typical:
2180 ;; (defvar shell-mode-map '())
2181 ;; (cond ((not shell-mode-map)
2182 ;; (setq shell-mode-map (copy-keymap comint-mode-map))
2183 ;; (define-key shell-mode-map "\C-c\C-f" 'shell-forward-command)
2184 ;; (define-key shell-mode-map "\C-c\C-b" 'shell-backward-command)
2185 ;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
2186 ;; (define-key shell-mode-map "\M-?"
2187 ;; 'comint-dynamic-list-filename-completions)))
2189 ;; (defun shell-mode ()
2190 ;; (interactive)
2191 ;; (comint-mode)
2192 ;; (setq comint-prompt-regexp shell-prompt-pattern)
2193 ;; (setq major-mode 'shell-mode)
2194 ;; (setq mode-name "Shell")
2195 ;; (use-local-map shell-mode-map)
2196 ;; (make-local-variable 'shell-directory-stack)
2197 ;; (setq shell-directory-stack nil)
2198 ;; (add-hook 'comint-input-filter-functions 'shell-directory-tracker)
2199 ;; (run-hooks 'shell-mode-hook))
2202 ;; Completion for comint-mode users
2204 ;; For modes that use comint-mode, comint-dynamic-complete-functions is the
2205 ;; hook to add completion functions to. Functions on this list should return
2206 ;; non-nil if completion occurs (i.e., further completion should not occur).
2207 ;; You could use comint-dynamic-simple-complete to do the bulk of the
2208 ;; completion job.
2210 (provide 'comint)
2212 ;; comint.el ends here