comparison lisp/comint/comint.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
comparison
equal deleted inserted replaced
-1:000000000000 0:376386a54a3c
1 ;;; comint.el --- general command interpreter in a window stuff
2
3 ;; Copyright (C) 1988, 90, 92, 93, 94, 95 Free Software Foundation, Inc.
4
5 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
6 ;; Adapted-by: Simon Marshall <simon@gnu.ai.mit.edu>
7 ;; Keywords: processes
8
9 ;; This file is part of XEmacs.
10
11 ;; XEmacs is free software; you can redistribute it and/or modify it
12 ;; 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.
15
16 ;; XEmacs is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
23 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;;; Synched up with: FSF 19.30.
26
27 ;;; Commentary:
28
29 ;;; Please send me bug reports, bug fixes, and extensions, so that I can
30 ;;; merge them into the master source.
31 ;;; - Olin Shivers (shivers@cs.cmu.edu)
32 ;;; - Simon Marshall (simon@gnu.ai.mit.edu)
33
34 ;;; This file defines a general command-interpreter-in-a-buffer package
35 ;;; (comint mode). The idea is that you can build specific process-in-a-buffer
36 ;;; modes on top of comint mode -- e.g., lisp, shell, scheme, T, soar, ....
37 ;;; This way, all these specific packages share a common base functionality,
38 ;;; and a common set of bindings, which makes them easier to use (and
39 ;;; saves code, implementation time, etc., etc.).
40
41 ;;; Several packages are already defined using comint mode:
42 ;;; - shell.el defines a shell-in-a-buffer mode.
43 ;;; - cmulisp.el defines a simple lisp-in-a-buffer mode.
44 ;;;
45 ;;; - The file cmuscheme.el defines a scheme-in-a-buffer mode.
46 ;;; - The file tea.el tunes scheme and inferior-scheme modes for T.
47 ;;; - The file soar.el tunes lisp and inferior-lisp modes for Soar.
48 ;;; - cmutex.el defines tex and latex modes that invoke tex, latex, bibtex,
49 ;;; previewers, and printers from within emacs.
50 ;;; - background.el allows csh-like job control inside emacs.
51 ;;; It is pretty easy to make new derived modes for other processes.
52
53 ;;; For documentation on the functionality provided by comint mode, and
54 ;;; the hooks available for customising it, see the comments below.
55 ;;; For further information on the standard derived modes (shell,
56 ;;; inferior-lisp, inferior-scheme, ...), see the relevant source files.
57
58 ;;; For hints on converting existing process modes (e.g., tex-mode,
59 ;;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode
60 ;;; instead of shell-mode, see the notes at the end of this file.
61
62
63 ;;; Brief Command Documentation:
64 ;;;============================================================================
65 ;;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp
66 ;;; mode)
67 ;;;
68 ;;; XEmacs - FSF19 binds M-p/M-n to comint-{previous,next}-input instead of
69 ;;; comint-{previous,next}-matching-input-from-input.
70 ;;; XEmacs is mo' better.
71 ;;;
72 ;;;
73 ;;; m-p comint-previous-matching-input-from-input Cycle backwards in input history
74 ;;; m-n comint-next-matching-input-from-input Cycle forwards
75 ;;; m-r comint-previous-matching-input Previous input matching a regexp
76 ;;; m-s comint-next-matching-input Next input that matches
77 ;;; XEmacs - remove evil binding of M-C-l. It's already bound to C-c C-r.
78 ;;; NOT: m-c-l comint-show-output Show last batch of process output
79 ;;; m-c-r comint-previous-input-matching Search backwards in input history
80 ;;; return comint-send-input
81 ;;; XEmacs - fsf nuked the binding for ^A, and we nuked the binding for ^D
82 ;;; c-a comint-bol Beginning of line; skip prompt
83 ;;; NOT: c-d comint-delchar-or-maybe-eof Delete char unless at end of buff
84 ;;; c-c c-a comint-bol Beginning of line; skip prompt
85 ;;; c-c c-d comint-send-eof ^d
86 ;;; c-c c-u comint-kill-input ^u
87 ;;; c-c c-w backward-kill-word ^w
88 ;;; c-c c-c comint-interrupt-subjob ^c
89 ;;; c-c c-z comint-stop-subjob ^z
90 ;;; c-c c-\ comint-quit-subjob ^\
91 ;;; c-c c-o comint-kill-output Delete last batch of process output
92 ;;; c-c c-r comint-show-output Show last batch of process output
93 ;;; c-c c-l comint-dynamic-list-input-ring List input history
94 ;;;
95 ;;; Not bound by default in comint-mode (some are in shell mode)
96 ;;; comint-run Run a program under comint-mode
97 ;;; send-invisible Read a line w/o echo, and send to proc
98 ;;; comint-dynamic-complete-filename Complete filename at point.
99 ;;; comint-dynamic-complete-variable Complete variable name at point.
100 ;;; comint-dynamic-list-filename-completions List completions in help buffer.
101 ;;; comint-replace-by-expanded-filename Expand and complete filename at point;
102 ;;; replace with expanded/completed name.
103 ;;; comint-replace-by-expanded-history Expand history at point;
104 ;;; replace with expanded name.
105 ;;; comint-magic-space Expand history and add (a) space(s).
106 ;;; comint-kill-subjob No mercy.
107 ;;; comint-show-maximum-output Show as much output as possible.
108 ;;; comint-continue-subjob Send CONT signal to buffer's process
109 ;;; group. Useful if you accidentally
110 ;;; suspend your process (with C-c C-z).
111
112 ;;; comint-mode-hook is the comint mode hook. Basically for your keybindings.
113
114 ;;; Code:
115
116 (require 'ring)
117
118 ;;; Buffer Local Variables:
119 ;;;============================================================================
120 ;;; Comint mode buffer local variables:
121 ;;; comint-prompt-regexp - string comint-bol uses to match prompt
122 ;;; comint-delimiter-argument-list - list For delimiters and arguments
123 ;;; comint-last-input-start - marker Handy if inferior always echoes
124 ;;; comint-last-input-end - marker For comint-kill-output command
125 ;;; comint-input-ring-size - integer For the input history
126 ;;; comint-input-ring - ring mechanism
127 ;;; comint-input-ring-index - number ...
128 ;;; comint-input-autoexpand - symbol ...
129 ;;; comint-input-ignoredups - boolean ...
130 ;;; comint-last-input-match - string ...
131 ;;; comint-dynamic-complete-functions - hook For the completion mechanism
132 ;;; comint-completion-fignore - list ...
133 ;;; comint-file-name-quote-list - list ...
134 ;;; comint-get-old-input - function Hooks for specific
135 ;;; comint-input-filter-functions - hook process-in-a-buffer
136 ;;; comint-output-filter-functions - hook function modes.
137 ;;; comint-input-filter - function ...
138 ;;; comint-input-sender - function ...
139 ;;; comint-eol-on-send - boolean ...
140 ;;; comint-process-echoes - boolean ...
141 ;;; comint-scroll-to-bottom-on-input - symbol For scroll behavior
142 ;;; comint-scroll-to-bottom-on-output - symbol ...
143 ;;; comint-scroll-show-maximum-output - boolean...
144 ;;;
145 ;;; Comint mode non-buffer local variables:
146 ;;; comint-completion-addsuffix - boolean/cons For file name completion
147 ;;; comint-completion-autolist - boolean behavior
148 ;;; comint-completion-recexact - boolean ...
149
150 (defvar comint-prompt-regexp "^"
151 "Regexp to recognise prompts in the inferior process.
152 Defaults to \"^\", the null string at BOL.
153
154 Good choices:
155 Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
156 Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
157 franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
158 kcl: \"^>+ *\"
159 shell: \"^[^#$%>\\n]*[#$%>] *\"
160 T: \"^>+ *\"
161
162 The pattern should begin with \"^\". It can match text on more than one line.
163 This pattern gets handed to re-search-backward, not looking-at.
164
165 This is a good thing to set in mode hooks.")
166
167 (defvar comint-delimiter-argument-list ()
168 "List of characters to recognise as separate arguments in input.
169 Strings comprising a character in this list will separate the arguments
170 surrounding them, and also be regarded as arguments in their own right (unlike
171 whitespace). See `comint-arguments'.
172 Defaults to the empty list.
173
174 For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?;).
175
176 This is a good thing to set in mode hooks.")
177
178 ;; #### BUG: this loser mangles history; when one types
179 ;; find /tmp \( -name foo \) -print
180 ;; one gets find /tmp \ ( -name foo \ ) -print
181 ;;
182 ;; XEmacs - So turn this off by default. -- jwz
183 ;;
184 (defvar comint-input-autoexpand nil
185 "*If non-nil, expand input command history references on completion.
186 This mirrors the optional behavior of tcsh (its autoexpand and histlit).
187
188 If the value is `input', then the expansion is seen on input.
189 If the value is `history', then the expansion is only when inserting
190 into the buffer's input ring. See also `comint-magic-space' and
191 `comint-dynamic-complete'.
192
193 This variable is buffer-local.")
194
195 ;; XEmacs - this should default to t for consistency with minibuffer history. -jwz
196 (defvar comint-input-ignoredups t
197 "*If non-nil, don't add input matching the last on the input ring.
198 This mirrors the optional behavior of bash.
199
200 This variable is buffer-local.")
201
202 (defvar comint-input-ring-file-name nil
203 "*If non-nil, name of the file to read/write input history.
204 See also `comint-read-input-ring' and `comint-write-input-ring'.
205
206 This variable is buffer-local, and is a good thing to set in mode hooks.")
207
208 (defvar comint-scroll-to-bottom-on-input nil
209 "*Controls whether input to interpreter causes window to scroll.
210 If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
211 If `this', scroll only the selected window.
212
213 The default is nil.
214
215 See `comint-preinput-scroll-to-bottom'. This variable is buffer-local.")
216
217 (defvar comint-scroll-to-bottom-on-output nil
218 "*Controls whether interpreter output causes window to scroll.
219 If nil, then do not scroll. If t or `all', scroll all windows showing buffer.
220 If `this', scroll only the selected window.
221 If `others', scroll only those that are not the selected window.
222
223 The default is nil.
224
225 See variable `comint-scroll-show-maximum-output' and function
226 `comint-postoutput-scroll-to-bottom'. This variable is buffer-local.")
227
228 ;; XEmacs - Default this to nil: this is just horrible
229 (defvar comint-scroll-show-maximum-output nil
230 "*Controls how interpreter output causes window to scroll.
231 If non-nil, then show the maximum output when the window is scrolled.
232
233 See variable `comint-scroll-to-bottom-on-output' and function
234 `comint-postoutput-scroll-to-bottom'. This variable is buffer-local.")
235
236 (defvar comint-buffer-maximum-size 1024
237 "*The maximum size in lines for comint buffers.
238 Comint buffers are truncated from the top to be no greater than this number, if
239 the function `comint-truncate-buffer' is on `comint-output-filter-functions'.")
240
241 (defvar comint-input-ring-size 32
242 "Size of input history ring.")
243
244 (defvar comint-process-echoes nil
245 "*If non-nil, assume that the subprocess echoes any input.
246 If so, delete one copy of the input so that only one copy eventually
247 appears in the buffer.
248
249 This variable is buffer-local.")
250
251 ;; AIX puts the name of the person being su'd to in from of the prompt.
252 (defvar comint-password-prompt-regexp
253 (if (eq system-type 'aix-v3)
254 "\\(\\([Oo]ld \\|[Nn]ew \\|^\\|^..*s\\)[Pp]assword\\|pass phrase\\):\\s *\\'"
255 "\\(\\([Oo]ld \\|[Nn]ew \\|^\\)[Pp]assword\\|pass phrase\\):\\s *\\'")
256 "*Regexp matching prompts for passwords in the inferior process.
257 This is used by `comint-watch-for-password-prompt'.")
258
259 ;;; Here are the per-interpreter hooks.
260 (defvar comint-get-old-input (function comint-get-old-input-default)
261 "Function that returns old text in comint mode.
262 This function is called when return is typed while the point is in old text.
263 It returns the text to be submitted as process input. The default is
264 `comint-get-old-input-default', which grabs the current line, and strips off
265 leading text matching `comint-prompt-regexp'.")
266
267 ;; XEmacs - fsf doesn't have this, and I think it ought to default to 't'
268 ;; because it's good idiot-proof interface. --stig
269 (defvar comint-append-old-input t
270 "*If nil, old text selected by \\[comint-send-input] is re-sent immediately.
271 If non-nil, the old text is appended to the end of the buffer,
272 and a prompting message is printed.
273
274 This flag does not affect the behavior of \\[comint-send-input]
275 after the process output mark.")
276
277 (defvar comint-dynamic-complete-functions
278 '(comint-replace-by-expanded-history comint-dynamic-complete-filename)
279 "List of functions called to perform completion.
280 Functions should return non-nil if completion was performed.
281 See also `comint-dynamic-complete'.
282
283 This is a good thing to set in mode hooks.")
284
285 (defvar comint-input-filter
286 #'(lambda (str)
287 (and (not (string-match "\\`\\s *\\'" str))
288 ;; XEmacs - ignore '!!' and kin
289 (> (length str) 2)))
290 "Predicate for filtering additions to input history.
291 Takes one argument, the input. If non-nil, the input may be saved on the input
292 history list. Default is to save anything longer than two characters
293 that isn't all whitespace.")
294
295 (defvar comint-input-filter-functions '()
296 "Functions to call before input is sent to the process.
297 These functions get one argument, a string containing the text to send.
298
299 This variable is buffer-local.")
300
301 (defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom
302 ;; XEmacs - not here by default for FSF
303 comint-watch-for-password-prompt)
304 "Functions to call after output is inserted into the buffer.
305 One possible function is `comint-postoutput-scroll-to-bottom'.
306 These functions get one argument, a string containing the text just inserted.
307
308 This variable is buffer-local.")
309
310 (defvar comint-input-sender (function comint-simple-send)
311 "Function to actually send to PROCESS the STRING submitted by user.
312 Usually this is just `comint-simple-send', but if your mode needs to
313 massage the input string, put a different function here.
314 `comint-simple-send' just sends the string plus a newline.
315 This is called from the user command `comint-send-input'.")
316
317 (defvar comint-eol-on-send t
318 "*Non-nil means go to the end of the line before sending input.
319 See `comint-send-input'.")
320
321 (defvar comint-mode-hook '()
322 "Called upon entry into comint-mode
323 This is run before the process is cranked up.")
324
325 (defvar comint-exec-hook '()
326 "Called each time a process is exec'd by `comint-exec'.
327 This is called after the process is cranked up. It is useful for things that
328 must be done each time a process is executed in a comint mode buffer (e.g.,
329 `(process-kill-without-query)'). In contrast, the `comint-mode-hook' is only
330 executed once when the buffer is created.")
331
332 (defvar comint-mode-map nil)
333
334 (defvar comint-ptyp t
335 "Non-nil if communications via pty; false if by pipe. Buffer local.
336 This is to work around a bug in Emacs process signalling.")
337
338 (defvar comint-input-ring nil)
339 (defvar comint-last-input-start)
340 (defvar comint-last-input-end)
341 (defvar comint-last-output-start)
342 (defvar comint-input-ring-index nil
343 "Index of last matched history element.")
344 (defvar comint-matching-input-from-input-string ""
345 "Input previously used to match input history.")
346
347 (put 'comint-input-ring 'permanent-local t)
348 (put 'comint-input-ring-index 'permanent-local t)
349 (put 'comint-input-autoexpand 'permanent-local t)
350 (put 'comint-input-filter-functions 'permanent-local t)
351 (put 'comint-output-filter-functions 'permanent-local t)
352 (put 'comint-scroll-to-bottom-on-input 'permanent-local t)
353 (put 'comint-scroll-to-bottom-on-output 'permanent-local t)
354 (put 'comint-scroll-show-maximum-output 'permanent-local t)
355 (put 'comint-ptyp 'permanent-local t)
356
357 (defun comint-mode ()
358 "Major mode for interacting with an inferior interpreter.
359 Interpreter name is same as buffer name, sans the asterisks.
360 Return at end of buffer sends line as input.
361 Return not at end copies rest of line to end and sends it.
362 Setting variable `comint-eol-on-send' means jump to the end of the line
363 before submitting new input.
364
365 This mode is customised to create major modes such as Inferior Lisp
366 mode, Shell mode, etc. This can be done by setting the hooks
367 `comint-input-filter-functions', `comint-input-filter', `comint-input-sender'
368 and `comint-get-old-input' to appropriate functions, and the variable
369 `comint-prompt-regexp' to the appropriate regular expression.
370
371 An input history is maintained of size `comint-input-ring-size', and
372 can be accessed with the commands \\[comint-next-input], \\[comint-previous-input], and \\[comint-dynamic-list-input-ring].
373 Input ring history expansion can be achieved with the commands
374 \\[comint-replace-by-expanded-history] or \\[comint-magic-space].
375 Input ring expansion is controlled by the variable `comint-input-autoexpand',
376 and addition is controlled by the variable `comint-input-ignoredups'.
377
378 Commands with no default key bindings include `send-invisible',
379 `comint-dynamic-complete', `comint-dynamic-list-filename-completions', and
380 `comint-magic-space'.
381
382 Input to, and output from, the subprocess can cause the window to scroll to
383 the end of the buffer. See variables `comint-output-filter-functions',
384 `comint-scroll-to-bottom-on-input', and `comint-scroll-to-bottom-on-output'.
385
386 If you accidentally suspend your process, use \\[comint-continue-subjob]
387 to continue it.
388
389 \\{comint-mode-map}
390
391 Entry to this mode runs the hooks on `comint-mode-hook'."
392 (interactive)
393 ;; Do not remove this. All major modes must do this.
394 (kill-all-local-variables)
395 (setq major-mode 'comint-mode)
396 (setq mode-name "Comint")
397 (setq mode-line-process '(": %s")) ; XEmacs
398 (use-local-map comint-mode-map)
399 (make-local-variable 'comint-last-input-start)
400 (setq comint-last-input-start (make-marker))
401 (set-marker comint-last-input-start (point-min))
402 (make-local-variable 'comint-last-input-end)
403 (setq comint-last-input-end (make-marker))
404 (set-marker comint-last-input-end (point-min))
405 (make-local-variable 'comint-last-output-start)
406 (setq comint-last-output-start (make-marker))
407 (make-local-variable 'comint-prompt-regexp) ; Don't set; default
408 (make-local-variable 'comint-input-ring-size) ; ...to global val.
409 (make-local-variable 'comint-input-ring)
410 (make-local-variable 'comint-input-ring-file-name)
411 (or (and (boundp 'comint-input-ring) comint-input-ring)
412 (setq comint-input-ring (make-ring comint-input-ring-size)))
413 (make-local-variable 'comint-input-ring-index)
414 (or (and (boundp 'comint-input-ring-index) comint-input-ring-index)
415 (setq comint-input-ring-index nil))
416 (make-local-variable 'comint-matching-input-from-input-string)
417 (make-local-variable 'comint-input-autoexpand)
418 (make-local-variable 'comint-input-ignoredups)
419 (make-local-variable 'comint-delimiter-argument-list)
420 (make-local-hook 'comint-dynamic-complete-functions)
421 (make-local-variable 'comint-completion-fignore)
422 (make-local-variable 'comint-get-old-input)
423 (make-local-hook 'comint-input-filter-functions)
424 (make-local-variable 'comint-input-filter)
425 (make-local-variable 'comint-input-sender)
426 (make-local-variable 'comint-eol-on-send)
427 (make-local-variable 'comint-scroll-to-bottom-on-input)
428 (make-local-variable 'comint-scroll-to-bottom-on-output)
429 (make-local-variable 'comint-scroll-show-maximum-output)
430 (make-local-hook 'pre-command-hook)
431 (add-hook 'pre-command-hook 'comint-preinput-scroll-to-bottom nil t)
432 (make-local-hook 'comint-output-filter-functions)
433 (make-local-variable 'comint-ptyp)
434 (make-local-hook 'comint-exec-hook)
435 (make-local-variable 'comint-process-echoes)
436 (make-local-variable 'comint-file-name-quote-list)
437 (if (featurep 'menubar)
438 (progn
439 ;; make a local copy of the menubar, so our modes don't
440 ;; change the global menubar
441 (set-buffer-menubar current-menubar)
442 (add-submenu nil comint-1-menubar-menu)
443 (add-submenu nil comint-2-menubar-menu)
444 (add-submenu nil comint-history-menubar-menu)))
445 (run-hooks 'comint-mode-hook))
446
447 (if comint-mode-map
448 nil
449 ;; Keys:
450 (setq comint-mode-map (make-sparse-keymap))
451 (set-keymap-name comint-mode-map 'comint-mode-map) ; XEmacs
452
453 ;; XEmacs - The FSF19 party line
454 ;;(define-key comint-mode-map "\ep" 'comint-previous-input)
455 ;;(define-key comint-mode-map "\en" 'comint-next-input)
456
457 ;; The Lucid party line
458 (define-key comint-mode-map "\ep" 'comint-previous-matching-input-from-input)
459 (define-key comint-mode-map "\en" 'comint-next-matching-input-from-input)
460 (define-key comint-mode-map '(control up)
461 'comint-previous-matching-input-from-input)
462 (define-key comint-mode-map '(control down)
463 'comint-next-matching-input-from-input)
464
465 (define-key comint-mode-map "\er" 'comint-previous-matching-input)
466 (define-key comint-mode-map "\es" 'comint-next-matching-input)
467 ;; XEmacs - alt-meta-anything is a horrible binding. Some keyboards don't have
468 ;; meta keys, so we use alt as meta. Consequently, alt-meta will not exist on
469 ;; all keyboards. Just blow this. These functions are on M-n and M-p. --stig
470 ;;(define-key comint-mode-map [?\A-\M-r] 'comint-previous-matching-input-from-input)
471 ;;(define-key comint-mode-map [?\A-\M-s] 'comint-next-matching-input-from-input)
472 ;; XEmacs: Yuck yuck. C-M-l has a perfectly good normal binding.
473 ;;(define-key comint-mode-map "\e\C-l" 'comint-show-output)
474 (define-key comint-mode-map "\C-m" 'comint-send-input)
475 ;; XEmacs - Use ^C^D instead of ^D. Jamie & Stig think this is too un-emacs.
476 ;;(define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
477 ;; XEmacs - FSF nuked this, but we're gonna keep it....
478 (define-key comint-mode-map "\C-a" 'comint-bol)
479 ;; yuck, this is evil.
480 ;;(define-key comint-mode-map "\C-u" 'comint-universal-argument) ; XEmacs
481 (define-key comint-mode-map "\C-c\C-a" 'comint-bol)
482 (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input)
483 (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word)
484 (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob)
485 (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob)
486 (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob)
487 (define-key comint-mode-map "\C-c\C-m" 'comint-copy-old-input)
488 (define-key comint-mode-map "\C-c\C-o" 'comint-kill-output)
489 (define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
490 (define-key comint-mode-map "\C-c\C-e" 'comint-show-maximum-output)
491 (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring)
492 (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof)
493
494 (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt)
495 (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt)
496 ;; John Rose's suggestion
497 (define-key comint-mode-map "\e}" 'comint-next-prompt)
498 (define-key comint-mode-map "\e{" 'comint-previous-prompt)
499
500 (define-key comint-mode-map 'button3 'comint-popup-menu)
501 )
502
503 (defconst comint-1-menubar-menu
504 (purecopy
505 '("Comint1"
506 ["Previous Matching Current Input"
507 comint-previous-matching-input-from-input t]
508 ["Next Matching Current Input" comint-next-matching-input-from-input t]
509 ["Previous Input" comint-previous-input t]
510 ["Next Input" comint-next-input t]
511 ["Previous Input Matching Regexp..." comint-previous-matching-input t]
512 ["Next Input Matching Regexp..." comint-next-matching-input t]
513 ["Backward Matching Input..." comint-backward-matching-input t]
514 ["Forward Matching Input..." comint-forward-matching-input t]
515 "---"
516 ["Copy Old Input" comint-copy-old-input t]
517 ["Kill Current Input" comint-kill-input t]
518 ["Show Current Output Group" comint-show-output t]
519 ["Show Maximum Output" comint-show-maximum-output t]
520 ["Goto Previous Prompt" comint-previous-prompt t]
521 ["Goto Next Prompt" comint-next-prompt t]
522 ["Kill Command Output" comint-kill-output t]
523 )))
524
525 (defconst comint-2-menubar-menu
526 (purecopy
527 '("Comint2"
528 ["Complete Before Point" comint-dynamic-complete t]
529 ["Complete File Name" comint-dynamic-complete-filename t]
530 ["File Completion Listing" comint-dynamic-list-filename-completions t]
531 ["Expand File Name" comint-replace-by-expanded-filename t]
532 ;; this is cheesy but the easiest way to get this.
533 ["Complete Env. Variable Name" shell-dynamic-complete-environment-variable
534 :active t :included (eq 'shell-mode major-mode)]
535 ["Expand Directory Reference" shell-replace-by-expanded-directory
536 :active t :included (eq 'shell-mode major-mode)]
537 "---"
538 ["Send INT" comint-interrupt-subjob t]
539 ["Send STOP" comint-stop-subjob t]
540 ["Send CONT" comint-continue-subjob t]
541 ["Send QUIT" comint-quit-subjob t]
542 ["Send KILL" comint-kill-subjob t]
543 ["Send EOF" comint-send-eof t]
544 )))
545
546 (defconst comint-history-menubar-menu
547 (purecopy
548 '("History"
549 :filter comint-history-menu-filter
550 ["Expand History Before Point" comint-replace-by-expanded-history
551 comint-input-autoexpand]
552 ["List Input History" comint-dynamic-list-input-ring t]
553 "---"
554 )))
555
556 (defconst comint-popup-menu
557 '("Command Interpreter Commands"
558 ["Kill Command Output" comint-kill-output t]
559 ["Goto Next Prompt" comint-next-prompt t]
560 ["Goto Previous Prompt" comint-previous-prompt t]
561 ["Kill Input" comint-kill-input t]
562 "----"
563 ["Previous Input" comint-previous-matching-input-from-input t]
564 ["Next Input" comint-next-matching-input-from-input t]
565 ["Previous Input matching Regexp..." 'comint-previous-matching-input t]
566 ["Next Input matching Regexp..." 'comint-next-matching-input t]
567 ["List Command History" comint-dynamic-list-input-ring t]
568 "----"
569 ["Send INT" comint-interrupt-subjob t]
570 ["Send STOP" comint-stop-subjob t]
571 ["Send CONT" comint-continue-subjob t]
572 ["Send QUIT" comint-quit-subjob t]
573 ["Send KILL" comint-kill-subjob t]
574 ["Send EOF" comint-send-eof t]
575 ))
576
577 (defun comint-popup-menu (event)
578 "Display the comint-mode menu."
579 (interactive "@e")
580 (let ((history (comint-make-history-menu)))
581 (popup-menu (if history
582 (append comint-popup-menu
583 (list "---" (cons "Command History" history)))
584 comint-menu))))
585
586 (defvar comint-history-menu-max 40
587 "*Maximum number of entries to display on the Comint command-history menu.")
588
589 (defun comint-history-menu-filter (menu)
590 (let ((histmenu (comint-make-history-menu)))
591 (append menu histmenu)))
592
593 (defun comint-make-history-menu ()
594 (if (or (not (ring-p comint-input-ring))
595 (ring-empty-p comint-input-ring))
596 nil
597 (let ((menu nil)
598 hist
599 (index (1- (ring-length comint-input-ring)))
600 (count 0))
601 ;; We have to build up a list ourselves from the ring vector.
602 (while (and (>= index 0)
603 (and comint-history-menu-max
604 (< count comint-history-menu-max)))
605 (setq hist (ring-ref comint-input-ring index)
606 menu (cons (vector hist (list 'comint-menu-history hist) t)
607 menu)
608 count (1+ count)
609 index (1- index)))
610 menu)))
611
612 (defun comint-menu-history (string)
613 (goto-char (point-max))
614 (delete-region (process-mark (get-buffer-process (current-buffer))) (point))
615 (insert string))
616
617 (defun comint-check-proc (buffer)
618 "Return t if there is a living process associated w/buffer BUFFER.
619 Living means the status is `open', `run', or `stop'.
620 BUFFER can be either a buffer or the name of one."
621 (let ((proc (get-buffer-process buffer)))
622 (and proc (memq (process-status proc) '(open run stop)))))
623
624 ;;; Note that this guy, unlike shell.el's make-shell, barfs if you pass it ()
625 ;;; for the second argument (program).
626 ;;;###autoload
627 (defun make-comint (name program &optional startfile &rest switches)
628 "Make a comint process NAME in a buffer, running PROGRAM.
629 The name of the buffer is made by surrounding NAME with `*'s.
630 PROGRAM should be either a string denoting an executable program to create
631 via `start-process', or a cons pair of the form (HOST . SERVICE) denoting a TCP
632 connection to be opened via `open-network-stream'. If there is already a
633 running process in that buffer, it is not restarted. Optional third arg
634 STARTFILE is the name of a file to send the contents of to the process.
635
636 If PROGRAM is a string, any more args are arguments to PROGRAM."
637 (or (fboundp 'start-process)
638 (error "Multi-processing is not supported for this system"))
639 (let ((buffer (get-buffer-create (concat "*" name "*"))))
640 ;; If no process, or nuked process, crank up a new one and put buffer in
641 ;; comint mode. Otherwise, leave buffer and existing process alone.
642 (cond ((not (comint-check-proc buffer))
643 (save-excursion
644 (set-buffer buffer)
645 (comint-mode)) ; Install local vars, mode, keymap, ...
646 (comint-exec buffer name program startfile switches)))
647 buffer))
648
649 ;;;###autoload
650 (defun comint-run (program)
651 "Run PROGRAM in a comint buffer and switch to it.
652 The buffer name is made by surrounding the file name of PROGRAM with `*'s.
653 The file name is used to make a symbol name, such as `comint-sh-hook', and any
654 hooks on this symbol are run in the buffer.
655 See `make-comint' and `comint-exec'."
656 (interactive "sRun program: ")
657 (let ((name (file-name-nondirectory program)))
658 (switch-to-buffer (make-comint name program))
659 (run-hooks (intern-soft (concat "comint-" name "-hook")))))
660
661 (defun comint-exec (buffer name command startfile switches)
662 "Start up a process in buffer BUFFER for comint modes.
663 Blasts any old process running in the buffer. Doesn't set the buffer mode.
664 You can use this to cheaply run a series of processes in the same comint
665 buffer. The hook `comint-exec-hook' is run after each exec."
666 (save-excursion
667 (set-buffer buffer)
668 (let ((proc (get-buffer-process buffer))) ; Blast any old process.
669 (if proc (delete-process proc)))
670 ;; Crank up a new process
671 (let ((proc
672 (if (consp command)
673 (open-network-stream name buffer (car command) (cdr command))
674 (comint-exec-1 name buffer command switches))))
675 (set-process-filter proc 'comint-output-filter)
676 (make-local-variable 'comint-ptyp)
677 (setq comint-ptyp process-connection-type) ; T if pty, NIL if pipe.
678 ;; Jump to the end, and set the process mark.
679 (goto-char (point-max))
680 (set-marker (process-mark proc) (point))
681 ;; Feed it the startfile.
682 (cond (startfile
683 ;;This is guaranteed to wait long enough
684 ;;but has bad results if the comint does not prompt at all
685 ;; (while (= size (buffer-size))
686 ;; (sleep-for 1))
687 ;;I hope 1 second is enough!
688 (sleep-for 1)
689 (goto-char (point-max))
690 (insert-file-contents startfile)
691 (setq startfile (buffer-substring (point) (point-max)))
692 (delete-region (point) (point-max))
693 (comint-send-string proc startfile)))
694 (run-hooks 'comint-exec-hook)
695 buffer)))
696
697 ;;; This auxiliary function cranks up the process for comint-exec in
698 ;;; the appropriate environment.
699
700 (defun comint-exec-1 (name buffer command switches)
701 (let ((process-environment
702 (nconc
703 ;; If using termcap, we specify `emacs' as the terminal type
704 ;; because that lets us specify a width.
705 ;; If using terminfo, we specify `unknown' because that is
706 ;; a defined terminal type. `emacs' is not a defined terminal type
707 ;; and there is no way for us to define it here.
708 ;; Some programs that use terminfo get very confused
709 ;; if TERM is not a valid terminal type.
710 (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
711 (list "TERM=unknown"
712 (format "COLUMNS=%d" (frame-width)))
713 (list "TERM=emacs"
714 (format "TERMCAP=emacs:co#%d:tc=unknown:" (frame-width))))
715 (if (getenv "EMACS") nil (list "EMACS=t"))
716 process-environment))
717 (default-directory
718 (if (file-directory-p default-directory)
719 default-directory
720 "/")))
721 (apply 'start-process name buffer command switches)))
722
723 ;;; Input history processing in a buffer
724 ;;; ===========================================================================
725 ;;; Useful input history functions, courtesy of the Ergo group.
726
727 ;;; Eleven commands:
728 ;;; comint-dynamic-list-input-ring List history in help buffer.
729 ;;; comint-previous-input Previous input...
730 ;;; comint-previous-matching-input ...matching a string.
731 ;;; comint-previous-matching-input-from-input ... matching the current input.
732 ;;; comint-next-input Next input...
733 ;;; comint-next-matching-input ...matching a string.
734 ;;; comint-next-matching-input-from-input ... matching the current input.
735 ;;; comint-backward-matching-input Backwards input...
736 ;;; comint-forward-matching-input ...matching a string.
737 ;;; comint-replace-by-expanded-history Expand history at point;
738 ;;; replace with expanded history.
739 ;;; comint-magic-space Expand history and insert space.
740 ;;;
741 ;;; Three functions:
742 ;;; comint-read-input-ring Read into comint-input-ring...
743 ;;; comint-write-input-ring Write to comint-input-ring-file-name.
744 ;;; comint-replace-by-expanded-history-before-point Workhorse function.
745
746 (defun comint-read-input-ring (&optional silent)
747 "Sets the buffer's `comint-input-ring' from a history file.
748 The name of the file is given by the variable `comint-input-ring-file-name'.
749 The history ring is of size `comint-input-ring-size', regardless of file size.
750 If `comint-input-ring-file-name' is nil this function does nothing.
751
752 If the optional argument SILENT is non-nil, we say nothing about a
753 failure to read the history file.
754
755 This function is useful for major mode commands and mode hooks.
756
757 The structure of the history file should be one input command per line,
758 with the most recent command last.
759 See also `comint-input-ignoredups' and `comint-write-input-ring'."
760 (cond ((or (null comint-input-ring-file-name)
761 (equal comint-input-ring-file-name ""))
762 nil)
763 ((not (file-readable-p comint-input-ring-file-name))
764 (or silent
765 (message "Cannot read history file %s"
766 comint-input-ring-file-name)))
767 (t
768 (let ((history-buf (get-buffer-create " *comint-history*"))
769 (file comint-input-ring-file-name)
770 (count 0)
771 (ring (make-ring comint-input-ring-size)))
772 (unwind-protect
773 (save-excursion
774 (set-buffer history-buf)
775 (widen)
776 (erase-buffer)
777 (insert-file-contents file)
778 ;; Save restriction in case file is already visited...
779 ;; Watch for those date stamps in history files!
780 (goto-char (point-max))
781 (while (and (< count comint-input-ring-size)
782 (re-search-backward "^[ \t]*\\([^#\n].*\\)[ \t]*$"
783 nil t))
784 (let ((history (buffer-substring (match-beginning 1)
785 (match-end 1))))
786 (if (or (null comint-input-ignoredups)
787 (ring-empty-p ring)
788 (not (string-equal (ring-ref ring 0) history)))
789 (ring-insert-at-beginning ring history)))
790 (setq count (1+ count))))
791 (kill-buffer history-buf))
792 (setq comint-input-ring ring
793 comint-input-ring-index nil)))))
794
795 (defun comint-write-input-ring ()
796 "Writes the buffer's `comint-input-ring' to a history file.
797 The name of the file is given by the variable `comint-input-ring-file-name'.
798 The original contents of the file are lost if `comint-input-ring' is not empty.
799 If `comint-input-ring-file-name' is nil this function does nothing.
800
801 Useful within process sentinels.
802
803 See also `comint-read-input-ring'."
804 (cond ((or (null comint-input-ring-file-name)
805 (equal comint-input-ring-file-name "")
806 (null comint-input-ring) (ring-empty-p comint-input-ring))
807 nil)
808 ((not (file-writable-p comint-input-ring-file-name))
809 (message "Cannot write history file %s" comint-input-ring-file-name))
810 (t
811 (let* ((history-buf (get-buffer-create " *Temp Input History*"))
812 (ring comint-input-ring)
813 (file comint-input-ring-file-name)
814 (index (ring-length ring)))
815 ;; Write it all out into a buffer first. Much faster, but messier,
816 ;; than writing it one line at a time.
817 (save-excursion
818 (set-buffer history-buf)
819 (erase-buffer)
820 (while (> index 0)
821 (setq index (1- index))
822 (insert (ring-ref ring index) ?\n))
823 (write-region (buffer-string) nil file nil 'no-message)
824 (kill-buffer nil))))))
825
826 ;; XEmacs - FSF doesn't have this.
827 (defun comint-restore-window-config (conf &optional message)
828 ;; Don't obscure buffer being edited
829 (or (eq (selected-window) (minibuffer-window))
830 (message "%s" (or message "Press space to flush")))
831 (sit-for 0)
832 (if (if (fboundp 'next-command-event)
833 ;; lemacs
834 (let ((ch (next-command-event)))
835 (if (eq (event-to-character ch) ?\ )
836 t
837 (progn (setq unread-command-event ch)
838 nil)))
839 ;; v19 FSFmacs
840 (let ((ch (read-event)))
841 (if (eq ch ?\ )
842 t
843 (progn (setq unread-command-events (list ch))
844 nil))))
845 (set-window-configuration conf)))
846
847
848 (defun comint-dynamic-list-input-ring ()
849 "List in help buffer the buffer's input history."
850 (interactive)
851 (if (or (not (ring-p comint-input-ring))
852 (ring-empty-p comint-input-ring))
853 (message "No history")
854 (let ((history nil)
855 (history-buffer " *Input History*")
856 (index (1- (ring-length comint-input-ring)))
857 (conf (current-window-configuration)))
858 ;; We have to build up a list ourselves from the ring vector.
859 (while (>= index 0)
860 (setq history (cons (ring-ref comint-input-ring index) history)
861 index (1- index)))
862 ;; Change "completion" to "history reference"
863 ;; to make the display accurate.
864 (with-output-to-temp-buffer history-buffer
865 (display-completion-list history)
866 (set-buffer history-buffer)
867 (forward-line 3)
868 (let ((buffer-read-only nil))
869 (while (search-backward "completion" nil 'move)
870 (replace-match "history reference"))))
871 (comint-restore-window-config conf))))
872
873 (defun comint-regexp-arg (prompt)
874 ;; Return list of regexp and prefix arg using PROMPT.
875 (let* ((minibuffer-history-sexp-flag nil)
876 ;; Don't clobber this.
877 (last-command last-command)
878 (regexp (read-from-minibuffer prompt nil nil nil
879 'minibuffer-history-search-history)))
880 (list (if (string-equal regexp "")
881 (setcar minibuffer-history-search-history
882 (nth 1 minibuffer-history-search-history))
883 regexp)
884 (prefix-numeric-value current-prefix-arg))))
885
886 (defun comint-search-arg (arg)
887 ;; First make sure there is a ring and that we are after the process mark
888 (cond ((not (comint-after-pmark-p))
889 (error "Not at command line"))
890 ((or (null comint-input-ring)
891 (ring-empty-p comint-input-ring))
892 (error "Empty input ring"))
893 ((zerop arg)
894 ;; arg of zero resets search from beginning, and uses arg of 1
895 (setq comint-input-ring-index nil)
896 1)
897 (t
898 arg)))
899
900 (defun comint-search-start (arg)
901 ;; Index to start a directional search, starting at comint-input-ring-index
902 (if comint-input-ring-index
903 ;; If a search is running, offset by 1 in direction of arg
904 (mod (+ comint-input-ring-index (if (> arg 0) 1 -1))
905 (ring-length comint-input-ring))
906 ;; For a new search, start from beginning or end, as appropriate
907 (if (>= arg 0)
908 0 ; First elt for forward search
909 (1- (ring-length comint-input-ring))))) ; Last elt for backward search
910
911 (defun comint-previous-input-string (arg)
912 "Return the string ARG places along the input ring.
913 Moves relative to `comint-input-ring-index'."
914 (ring-ref comint-input-ring (if comint-input-ring-index
915 (mod (+ arg comint-input-ring-index)
916 (ring-length comint-input-ring))
917 arg)))
918
919 (defun comint-previous-input (arg)
920 "Cycle backwards through input history."
921 (interactive "*p")
922 (comint-previous-matching-input "." arg))
923
924 (defun comint-next-input (arg)
925 "Cycle forwards through input history."
926 (interactive "*p")
927 (comint-previous-input (- arg)))
928
929 (defun comint-previous-matching-input-string (regexp arg)
930 "Return the string matching REGEXP ARG places along the input ring.
931 Moves relative to `comint-input-ring-index'."
932 (let* ((pos (comint-previous-matching-input-string-position regexp arg)))
933 (if pos (ring-ref comint-input-ring pos))))
934
935 (defun comint-previous-matching-input-string-position (regexp arg &optional start)
936 "Return the index matching REGEXP ARG places along the input ring.
937 Moves relative to START, or `comint-input-ring-index'."
938 (if (or (not (ring-p comint-input-ring))
939 (ring-empty-p comint-input-ring))
940 (error "No history"))
941 (let* ((len (ring-length comint-input-ring))
942 (motion (if (> arg 0) 1 -1))
943 (n (mod (- (or start (comint-search-start arg)) motion) len))
944 (tried-each-ring-item nil)
945 (prev nil))
946 ;; Do the whole search as many times as the argument says.
947 (while (and (/= arg 0) (not tried-each-ring-item))
948 ;; Step once.
949 (setq prev n
950 n (mod (+ n motion) len))
951 ;; If we haven't reached a match, step some more.
952 (while (and (< n len) (not tried-each-ring-item)
953 (not (string-match regexp (ring-ref comint-input-ring n))))
954 (setq n (mod (+ n motion) len)
955 ;; If we have gone all the way around in this search.
956 tried-each-ring-item (= n prev)))
957 (setq arg (if (> arg 0) (1- arg) (1+ arg))))
958 ;; Now that we know which ring element to use, if we found it, return that.
959 (if (string-match regexp (ring-ref comint-input-ring n))
960 n)))
961
962 (defun comint-previous-matching-input (regexp arg)
963 "Search backwards through input history for match for REGEXP.
964 \(Previous history elements are earlier commands.)
965 With prefix argument N, search for Nth previous match.
966 If N is negative, find the next or Nth next match."
967 (interactive (comint-regexp-arg "Previous input matching (regexp): "))
968 (setq arg (comint-search-arg arg))
969 (let ((pos (comint-previous-matching-input-string-position regexp arg)))
970 ;; Has a match been found?
971 (if (null pos)
972 (error "Not found")
973 (setq comint-input-ring-index pos)
974 (message "History item: %d" (1+ pos))
975 (delete-region
976 ;; Can't use kill-region as it sets this-command
977 (process-mark (get-buffer-process (current-buffer))) (point))
978 (insert (ring-ref comint-input-ring pos)))))
979
980 (defun comint-next-matching-input (regexp arg)
981 "Search forwards through input history for match for REGEXP.
982 \(Later history elements are more recent commands.)
983 With prefix argument N, search for Nth following match.
984 If N is negative, find the previous or Nth previous match."
985 (interactive (comint-regexp-arg "Next input matching (regexp): "))
986 (comint-previous-matching-input regexp (- arg)))
987
988 (defun comint-previous-matching-input-from-input (arg)
989 "Search backwards through input history for match for current input.
990 \(Previous history elements are earlier commands.)
991 With prefix argument N, search for Nth previous match.
992 If N is negative, search forwards for the -Nth following match."
993 (interactive "p")
994 (if (not (memq last-command '(comint-previous-matching-input-from-input
995 comint-next-matching-input-from-input)))
996 ;; Starting a new search
997 (setq comint-matching-input-from-input-string
998 (buffer-substring
999 (process-mark (get-buffer-process (current-buffer)))
1000 (point))
1001 comint-input-ring-index nil))
1002 (comint-previous-matching-input
1003 (concat "^" (regexp-quote comint-matching-input-from-input-string))
1004 arg))
1005
1006 (defun comint-next-matching-input-from-input (arg)
1007 "Search forwards through input history for match for current input.
1008 \(Following history elements are more recent commands.)
1009 With prefix argument N, search for Nth following match.
1010 If N is negative, search backwards for the -Nth previous match."
1011 (interactive "p")
1012 (comint-previous-matching-input-from-input (- arg)))
1013
1014
1015 (defun comint-replace-by-expanded-history (&optional silent)
1016 "Expand input command history references before point.
1017 Expansion is dependent on the value of `comint-input-autoexpand'.
1018
1019 This function depends on the buffer's idea of the input history, which may not
1020 match the command interpreter's idea, assuming it has one.
1021
1022 Assumes history syntax is like typical Un*x shells'. However, since emacs
1023 cannot know the interpreter's idea of input line numbers, assuming it has one,
1024 it cannot expand absolute input line number references.
1025
1026 If the optional argument SILENT is non-nil, never complain
1027 even if history reference seems erroneous.
1028
1029 See `comint-magic-space' and `comint-replace-by-expanded-history-before-point'.
1030
1031 Returns t if successful."
1032 (interactive)
1033 (if (and comint-input-autoexpand
1034 (string-match "[!^]" (funcall comint-get-old-input))
1035 (save-excursion (beginning-of-line)
1036 (looking-at comint-prompt-regexp)))
1037 ;; Looks like there might be history references in the command.
1038 (let ((previous-modified-tick (buffer-modified-tick)))
1039 (message "Expanding history references...")
1040 (comint-replace-by-expanded-history-before-point silent)
1041 (/= previous-modified-tick (buffer-modified-tick)))))
1042
1043
1044 (defun comint-replace-by-expanded-history-before-point (silent)
1045 "Expand directory stack reference before point.
1046 See `comint-replace-by-expanded-history'. Returns t if successful."
1047 (save-excursion
1048 (let ((toend (- (save-excursion (end-of-line nil) (point)) (point)))
1049 (start (progn (comint-bol nil) (point))))
1050 ;; XEmacs - fsf has something weird and complex here that does the same thing.
1051 (while (re-search-forward
1052 "[!^]" (save-excursion (end-of-line nil) (- (point) toend)) t)
1053 ;; This seems a bit complex. We look for references such as !!, !-num,
1054 ;; !foo, !?foo, !{bar}, !?{bar}, ^oh, ^my^, ^god^it, ^never^ends^.
1055 ;; If that wasn't enough, the plings can be suffixed with argument
1056 ;; range specifiers.
1057 ;; Argument ranges are complex too, so we hive off the input line,
1058 ;; referenced with plings, with the range string to `comint-args'.
1059 (setq comint-input-ring-index nil)
1060 (goto-char (match-beginning 0)) ; XEmacs
1061 (cond ((or (= (preceding-char) ?\\)
1062 (comint-within-quotes start (point)))
1063 ;; The history is quoted, or we're in quotes.
1064 (goto-char (match-end 0))) ; XEmacs
1065 ((looking-at "![0-9]+\\($\\|[^-]\\)")
1066 ;; We cannot know the interpreter's idea of input line numbers.
1067 (goto-char (match-end 0))
1068 (message "Absolute reference cannot be expanded"))
1069 ((looking-at "!-\\([0-9]+\\)\\(:?[0-9^$*-]+\\)?")
1070 ;; Just a number of args from `number' lines backward.
1071 (let ((number (1- (string-to-number
1072 (buffer-substring (match-beginning 1)
1073 (match-end 1))))))
1074 (if (<= number (ring-length comint-input-ring))
1075 (progn
1076 (replace-match
1077 (comint-args (comint-previous-input-string number)
1078 (match-beginning 2) (match-end 2))
1079 t t)
1080 (setq comint-input-ring-index number)
1081 (message "History item: %d" (1+ number)))
1082 (goto-char (match-end 0))
1083 (message "Relative reference exceeds input history size"))))
1084 ((or (looking-at "!!?:?\\([0-9^$*-]+\\)") (looking-at "!!"))
1085 ;; Just a number of args from the previous input line.
1086 (replace-match
1087 (comint-args (comint-previous-input-string 0)
1088 (match-beginning 1) (match-end 1)) t t)
1089 (message "History item: previous"))
1090 ((looking-at
1091 "!\\??\\({\\(.+\\)}\\|\\(\\sw+\\)\\)\\(:?[0-9^$*-]+\\)?")
1092 ;; Most recent input starting with or containing (possibly
1093 ;; protected) string, maybe just a number of args. Phew.
1094 (let* ((mb1 (match-beginning 1)) (me1 (match-end 1))
1095 (mb2 (match-beginning 2)) (me2 (match-end 2))
1096 (exp (buffer-substring (or mb2 mb1) (or me2 me1)))
1097 (pref (if (save-match-data (looking-at "!\\?")) "" "^"))
1098 (pos (save-match-data
1099 (comint-previous-matching-input-string-position
1100 (concat pref (regexp-quote exp)) 1))))
1101 (if (null pos)
1102 (progn
1103 (goto-char (match-end 0))
1104 (or silent
1105 (progn (message "Not found")
1106 (ding))))
1107 (setq comint-input-ring-index pos)
1108 (replace-match
1109 (comint-args (ring-ref comint-input-ring pos)
1110 (match-beginning 4) (match-end 4))
1111 t t)
1112 (message "History item: %d" (1+ pos)))))
1113 ((looking-at "\\^\\([^^]+\\)\\^?\\([^^]*\\)\\^?")
1114 ;; Quick substitution on the previous input line.
1115 (let ((old (buffer-substring (match-beginning 1) (match-end 1)))
1116 (new (buffer-substring (match-beginning 2) (match-end 2)))
1117 (pos nil))
1118 (replace-match (comint-previous-input-string 0) t t)
1119 (setq pos (point))
1120 (goto-char (match-beginning 0))
1121 (if (not (search-forward old pos t))
1122 (or silent
1123 (error "Not found"))
1124 (replace-match new t t)
1125 (message "History item: substituted"))))
1126 (t
1127 (goto-char (match-end 0))))))))
1128
1129
1130 (defun comint-magic-space (arg)
1131 "Expand input history references before point and insert ARG spaces.
1132 A useful command to bind to SPC. See `comint-replace-by-expanded-history'."
1133 (interactive "p")
1134 (comint-replace-by-expanded-history)
1135 (self-insert-command arg))
1136
1137 (defun comint-within-quotes (beg end)
1138 "Return t if the number of quotes between BEG and END is odd.
1139 Quotes are single and double."
1140 (let ((countsq (comint-how-many-region "\\(^\\|[^\\\\]\\)\'" beg end))
1141 (countdq (comint-how-many-region "\\(^\\|[^\\\\]\\)\"" beg end)))
1142 (or (= (mod countsq 2) 1) (= (mod countdq 2) 1))))
1143
1144 (defun comint-how-many-region (regexp beg end)
1145 "Return number of matches for REGEXP from BEG to END."
1146 (let ((count 0))
1147 (save-excursion
1148 (save-match-data
1149 (goto-char beg)
1150 (while (re-search-forward regexp end t)
1151 (setq count (1+ count)))))
1152 count))
1153
1154 (defun comint-args (string begin end)
1155 ;; From STRING, return the args depending on the range specified in the text
1156 ;; from BEGIN to END. If BEGIN is nil, assume all args. Ignore leading `:'.
1157 ;; Range can be x-y, x-, -y, where x/y can be [0-9], *, ^, $.
1158 (save-match-data
1159 (if (null begin)
1160 (comint-arguments string 0 nil)
1161 (let* ((range (buffer-substring
1162 (if (eq (char-after begin) ?:) (1+ begin) begin) end))
1163 (nth (cond ((string-match "^[*^]" range) 1)
1164 ((string-match "^-" range) 0)
1165 ((string-equal range "$") nil)
1166 (t (string-to-number range))))
1167 (mth (cond ((string-match "[-*$]$" range) nil)
1168 ((string-match "-" range)
1169 (string-to-number (substring range (match-end 0))))
1170 (t nth))))
1171 (comint-arguments string nth mth)))))
1172
1173 ;; Return a list of arguments from ARG. Break it up at the
1174 ;; delimiters in comint-delimiter-argument-list. Returned list is backwards.
1175 (defun comint-delim-arg (arg)
1176 (if (null comint-delimiter-argument-list)
1177 (list arg)
1178 (let ((args nil)
1179 (pos 0)
1180 (len (length arg)))
1181 (while (< pos len)
1182 (let ((char (aref arg pos))
1183 (start pos))
1184 (if (memq char comint-delimiter-argument-list)
1185 (while (and (< pos len) (eq (aref arg pos) char))
1186 (setq pos (1+ pos)))
1187 (while (and (< pos len)
1188 (not (memq (aref arg pos)
1189 comint-delimiter-argument-list)))
1190 (setq pos (1+ pos))))
1191 (setq args (cons (substring arg start pos) args))))
1192 args)))
1193
1194 (defun comint-arguments (string nth mth)
1195 "Return from STRING the NTH to MTH arguments.
1196 NTH and/or MTH can be nil, which means the last argument.
1197 Returned arguments are separated by single spaces.
1198 We assume whitespace separates arguments, except within quotes.
1199 Also, a run of one or more of a single character
1200 in `comint-delimiter-argument-list' is a separate argument.
1201 Argument 0 is the command name."
1202 (let ((argpart "[^ \n\t\"'`]+\\|\\(\"[^\"]*\"\\|'[^']*'\\|`[^`]*`\\)")
1203 (args ()) (pos 0)
1204 (count 0)
1205 beg str value quotes)
1206 ;; Build a list of all the args until we have as many as we want.
1207 (while (and (or (null mth) (<= count mth))
1208 (string-match argpart string pos))
1209 (if (and beg (= pos (match-beginning 0)))
1210 ;; It's contiguous, part of the same arg.
1211 (setq pos (match-end 0)
1212 quotes (or quotes (match-beginning 1)))
1213 ;; It's a new separate arg.
1214 (if beg
1215 ;; Put the previous arg, if there was one, onto ARGS.
1216 (setq str (substring string beg pos)
1217 args (if quotes (cons str args)
1218 (nconc (comint-delim-arg str) args))
1219 count (1+ count)))
1220 (setq quotes (match-beginning 1))
1221 (setq beg (match-beginning 0))
1222 (setq pos (match-end 0))))
1223 (if beg
1224 (setq str (substring string beg pos)
1225 args (if quotes (cons str args)
1226 (nconc (comint-delim-arg str) args))
1227 count (1+ count)))
1228 (let ((n (or nth (1- count)))
1229 (m (if mth (1- (- count mth)) 0)))
1230 (mapconcat
1231 (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " "))))
1232
1233 ;;;
1234 ;;; Input processing stuff
1235 ;;;
1236
1237 (defun comint-send-input ()
1238 "Send input to process.
1239 After the process output mark, sends all text from the process mark to
1240 point as input to the process. Before the process output mark, calls value
1241 of variable `comint-get-old-input' to retrieve old input, copies it to the
1242 process mark, and sends it. If variable `comint-process-echoes' is nil,
1243 a terminal newline is also inserted into the buffer and sent to the process
1244 \(if it is non-nil, all text from the process mark to point is deleted,
1245 since it is assumed the remote process will re-echo it).
1246
1247 Any history reference may be expanded depending on the value of the variable
1248 `comint-input-autoexpand'. The list of function names contained in the value
1249 of `comint-input-filter-functions' is called on the input before sending it.
1250 The input is entered into the input history ring, if the value of variable
1251 `comint-input-filter' returns non-nil when called on the input.
1252
1253 If variable `comint-eol-on-send' is non-nil, then point is moved to the
1254 end of line before sending the input.
1255
1256 If variable `comint-append-old-input' is non-nil, then the results of
1257 calling `comint-get-old-input' are appended to the end of the buffer.
1258 The new input will combine with any partially-typed text already present
1259 after the process output mark. Point is moved just before the newly
1260 appended input, and a message is displayed prompting the user to type
1261 \\[comint-send-input] again.
1262
1263 The values of `comint-get-old-input', `comint-input-filter-functions' and
1264 `comint-input-filter' are chosen according to the command interpreter running
1265 in the buffer. E.g.,
1266
1267 If the interpreter is the csh,
1268 comint-get-old-input is the default: take the current line, discard any
1269 initial string matching regexp comint-prompt-regexp.
1270 comint-input-filter-functions monitors input for \"cd\", \"pushd\", and
1271 \"popd\" commands. When it sees one, it cd's the buffer.
1272 comint-input-filter is the default: returns t if the input isn't all white
1273 space.
1274
1275 If the comint is Lucid Common Lisp,
1276 comint-get-old-input snarfs the sexp ending at point.
1277 comint-input-filter-functions does nothing.
1278 comint-input-filter returns nil if the input matches input-filter-regexp,
1279 which matches (1) all whitespace (2) :a, :c, etc.
1280
1281 Similarly for Soar, Scheme, etc."
1282 (interactive)
1283 ;; Note that the input string does not include its terminal newline.
1284 (let ((proc (get-buffer-process (current-buffer))))
1285 (if (not proc) (error "Current buffer has no process")
1286 (let* ((pmark (process-mark proc))
1287 (pmark-val (marker-position pmark))
1288 ;; XEmacs - change by John Rose: confirm before sending input if
1289 ;; not after process mark.
1290 (append-here nil)
1291 (intxt (if (>= (point) pmark-val)
1292 (progn (if comint-eol-on-send (end-of-line))
1293 (buffer-substring pmark (point)))
1294 (let ((copy (funcall comint-get-old-input)))
1295 (push-mark)
1296 (if (not comint-append-old-input)
1297 (goto-char pmark-val)
1298 (setq append-here (point-max))
1299 (goto-char append-here))
1300 (insert copy)
1301 copy)))
1302 (input (if (not (eq comint-input-autoexpand 'input))
1303 ;; Just whatever's already there
1304 intxt
1305 ;; Expand and leave it visible in buffer
1306 (comint-replace-by-expanded-history t)
1307 (buffer-substring pmark (point))))
1308 (history (if (not (eq comint-input-autoexpand 'history))
1309 (if (eq comint-input-autoexpand nil)
1310 ;; XEmacs - nil means leave it alone!
1311 input
1312 (comint-arguments input 0 nil))
1313 ;; This is messy 'cos ultimately the original
1314 ;; functions used do insertion, rather than return
1315 ;; strings. We have to expand, then insert back.
1316 (comint-replace-by-expanded-history t)
1317 (let ((copy (buffer-substring pmark (point))))
1318 (delete-region pmark (point))
1319 (insert input)
1320 (comint-arguments copy 0 nil)))))
1321 (if append-here
1322 (progn
1323 (goto-char append-here)
1324 (message
1325 (substitute-command-keys
1326 "(\\[comint-send-input] to confirm)")))
1327 (if comint-process-echoes
1328 (delete-region pmark (point))
1329 (insert ?\n))
1330 (if (and (funcall comint-input-filter history)
1331 (or (null comint-input-ignoredups)
1332 (not (ring-p comint-input-ring))
1333 (ring-empty-p comint-input-ring)
1334 (not (string-equal (ring-ref comint-input-ring 0)
1335 history))))
1336 (ring-insert comint-input-ring history))
1337 ;; XEmacs - run the input filters on the history instead
1338 ;; of the input, so that the input sentinel is called on the
1339 ;; history-expanded text and sees "cd foo" instead of "cd !$".
1340 (run-hook-with-args 'comint-input-filter-functions
1341 (concat history "\n"))
1342 (setq comint-input-ring-index nil)
1343 ;; Update the markers before we send the input
1344 ;; in case we get output amidst sending the input.
1345 (set-marker comint-last-input-start pmark)
1346 (set-marker comint-last-input-end (point))
1347 (set-marker (process-mark proc) (point))
1348 (funcall comint-input-sender proc input)
1349 ;; XEmacs - A kludge to prevent the delay between insert and
1350 ;; process output affecting the display. A case for a
1351 ;; comint-send-input-hook?
1352 (run-hook-with-args 'comint-output-filter-functions
1353 (concat input "\n"))
1354 (comint-output-filter proc "")
1355 )))))
1356
1357 ;; The purpose of using this filter for comint processes
1358 ;; is to keep comint-last-input-end from moving forward
1359 ;; when output is inserted.
1360 (defun comint-output-filter (process string)
1361 ;; First check for killed buffer
1362 (let ((oprocbuf (process-buffer process)))
1363 (if (and oprocbuf (buffer-name oprocbuf))
1364 (let ((obuf (current-buffer))
1365 (opoint nil) (obeg nil) (oend nil))
1366 (set-buffer oprocbuf)
1367 (setq string (replace-in-string string "\^M" "")
1368 opoint (point)
1369 obeg (point-min)
1370 oend (point-max))
1371 (let ((buffer-read-only nil)
1372 (nchars (length string))
1373 (ostart nil))
1374 (widen)
1375 (goto-char (process-mark process))
1376 (setq ostart (point))
1377 (if (<= (point) opoint)
1378 (setq opoint (+ opoint nchars)))
1379 ;; Insert after old_begv, but before old_zv.
1380 (if (< (point) obeg)
1381 (setq obeg (+ obeg nchars)))
1382 (if (<= (point) oend)
1383 (setq oend (+ oend nchars)))
1384 (insert-before-markers string)
1385 ;; Don't insert initial prompt outside the top of the window.
1386 (if (= (window-start (selected-window)) (point))
1387 (set-window-start (selected-window) (- (point) (length string))))
1388 (if (and comint-last-input-end
1389 (marker-buffer comint-last-input-end)
1390 (= (point) comint-last-input-end))
1391 (set-marker comint-last-input-end (- comint-last-input-end nchars)))
1392 (set-marker comint-last-output-start ostart)
1393 (set-marker (process-mark process) (point))
1394 (redraw-modeline))
1395
1396 (narrow-to-region obeg oend)
1397 (goto-char opoint)
1398 (run-hook-with-args 'comint-output-filter-functions string)
1399 (set-buffer obuf)))))
1400
1401 ;; XEmacs - Use a variable for this so that new commands can be added easily.
1402 (defvar comint-scroll-to-bottom-on-input-commands
1403 '(self-insert-command
1404 mouse-yank
1405 mouse-yank-at-click
1406 x-insert-selection
1407 comint-previous-input
1408 comint-next-input
1409 comint-previous-matching-input
1410 comint-next-matching-input
1411 comint-previous-matching-input-from-input
1412 comint-next-matching-input-from-input
1413 )
1414 "List of functions which will cause the point to move to the end of comint buffers.")
1415
1416 (defun comint-preinput-scroll-to-bottom ()
1417 "Go to the end of buffer in all windows showing it.
1418 Movement occurs if point in the selected window is not after the process mark,
1419 and `this-command' is an insertion command. Insertion commands recognised
1420 are those in `comint-scroll-to-bottom-on-input-commands'.
1421 Depends on the value of `comint-scroll-to-bottom-on-input'.
1422
1423 This function should be a pre-command hook."
1424 (if (and comint-scroll-to-bottom-on-input
1425 (memq this-command comint-scroll-to-bottom-on-input-commands))
1426 (let* ((selected (selected-window))
1427 (current (current-buffer))
1428 (process (get-buffer-process current))
1429 (scroll comint-scroll-to-bottom-on-input))
1430 (if (and process (< (point) (process-mark process))
1431 scroll (not (window-minibuffer-p selected)))
1432 (if (eq scroll 'this)
1433 (goto-char (point-max))
1434 (walk-windows
1435 (function (lambda (window)
1436 (if (and (eq (window-buffer window) current)
1437 (or (eq scroll t) (eq scroll 'all)))
1438 ;; XEmacs - fsf does this the hard way.
1439 (set-window-point window (point-max))
1440 )))
1441 'not-minibuf t))))))
1442
1443 (defun comint-postoutput-scroll-to-bottom (string)
1444 "Go to the end of buffer in all windows showing it.
1445 Does not scroll if the current line is the last line in the buffer.
1446 Depends on the value of `comint-scroll-to-bottom-on-output' and
1447 `comint-scroll-show-maximum-output'.
1448
1449 This function should be in the list `comint-output-filter-functions'."
1450 (let* ((selected (selected-window))
1451 (current (current-buffer))
1452 (process (get-buffer-process current))
1453 (scroll comint-scroll-to-bottom-on-output))
1454 ;; XEmacs - don't select windows as they're walked.
1455 (if process
1456 (walk-windows
1457 (function (lambda (window)
1458 (if (eq (window-buffer window) current)
1459 (progn
1460 (if (and (< (window-point window)
1461 (process-mark process))
1462 (or (eq scroll t) (eq scroll 'all)
1463 ;; Maybe user wants point to jump to the end.
1464 (and (eq scroll 'this)
1465 (eq selected window))
1466 (and (eq scroll 'others)
1467 (not (eq selected window)))
1468 ;; If point was at the end, keep it at the end.
1469 (>= (window-point window)
1470 (- (process-mark process) (length string)))))
1471 (set-window-point window (process-mark process)))
1472 ;; Optionally scroll so that the text
1473 ;; ends at the bottom of the window.
1474 (if (and comint-scroll-show-maximum-output
1475 (>= (window-point window)
1476 (process-mark process))
1477 ;; XEmacs - lemacs addition
1478 (not (pos-visible-in-window-p (point-max) window)))
1479 (save-excursion
1480 (set-window-point window (point-max))
1481 (recenter
1482 ;; XEmacs - lemacs addition
1483 ;; (cond ((integerp comint-scroll-show-maximum-output)
1484 ;; comint-scroll-show-maximum-output)
1485 ;; ((floatp comint-scroll-show-maximum-output)
1486 ;; (floor (* (window-height window)
1487 ;; comint-scroll-show-maximum-output)
1488 ;; 1))
1489 ;; (t
1490 ;; -1))
1491 )))
1492 ))))
1493 nil t))))
1494
1495 (defun comint-truncate-buffer (&optional string)
1496 "Truncate the buffer to `comint-buffer-maximum-size'.
1497 This function could be on `comint-output-filter-functions' or bound to a key."
1498 (interactive)
1499 (save-excursion
1500 (goto-char (point-max))
1501 (forward-line (- comint-buffer-maximum-size))
1502 (beginning-of-line)
1503 (delete-region (point-min) (point))))
1504
1505 (defun comint-strip-ctrl-m (&optional string)
1506 "Strip trailing `^M' characters from the current output group.
1507 This function could be on `comint-output-filter-functions' or bound to a key."
1508 (interactive)
1509 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
1510 (save-excursion
1511 (goto-char
1512 (if (interactive-p) comint-last-input-end comint-last-output-start))
1513 (while (re-search-forward "\r+$" pmark t)
1514 (replace-match "" t t)))))
1515 (defalias 'shell-strip-ctrl-m 'comint-strip-ctrl-m)
1516
1517 (defun comint-show-maximum-output ()
1518 "Put the end of the buffer at the bottom of the window."
1519 (interactive)
1520 (goto-char (point-max))
1521 (recenter -1))
1522
1523 (defun comint-get-old-input-default ()
1524 "Default for `comint-get-old-input'.
1525 Take the current line, and discard any initial text matching
1526 `comint-prompt-regexp'."
1527 (save-excursion
1528 (beginning-of-line)
1529 (comint-skip-prompt)
1530 (let ((beg (point)))
1531 (end-of-line)
1532 (buffer-substring beg (point)))))
1533
1534 (defun comint-copy-old-input ()
1535 "Insert after prompt old input at point as new input to be edited.
1536 Calls `comint-get-old-input' to get old input."
1537 (interactive)
1538 (let ((input (funcall comint-get-old-input))
1539 (process (get-buffer-process (current-buffer))))
1540 (if (not process)
1541 (error "Current buffer has no process")
1542 (goto-char (process-mark process))
1543 (insert input))))
1544
1545 (defun comint-skip-prompt ()
1546 "Skip past the text matching regexp `comint-prompt-regexp'.
1547 If this takes us past the end of the current line, don't skip at all."
1548 (let ((eol (save-excursion (end-of-line) (point)))
1549 ;; XEmacs - Arbitrary limit: prompt can be up to 10 lines long.
1550 (search-limit (save-excursion (forward-line -10) (point))))
1551 (if (and (save-excursion
1552 (goto-char eol)
1553 (re-search-backward comint-prompt-regexp search-limit t))
1554 (<= (match-beginning 0) (point))
1555 (> (match-end 0) (point))
1556 (<= (match-end 0) eol))
1557 (goto-char (match-end 0)))))
1558
1559 (defun comint-after-pmark-p ()
1560 "Return t if point is after the process output marker."
1561 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
1562 (<= (marker-position pmark) (point))))
1563
1564 (defun comint-simple-send (proc string)
1565 "Default function for sending to PROC input STRING.
1566 This just sends STRING plus a newline. To override this,
1567 set the hook `comint-input-sender'."
1568 (comint-send-string proc string)
1569 (comint-send-string proc "\n"))
1570
1571 ;; XEmacs - fsf doesn't bind this to ^A, but we do. There is some merit to
1572 ;; their change, so we change the behavior of the function to act the same
1573 ;; as normal ^A unless we're after the process mark. For the old behavior,
1574 ;; use ^C^A as in FSF. --Stig
1575 (defun comint-bol (arg)
1576 "Goes to the beginning of line, then skips past the prompt, if any.
1577 If prefix argument is given (\\[universal-argument]) the prompt is not skipped.
1578
1579 The prompt skip is done by skipping text matching the regular expression
1580 `comint-prompt-regexp', a buffer local variable."
1581 (interactive "_P")
1582 (let ((skip (and (null arg)
1583 (or (not (eq (lookup-key global-map (this-command-keys))
1584 'beginning-of-line))
1585 ;; If the buffer's process has gone bye-bye
1586 ;; revert to being just beginning-of-line.
1587 (not (get-buffer-process (current-buffer)))
1588 (comint-after-pmark-p)))))
1589 (beginning-of-line)
1590 (if skip (comint-skip-prompt))))
1591
1592 ;; XEmacs - more like an xterm interaction model...
1593 (defun comint-universal-argument ()
1594 "Erase the current line of input, or begin a numeric argument.
1595
1596 In buffers with interactive subprocesses, this modified version of
1597 `universal-argument' erases the current line of user input just as ^U erases a
1598 line of text at the UNIX command prompt.
1599
1600 Otherwise, begin a numeric argument for the following command.
1601 Digits or minus sign following \\[universal-argument] make up the numeric argument.
1602 \\[universal-argument] following the digits or minus sign ends the argument.
1603 \\[universal-argument] without digits or minus sign provides 4 as argument.
1604 Repeating \\[universal-argument] without digits or minus sign
1605 multiplies the argument by 4 each time."
1606 (interactive)
1607 (let ((proc (get-buffer-process (current-buffer))))
1608 (if (and proc (> (point) (process-mark proc)))
1609 (progn (comint-bol nil)
1610 (kill-region (point) (save-excursion (end-of-line) (point))))
1611 (let (key)
1612 (setq key (read-key-sequence nil t))
1613 (while (equal (key-binding key) 'universal-argument)
1614 (setq key (read-key-sequence nil t)))))))
1615
1616 ;;; These three functions are for entering text you don't want echoed or
1617 ;;; saved -- typically passwords to ftp, telnet, or somesuch.
1618 ;;; Just enter m-x send-invisible and type in your line, or add
1619 ;;; `comint-watch-for-password-prompt' to `comint-output-filter-functions'.
1620
1621 ;; XEmacs has a standard function for this.
1622 (defun comint-read-noecho (prompt &optional stars)
1623 "Read a password from the user.
1624 See documentation of `read-passwd' for more info."
1625 (read-passwd prompt))
1626
1627 (defun send-invisible (str)
1628 "Read a string without echoing.
1629 Then send it to the process running in the current buffer. A new-line
1630 is additionally sent. String is not saved on comint input history list.
1631 Security bug: your string can still be temporarily recovered with
1632 \\[view-lossage]."
1633 (interactive "P") ; Defeat snooping via C-x esc
1634 (let ((proc (get-buffer-process (current-buffer))))
1635 (if (not proc)
1636 (error "Current buffer has no process")
1637 (comint-send-string
1638 proc (if (stringp str) str (comint-read-noecho "Non-echoed text: " t)))
1639 (comint-send-string proc "\n"))))
1640
1641 (defun comint-watch-for-password-prompt (string)
1642 "Prompt in the minibuffer for password and send without echoing.
1643 This function uses `send-invisible' to read and send a password to the buffer's
1644 process if STRING contains a password prompt defined by
1645 `comint-password-prompt-regexp'.
1646
1647 This function could be in the list `comint-output-filter-functions'."
1648 (if (string-match comint-password-prompt-regexp string)
1649 (send-invisible nil)))
1650
1651 ;;; Low-level process communication
1652
1653 (defalias 'comint-send-string 'process-send-string)
1654 (defalias 'comint-send-region 'process-send-region)
1655
1656 ;;; Random input hackage
1657
1658 (defun comint-kill-output ()
1659 "Kill all output from interpreter since last input.
1660 Does not delete the prompt."
1661 (interactive)
1662 (let ((proc (get-buffer-process (current-buffer)))
1663 (replacement nil))
1664 (save-excursion
1665 (let ((pmark (progn (goto-char (process-mark proc))
1666 (beginning-of-line nil)
1667 (point-marker))))
1668 ;; XEmacs - kill in case we want it back...
1669 (kill-region comint-last-input-end pmark)
1670 (goto-char (process-mark proc))
1671 (setq replacement (concat "*** output flushed ***\n"
1672 (buffer-substring pmark (point))))
1673 (delete-region pmark (point))))
1674 ;; Output message and put back prompt
1675 (comint-output-filter proc replacement)))
1676
1677 ;; XEmacs - don't move cursor unless necessary...
1678 (defun comint-show-output ()
1679 "Display start of this batch of interpreter output at top of window.
1680 Also put cursor there if the current position is not visible.
1681 If the cursor is moved, then a mark is set at its old location."
1682 (interactive)
1683 (let ((pos (point)))
1684 (goto-char (or (marker-position comint-last-input-end) (point-max)))
1685 (beginning-of-line 0)
1686 (set-window-start (selected-window) (point))
1687 (if (pos-visible-in-window-p pos)
1688 (goto-char pos)
1689 (save-excursion
1690 (goto-char pos)
1691 (push-mark))
1692 (comint-skip-prompt))))
1693
1694 (defun comint-interrupt-subjob ()
1695 "Interrupt the current subjob."
1696 (interactive)
1697 (interrupt-process nil comint-ptyp))
1698
1699 (defun comint-kill-subjob ()
1700 "Send kill signal to the current subjob."
1701 (interactive)
1702 (kill-process nil comint-ptyp))
1703
1704 (defun comint-quit-subjob ()
1705 "Send quit signal to the current subjob."
1706 (interactive)
1707 (quit-process nil comint-ptyp))
1708
1709 (defun comint-stop-subjob ()
1710 "Stop the current subjob.
1711 WARNING: if there is no current subjob, you can end up suspending
1712 the top-level process running in the buffer. If you accidentally do
1713 this, use \\[comint-continue-subjob] to resume the process. (This
1714 is not a problem with most shells, since they ignore this signal.)"
1715 (interactive)
1716 (stop-process nil comint-ptyp))
1717
1718 (defun comint-continue-subjob ()
1719 "Send CONT signal to process buffer's process group.
1720 Useful if you accidentally suspend the top-level process."
1721 (interactive)
1722 (continue-process nil comint-ptyp))
1723
1724 (defun comint-kill-input ()
1725 "Kill all text from last stuff output by interpreter to point."
1726 (interactive)
1727 (let ((pmark (process-mark (get-buffer-process (current-buffer)))))
1728 (if (> (point) (marker-position pmark))
1729 (kill-region pmark (point)))))
1730
1731 (defun comint-delchar-or-maybe-eof (arg)
1732 "Delete ARG characters forward, or (if at eob) send an EOF to subprocess."
1733 (interactive "p")
1734 (if (eobp)
1735 (process-send-eof)
1736 (delete-char arg)))
1737
1738 (defun comint-send-eof ()
1739 "Send an EOF to the current buffer's process."
1740 (interactive)
1741 (process-send-eof))
1742
1743
1744 (defun comint-backward-matching-input (regexp arg)
1745 "Search backward through buffer for match for REGEXP.
1746 Matches are searched for on lines that match `comint-prompt-regexp'.
1747 With prefix argument N, search for Nth previous match.
1748 If N is negative, find the next or Nth next match."
1749 (interactive (comint-regexp-arg "Backward input matching (regexp): "))
1750 (let* ((re (concat comint-prompt-regexp ".*" regexp))
1751 (pos (save-excursion (end-of-line (if (> arg 0) 0 1))
1752 (if (re-search-backward re nil t arg)
1753 (point)))))
1754 (if (null pos)
1755 (progn (message "Not found")
1756 (ding))
1757 (goto-char pos)
1758 (comint-bol nil))))
1759
1760 (defun comint-forward-matching-input (regexp arg)
1761 "Search forward through buffer for match for REGEXP.
1762 Matches are searched for on lines that match `comint-prompt-regexp'.
1763 With prefix argument N, search for Nth following match.
1764 If N is negative, find the previous or Nth previous match."
1765 (interactive (comint-regexp-arg "Forward input matching (regexp): "))
1766 (comint-backward-matching-input regexp (- arg)))
1767
1768
1769 (defun comint-next-prompt (n)
1770 "Move to end of Nth next prompt in the buffer.
1771 See `comint-prompt-regexp'."
1772 (interactive "_p") ; XEmacs - zmacs-regions
1773 (let ((paragraph-start comint-prompt-regexp))
1774 (end-of-line (if (> n 0) 1 0))
1775 (forward-paragraph n)
1776 (comint-skip-prompt)))
1777
1778 (defun comint-previous-prompt (n)
1779 "Move to end of Nth previous prompt in the buffer.
1780 See `comint-prompt-regexp'."
1781 (interactive "_p") ; XEmacs
1782 (comint-next-prompt (- n)))
1783
1784 ;;; Support for source-file processing commands.
1785 ;;;============================================================================
1786 ;;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
1787 ;;; commands that process files of source text (e.g. loading or compiling
1788 ;;; files). So the corresponding process-in-a-buffer modes have commands
1789 ;;; for doing this (e.g., lisp-load-file). The functions below are useful
1790 ;;; for defining these commands.
1791 ;;;
1792 ;;; Alas, these guys don't do exactly the right thing for Lisp, Scheme
1793 ;;; and Soar, in that they don't know anything about file extensions.
1794 ;;; So the compile/load interface gets the wrong default occasionally.
1795 ;;; The load-file/compile-file default mechanism could be smarter -- it
1796 ;;; doesn't know about the relationship between filename extensions and
1797 ;;; whether the file is source or executable. If you compile foo.lisp
1798 ;;; with compile-file, then the next load-file should use foo.bin for
1799 ;;; the default, not foo.lisp. This is tricky to do right, particularly
1800 ;;; because the extension for executable files varies so much (.o, .bin,
1801 ;;; .lbin, .mo, .vo, .ao, ...).
1802
1803
1804 ;;; COMINT-SOURCE-DEFAULT -- determines defaults for source-file processing
1805 ;;; commands.
1806 ;;;
1807 ;;; COMINT-CHECK-SOURCE -- if FNAME is in a modified buffer, asks you if you
1808 ;;; want to save the buffer before issuing any process requests to the command
1809 ;;; interpreter.
1810 ;;;
1811 ;;; COMINT-GET-SOURCE -- used by the source-file processing commands to prompt
1812 ;;; for the file to process.
1813
1814 ;;; (COMINT-SOURCE-DEFAULT previous-dir/file source-modes)
1815 ;;;============================================================================
1816 ;;; This function computes the defaults for the load-file and compile-file
1817 ;;; commands for tea, soar, cmulisp, and cmuscheme modes.
1818 ;;;
1819 ;;; - PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
1820 ;;; source-file processing command. NIL if there hasn't been one yet.
1821 ;;; - SOURCE-MODES is a list used to determine what buffers contain source
1822 ;;; files: if the major mode of the buffer is in SOURCE-MODES, it's source.
1823 ;;; Typically, (lisp-mode) or (scheme-mode).
1824 ;;;
1825 ;;; If the command is given while the cursor is inside a string, *and*
1826 ;;; the string is an existing filename, *and* the filename is not a directory,
1827 ;;; then the string is taken as default. This allows you to just position
1828 ;;; your cursor over a string that's a filename and have it taken as default.
1829 ;;;
1830 ;;; If the command is given in a file buffer whose major mode is in
1831 ;;; SOURCE-MODES, then the the filename is the default file, and the
1832 ;;; file's directory is the default directory.
1833 ;;;
1834 ;;; If the buffer isn't a source file buffer (e.g., it's the process buffer),
1835 ;;; then the default directory & file are what was used in the last source-file
1836 ;;; processing command (i.e., PREVIOUS-DIR/FILE). If this is the first time
1837 ;;; the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
1838 ;;; is the cwd, with no default file. (\"no default file\" = nil)
1839 ;;;
1840 ;;; SOURCE-REGEXP is typically going to be something like (tea-mode)
1841 ;;; for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
1842 ;;; for Soar programs, etc.
1843 ;;;
1844 ;;; The function returns a pair: (default-directory . default-file).
1845
1846 (defun comint-source-default (previous-dir/file source-modes)
1847 (cond ((and buffer-file-name (memq major-mode source-modes))
1848 (cons (file-name-directory buffer-file-name)
1849 (file-name-nondirectory buffer-file-name)))
1850 (previous-dir/file)
1851 (t
1852 (cons default-directory nil))))
1853
1854
1855 ;;; (COMINT-CHECK-SOURCE fname)
1856 ;;;============================================================================
1857 ;;; Prior to loading or compiling (or otherwise processing) a file (in the CMU
1858 ;;; process-in-a-buffer modes), this function can be called on the filename.
1859 ;;; If the file is loaded into a buffer, and the buffer is modified, the user
1860 ;;; is queried to see if he wants to save the buffer before proceeding with
1861 ;;; the load or compile.
1862
1863 (defun comint-check-source (fname)
1864 (let ((buff (get-file-buffer fname)))
1865 (if (and buff
1866 (buffer-modified-p buff)
1867 (y-or-n-p (format "Save buffer %s first? " (buffer-name buff))))
1868 ;; save BUFF.
1869 (let ((old-buffer (current-buffer)))
1870 (set-buffer buff)
1871 (save-buffer)
1872 (set-buffer old-buffer)))))
1873
1874
1875 ;;; (COMINT-GET-SOURCE prompt prev-dir/file source-modes mustmatch-p)
1876 ;;;============================================================================
1877 ;;; COMINT-GET-SOURCE is used to prompt for filenames in command-interpreter
1878 ;;; commands that process source files (like loading or compiling a file).
1879 ;;; It prompts for the filename, provides a default, if there is one,
1880 ;;; and returns the result filename.
1881 ;;;
1882 ;;; See COMINT-SOURCE-DEFAULT for more on determining defaults.
1883 ;;;
1884 ;;; PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
1885 ;;; from the last source processing command. SOURCE-MODES is a list of major
1886 ;;; modes used to determine what file buffers contain source files. (These
1887 ;;; two arguments are used for determining defaults). If MUSTMATCH-P is true,
1888 ;;; then the filename reader will only accept a file that exists.
1889 ;;;
1890 ;;; A typical use:
1891 ;;; (interactive (comint-get-source "Compile file: " prev-lisp-dir/file
1892 ;;; '(lisp-mode) t))
1893
1894 ;;; This is pretty stupid about strings. It decides we're in a string
1895 ;;; if there's a quote on both sides of point on the current line.
1896 (defun comint-extract-string ()
1897 "Return string around POINT that starts the current line, or nil."
1898 (save-excursion
1899 (let* ((point (point))
1900 (bol (progn (beginning-of-line) (point)))
1901 (eol (progn (end-of-line) (point)))
1902 (start (progn (goto-char point)
1903 (and (search-backward "\"" bol t)
1904 (1+ (point)))))
1905 (end (progn (goto-char point)
1906 (and (search-forward "\"" eol t)
1907 (1- (point))))))
1908 (and start end
1909 (buffer-substring start end)))))
1910
1911 (defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p)
1912 (let* ((def (comint-source-default prev-dir/file source-modes))
1913 (stringfile (comint-extract-string))
1914 (sfile-p (and stringfile
1915 (condition-case ()
1916 (file-exists-p stringfile)
1917 (error nil))
1918 (not (file-directory-p stringfile))))
1919 (defdir (if sfile-p (file-name-directory stringfile)
1920 (car def)))
1921 (deffile (if sfile-p (file-name-nondirectory stringfile)
1922 (cdr def)))
1923 (ans (read-file-name (if deffile (format "%s(default %s) "
1924 prompt deffile)
1925 prompt)
1926 defdir
1927 (concat defdir deffile)
1928 mustmatch-p)))
1929 (list (expand-file-name (substitute-in-file-name ans)))))
1930
1931 ;;; I am somewhat divided on this string-default feature. It seems
1932 ;;; to violate the principle-of-least-astonishment, in that it makes
1933 ;;; the default harder to predict, so you actually have to look and see
1934 ;;; what the default really is before choosing it. This can trip you up.
1935 ;;; On the other hand, it can be useful, I guess. I would appreciate feedback
1936 ;;; on this.
1937 ;;; -Olin
1938
1939
1940 ;;; Simple process query facility.
1941 ;;; ===========================================================================
1942 ;;; This function is for commands that want to send a query to the process
1943 ;;; and show the response to the user. For example, a command to get the
1944 ;;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
1945 ;;; to an inferior Common Lisp process.
1946 ;;;
1947 ;;; This simple facility just sends strings to the inferior process and pops
1948 ;;; up a window for the process buffer so you can see what the process
1949 ;;; responds with. We don't do anything fancy like try to intercept what the
1950 ;;; process responds with and put it in a pop-up window or on the message
1951 ;;; line. We just display the buffer. Low tech. Simple. Works good.
1952
1953 ;;; Send to the inferior process PROC the string STR. Pop-up but do not select
1954 ;;; a window for the inferior process so that its response can be seen.
1955 (defun comint-proc-query (proc str)
1956 (let* ((proc-buf (process-buffer proc))
1957 (proc-mark (process-mark proc)))
1958 (display-buffer proc-buf)
1959 (set-buffer proc-buf) ; but it's not the selected *window*
1960 (let ((proc-win (get-buffer-window proc-buf))
1961 (proc-pt (marker-position proc-mark)))
1962 (comint-send-string proc str) ; send the query
1963 (accept-process-output proc) ; wait for some output
1964 ;; Try to position the proc window so you can see the answer.
1965 ;; This is bogus code. If you delete the (sit-for 0), it breaks.
1966 ;; I don't know why. Wizards invited to improve it.
1967 (if (not (pos-visible-in-window-p proc-pt proc-win))
1968 (let ((opoint (window-point proc-win)))
1969 (set-window-point proc-win proc-mark)
1970 (sit-for 0)
1971 (if (not (pos-visible-in-window-p opoint proc-win))
1972 (push-mark opoint)
1973 (set-window-point proc-win opoint)))))))
1974
1975
1976 ;;; Filename/command/history completion in a buffer
1977 ;;; ===========================================================================
1978 ;;; Useful completion functions, courtesy of the Ergo group.
1979
1980 ;;; Six commands:
1981 ;;; comint-dynamic-complete Complete or expand command, filename,
1982 ;;; history at point.
1983 ;;; comint-dynamic-complete-filename Complete filename at point.
1984 ;;; comint-dynamic-list-filename-completions List completions in help buffer.
1985 ;;; comint-replace-by-expanded-filename Expand and complete filename at point;
1986 ;;; replace with expanded/completed name.
1987 ;;; comint-dynamic-simple-complete Complete stub given candidates.
1988
1989 ;;; These are not installed in the comint-mode keymap. But they are
1990 ;;; available for people who want them. Shell-mode installs them:
1991 ;;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
1992 ;;; (define-key shell-mode-map "\M-?"
1993 ;;; 'comint-dynamic-list-filename-completions)))
1994 ;;;
1995 ;;; Commands like this are fine things to put in load hooks if you
1996 ;;; want them present in specific modes.
1997
1998 (defvar comint-completion-autolist nil
1999 "*If non-nil, automatically list possiblities on partial completion.
2000 This mirrors the optional behavior of tcsh.")
2001
2002 (defvar comint-completion-addsuffix t
2003 "*If non-nil, add a `/' to completed directories, ` ' to file names.
2004 If a cons pair, it should be of the form (DIRSUFFIX . FILESUFFIX) where
2005 DIRSUFFIX and FILESUFFIX are strings added on unambiguous or exact completion.
2006 This mirrors the optional behavior of tcsh.")
2007
2008 (defvar comint-completion-recexact nil
2009 "*If non-nil, use shortest completion if characters cannot be added.
2010 This mirrors the optional behavior of tcsh.
2011
2012 A non-nil value is useful if `comint-completion-autolist' is non-nil too.")
2013
2014 (defvar comint-completion-fignore nil
2015 "*List of suffixes to be disregarded during file completion.
2016 This mirrors the optional behavior of bash and tcsh.
2017
2018 Note that this applies to `comint-dynamic-complete-filename' only.")
2019
2020 (defvar comint-file-name-prefix ""
2021 "Prefix prepended to absolute file names taken from process input.
2022 This is used by comint's and shell's completion functions, and by shell's
2023 directory tracking functions.")
2024
2025 (defvar comint-file-name-quote-list nil
2026 "List of characters to quote with `\' when in a file name.
2027
2028 This is a good thing to set in mode hooks.")
2029
2030
2031 (defun comint-directory (directory)
2032 ;; Return expanded DIRECTORY, with `comint-file-name-prefix' if absolute.
2033 (expand-file-name (if (file-name-absolute-p directory)
2034 (concat comint-file-name-prefix directory)
2035 directory)))
2036
2037
2038 (defun comint-word (word-chars)
2039 "Return the word of WORD-CHARS at point, or nil if non is found.
2040 Word constituents are considered to be those in WORD-CHARS, which is like the
2041 inside of a \"[...]\" (see `skip-chars-forward')."
2042 (save-excursion
2043 (let ((non-word-chars (concat "[^\\\\" word-chars "]")) (here (point)))
2044 (while (and (re-search-backward non-word-chars nil 'move)
2045 ;(memq (char-after (point)) shell-file-name-quote-list)
2046 (eq (preceding-char) ?\\))
2047 (backward-char 1))
2048 ;; Don't go forward over a word-char (this can happen if we're at bob).
2049 (if (or (not (bobp)) (looking-at non-word-chars))
2050 (forward-char 1))
2051 ;; Set match-data to match the entire string.
2052 (if (< (point) here)
2053 (progn (store-match-data (list (point) here))
2054 (match-string 0))))))
2055
2056
2057 (defun comint-match-partial-filename ()
2058 "Return the filename at point, or nil if non is found.
2059 Environment variables are substituted. See `comint-word'."
2060 (let ((filename (comint-word "~/A-Za-z0-9+@:_.$#%,={}-")))
2061 (and filename (substitute-in-file-name (comint-unquote-filename filename)))))
2062
2063
2064 (defun comint-quote-filename (filename)
2065 "Return FILENAME with magic characters quoted.
2066 Magic characters are those in `comint-file-name-quote-list'."
2067 (if (null comint-file-name-quote-list)
2068 filename
2069 (let ((regexp
2070 (format "\\(^\\|[^\\]\\)\\([%s]\\)"
2071 (mapconcat 'char-to-string comint-file-name-quote-list ""))))
2072 (save-match-data
2073 (while (string-match regexp filename)
2074 (setq filename (replace-match "\\1\\\\\\2" nil nil filename)))
2075 filename))))
2076
2077 (defun comint-unquote-filename (filename)
2078 "Return FILENAME with quoted characters unquoted."
2079 (if (null comint-file-name-quote-list)
2080 filename
2081 (save-match-data
2082 (while (string-match "\\\\\\(.\\)" filename)
2083 (setq filename (replace-match "\\1" nil nil filename)))
2084 filename)))
2085
2086
2087 ;;;###autoload
2088 (defun comint-dynamic-complete ()
2089 "Dynamically perform completion at point.
2090 Calls the functions in `comint-dynamic-complete-functions' to perform
2091 completion until a function returns non-nil, at which point completion is
2092 assumed to have occurred."
2093 (interactive)
2094 (run-hook-with-args-until-success 'comint-dynamic-complete-functions))
2095
2096
2097 (defun comint-dynamic-complete-filename ()
2098 "Dynamically complete the filename at point.
2099 Completes if after a filename. See `comint-match-partial-filename' and
2100 `comint-dynamic-complete-as-filename'.
2101 This function is similar to `comint-replace-by-expanded-filename', except that
2102 it won't change parts of the filename already entered in the buffer; it just
2103 adds completion characters to the end of the filename. A completions listing
2104 may be shown in a help buffer if completion is ambiguous.
2105
2106 Completion is dependent on the value of `comint-completion-addsuffix',
2107 `comint-completion-recexact' and `comint-completion-fignore', and the timing of
2108 completions listing is dependent on the value of `comint-completion-autolist'.
2109
2110 Returns t if successful."
2111 (interactive)
2112 (if (comint-match-partial-filename)
2113 (prog2 (or (window-minibuffer-p (selected-window))
2114 (message "Completing file name..."))
2115 (comint-dynamic-complete-as-filename))))
2116
2117
2118 (defun comint-dynamic-complete-as-filename ()
2119 "Dynamically complete at point as a filename.
2120 See `comint-dynamic-complete-filename'. Returns t if successful."
2121 (let* ((completion-ignore-case nil)
2122 (completion-ignored-extensions comint-completion-fignore)
2123 (file-name-handler-alist nil)
2124 (minibuffer-p (window-minibuffer-p (selected-window)))
2125 (success t)
2126 (dirsuffix (cond ((not comint-completion-addsuffix) "")
2127 ((not (consp comint-completion-addsuffix)) "/")
2128 (t (car comint-completion-addsuffix))))
2129 (filesuffix (cond ((not comint-completion-addsuffix) "")
2130 ((not (consp comint-completion-addsuffix)) " ")
2131 (t (cdr comint-completion-addsuffix))))
2132 (filename (or (comint-match-partial-filename) ""))
2133 (pathdir (file-name-directory filename))
2134 (pathnondir (file-name-nondirectory filename))
2135 (directory (if pathdir (comint-directory pathdir) default-directory))
2136 (completion (file-name-completion pathnondir directory)))
2137 (cond ((null completion)
2138 (if minibuffer-p (ding) (message "No completions of %s" filename))
2139 (setq success nil))
2140 ((eq completion t) ; Means already completed "file".
2141 (insert filesuffix)
2142 (or minibuffer-p (message "Sole completion")))
2143 ((string-equal completion "") ; Means completion on "directory/".
2144 (comint-dynamic-list-filename-completions))
2145 (t ; Completion string returned.
2146 (let ((file (concat (file-name-as-directory directory) completion)))
2147 (insert (comint-quote-filename
2148 (substring (directory-file-name completion)
2149 (length pathnondir))))
2150 (cond ((symbolp (file-name-completion completion directory))
2151 ;; We inserted a unique completion.
2152 (insert (if (file-directory-p file) dirsuffix filesuffix))
2153 (or minibuffer-p (message "Completed")))
2154 ((and comint-completion-recexact comint-completion-addsuffix
2155 (string-equal pathnondir completion)
2156 (file-exists-p file))
2157 ;; It's not unique, but user wants shortest match.
2158 (insert (if (file-directory-p file) dirsuffix filesuffix))
2159 (or minibuffer-p (message "Completed shortest")))
2160 ((or comint-completion-autolist
2161 (string-equal pathnondir completion))
2162 ;; It's not unique, list possible completions.
2163 (comint-dynamic-list-filename-completions))
2164 (t
2165 (or minibuffer-p (message "Partially completed")))))))
2166 success))
2167
2168
2169 (defun comint-replace-by-expanded-filename ()
2170 "Dynamically expand and complete the filename at point.
2171 Replace the filename with an expanded, canonicalised and completed replacement.
2172 \"Expanded\" means environment variables (e.g., $HOME) and `~'s are replaced
2173 with the corresponding directories. \"Canonicalised\" means `..' and `.' are
2174 removed, and the filename is made absolute instead of relative. For expansion
2175 see `expand-file-name' and `substitute-in-file-name'. For completion see
2176 `comint-dynamic-complete-filename'."
2177 (interactive)
2178 (replace-match (expand-file-name (comint-match-partial-filename)) t t)
2179 (comint-dynamic-complete-filename))
2180
2181
2182 (defun comint-dynamic-simple-complete (stub candidates)
2183 "Dynamically complete STUB from CANDIDATES list.
2184 This function inserts completion characters at point by completing STUB from
2185 the strings in CANDIDATES. A completions listing may be shown in a help buffer
2186 if completion is ambiguous.
2187
2188 Returns nil if no completion was inserted.
2189 Returns `sole' if completed with the only completion match.
2190 Returns `shortest' if completed with the shortest of the completion matches.
2191 Returns `partial' if completed as far as possible with the completion matches.
2192 Returns `listed' if a completion listing was shown.
2193
2194 See also `comint-dynamic-complete-filename'."
2195 (let* ((completion-ignore-case nil)
2196 (suffix (cond ((not comint-completion-addsuffix) "")
2197 ((not (consp comint-completion-addsuffix)) " ")
2198 (t (cdr comint-completion-addsuffix))))
2199 (candidates (mapcar (function (lambda (x) (list x))) candidates))
2200 (completions (all-completions stub candidates)))
2201 (cond ((null completions)
2202 (message "No completions of %s" stub)
2203 nil)
2204 ((= 1 (length completions)) ; Gotcha!
2205 (let ((completion (car completions)))
2206 (if (string-equal completion stub)
2207 (message "Sole completion")
2208 (insert (substring completion (length stub)))
2209 (message "Completed"))
2210 (insert suffix)
2211 'sole))
2212 (t ; There's no unique completion.
2213 (let ((completion (try-completion stub candidates)))
2214 ;; Insert the longest substring.
2215 (insert (substring completion (length stub)))
2216 (cond ((and comint-completion-recexact comint-completion-addsuffix
2217 (string-equal stub completion)
2218 (member completion completions))
2219 ;; It's not unique, but user wants shortest match.
2220 (insert suffix)
2221 (message "Completed shortest")
2222 'shortest)
2223 ((or comint-completion-autolist
2224 (string-equal stub completion))
2225 ;; It's not unique, list possible completions.
2226 (comint-dynamic-list-completions completions)
2227 'listed)
2228 (t
2229 (message "Partially completed")
2230 'partial)))))))
2231
2232
2233 (defun comint-dynamic-list-filename-completions ()
2234 "List in help buffer possible completions of the filename at point."
2235 (interactive)
2236 (let* ((completion-ignore-case nil)
2237 (file-name-handler-alist nil)
2238 (filename (or (comint-match-partial-filename) ""))
2239 (pathdir (file-name-directory filename))
2240 (pathnondir (file-name-nondirectory filename))
2241 (directory (if pathdir (comint-directory pathdir) default-directory))
2242 (completions (file-name-all-completions pathnondir directory)))
2243 (if (not completions)
2244 (message "No completions of %s" filename)
2245 (comint-dynamic-list-completions
2246 (mapcar 'comint-quote-filename completions)))))
2247
2248
2249 ;;;###autoload
2250 (defun comint-dynamic-list-completions (completions)
2251 "List in help buffer sorted COMPLETIONS.
2252 Typing SPC flushes the help buffer."
2253 (let ((conf (current-window-configuration)))
2254 (with-output-to-temp-buffer "*Completions*"
2255 (display-completion-list (sort completions 'string-lessp)))
2256 ;; XEmacs - centralize this
2257 (comint-restore-window-config conf)))
2258
2259 ;; #### - FSFmacs doesn't have this and I'm not gonna nuke it just yet, but
2260 ;; it seems awfully redundant to have this here when compile.el does pretty
2261 ;; much the same thing. --Stig
2262
2263 ;;; Filename and source location extraction from a buffer.
2264 ;;; lemacs change by John Rose
2265 ;;; ===========================================================================
2266 ;;; Functions for recognizing and extracting file names and line numbers.
2267 ;;; C-c C-f attempts to extract a location from the current line, and
2268 ;;; go to that location.
2269
2270 ;;; One command:
2271 ;;; comint-find-source-code Extract source location and follow it.
2272
2273 ;;; This should be installed globally, since file names and source locations
2274 ;;; are ubiquitous. However, don't overwrite an existing key binding.
2275 (if (not (lookup-key global-map "\C-c\C-f"))
2276 (global-set-key "\C-c\C-f" 'comint-find-source-code))
2277
2278 ;;; Utility functions:
2279 ;;; comint-extract-source-location Parse source loc. from buffer or string.
2280 ;;; comint-extract-current-pathname Extract potential pathname around point.
2281 ;;; comint-match-partial-pathname Match a potential pathname before point.
2282
2283 (defconst comint-source-location-patterns
2284 '(;; grep (and cpp): file.c: 10:
2285 ("\\(^\\|[ \t]\\)\\([^ \t\n]+\\): *\\([0-9]+\\):[ \t]*\\(.*\\)" (grep cpp) (2 3 4))
2286 ;; cpp: #line 10 "file.c"
2287 ("#\\(line\\)? *\\([0-9]+\\) *\"\\([^\"\n]+\\)\"" cpp (3 2))
2288 ;; cc: "file.c", line 10
2289 ("\"\\([^\"\n]+\\)\", line +\\([0-9]+\\)\\(:[ \t]+\\(.*\\)\\)?" cc (1 2 4))
2290 ;; f77: line 10 of file.c
2291 ("line +\\([0-9]+\\) +of +\\([^ \t\n]+\\)\\(:[ \t]+\\(.*\\)\\)?" f77 (2 1 4))
2292 ;; perl: ...at file.c line 10.
2293 ;; perl: ...at file.c line 10, near "foo"
2294 ("^\\(.*\\) at \\([^ \t\n]+\\) line +\\([0-9]+\\)\\(\\.$\\|, \\)"
2295 perl (2 3 1))
2296 ;; dbx: line 10 in "file.c"
2297 ("\\(^\\(.*\\)[ \t]+at \\)?line +\\([0-9]+\\) +[in of file]+ +\"\\([^\"\n]+\\)\""
2298 dbx (4 3 2))
2299 ;; dbx: "file.c":10
2300 ("\"\\([^\"\n]+\\)\":\\([0-9]+\\)" dbx (1 2))
2301 ;; centerline: "file.c:10"
2302 ("\"\\([^\"\n]+\\):\\([0-9]+\\)\"" centerline (1 2))
2303 ;; lint: : file.c(10)
2304 (": *\\([^ \t\n)]+\\) *(\\([0-9]+\\))" lint (1 2))
2305 ;; lint: file.c(10) :
2306 ("\\(^\\|[ \t]\\)\\([^ \t\n)]+\\) *(\\([0-9]+\\)) *:" lint (2 3))
2307 ;; lint: ( file.c(10) )
2308 ("( +\\([^ \t\n)]+\\) *(\\([0-9]+\\)) +)" lint (1 2))
2309 ;; troff: `file.c', line 10
2310 ("[\"`']\\([^\"`'\n]+\\)[\"`'], line +\\([0-9]+\\)" troff (1 2))
2311 ;; ri: "file.c" 10:
2312 ("\"\\([^\"\n]+\\)\" *\\([0-9]+\\):" ri (1 2)) ;;Never heard of ri.
2313 ;; mod: File file.c, line 10
2314 ("[Ff]ile +\\([^ \t\n]+\\), line +\\([0-9]+\\)" mod (1 2))
2315 ;; ksh: file.c[10] :
2316 ("\\(^\\|[ \t]\\)\\([^ \t\n)]+\\) *\\[\\([0-9]+\\)\\] *:[ \t]+\\(.*\\)"
2317 ksh (2 3 4))
2318 ;; shell: file.c: syntax error at line 10
2319 ("\\(^\\|[ \t]\\)\\([^ \t\n:]+\\):[ \t]+\\(.*\\)[ \t]+[, at]*line +\\([0-9]+\\)"
2320 sh (2 4 3) -1)
2321 )
2322 "Series of regexps matching file number locations.
2323 Each list entry is a 3-list of a regexp, a program name, and up to 3 numbers.
2324 The numbers name regexp fields which will hold the file, line number,
2325 and associated diagnostic message (if any).
2326 The program name is a symbol or list of symbols, and
2327 is returned unexamined from `comint-extract-source-location';
2328 it should be a guess at who produced the message, e.g., 'cc'.
2329
2330 In the case of multiple matches, `comint-extract-source-location'
2331 will return the leftmost, longest match of the highest priority.
2332 The priority of most patterns is 0, but a fourth element on
2333 the list, if present, specifies a different priority.
2334
2335 The regexps initially stored here are based on the one in compile.el
2336 \(although the pattern containing 'of' must also contain 'line').
2337 They are also drawn from the Unix filters 'error' and 'fwarn'.
2338 The patterns are known to recognize errors from the following
2339 Un*x language processors:
2340 cpp, cc, dbx, lex, f77, Centerline C, sh (Bourne), lint, mod
2341 The following language processors do not incorporate file names
2342 in every error message, and so are more difficult to accomodate:
2343 yacc, pc, csh
2344 ")
2345
2346 (defun comint-extract-source-location (&optional start end commands markers)
2347 "Return a 6-list of (file line command diagnostic mstart mend),
2348 obtained by parsing the current buffer between START and END,
2349 which default to the bounds of the current line.
2350
2351 Use the list comint-source-location-patterns to guide parsing.
2352
2353 The match returned will be on the latest line containing a match, but
2354 will be the earliest possible match on that line.
2355
2356 START can also be a string, in which case it inserted in the buffer
2357 \"*Extract File and Line*\" and parsed there.
2358
2359 COMMANDS is an optional list of pattern types, which has the effect of
2360 temporarily reducing the list comint-source-location-patterns
2361 to only those entries which apply to the given commands.
2362
2363 Return NIL if there is no recognizable source location.
2364
2365 MSTART and MEND give the limits of the matched source location.
2366
2367 If MARKERS is true, return no strings, but rather cons cells
2368 of the form (beg-marker . end-marker).
2369 "
2370 (if (not start)
2371 (progn
2372 (setq start (save-excursion (beginning-of-line) (point)))
2373 (setq end (save-excursion (end-of-line) (point)))))
2374 (if (stringp start)
2375 (save-excursion
2376 (set-buffer (get-buffer-create "*Extract File and Line*"))
2377 (erase-buffer)
2378 (insert start)
2379 (comint-extract-source-location (point-min) (point-max) commands markers))
2380 (let ((ptr (if (and (consp commands)
2381 (consp (car commands)))
2382 (prog1 commands (setq commands nil))
2383 comint-source-location-patterns))
2384 pat
2385 (found-bol (- (point-min) 1))
2386 (found-prio -999999)
2387 found-beg
2388 found-end
2389 found-pat
2390 found-data
2391 set-found-data)
2392 (setq set-found-data
2393 (function (lambda (data)
2394 (while found-data
2395 (let ((m (car found-data)))
2396 (if (markerp m) (set-marker m nil)))
2397 (setq found-data (cdr found-data)))
2398 (setq found-data data))))
2399 (if (and commands (not (listp commands)))
2400 (setq commands (list commands)))
2401 (save-excursion
2402 (save-restriction
2403 (narrow-to-region start end)
2404 (while ptr
2405 (setq pat (car ptr) ptr (cdr ptr))
2406 (goto-char (point-max))
2407 (if (and (or (null commands)
2408 (if (consp (nth 1 pat))
2409 (member (nth 1 pat) commands)
2410 ;; If (cadr pat) is a list, each list element
2411 ;; is a command that might produce this.
2412 (let ((ptr (nth 1 pat))
2413 (ismem nil))
2414 (while (and ptr (not ismem))
2415 (if (member (car ptr) commands)
2416 (setq ismem t))
2417 (setq ptr (cdr ptr)))
2418 ismem)))
2419 (re-search-backward (nth 0 pat) found-bol t))
2420 (let (beg end bol prio)
2421 (setq beg (match-beginning 0))
2422 (setq end (match-end 0))
2423 (beginning-of-line)
2424 (setq bol (point))
2425 (re-search-forward (nth 0 pat))
2426 (if (> (match-beginning 0) beg)
2427 (error "comint-extract-source-location botch"))
2428 (setq beg (match-beginning 0))
2429 (setq end (match-end 0))
2430 (setq prio (or (nth 3 pat) 0))
2431 (if (or (> bol found-bol)
2432 (and (= bol found-bol)
2433 (or (> prio found-prio)
2434 (and (= prio found-prio)
2435 (or (< beg found-beg)
2436 (and (= beg found-beg)
2437 (> end found-end)))))))
2438 (progn
2439 (setq found-bol bol)
2440 (setq found-prio prio)
2441 (setq found-beg beg)
2442 (setq found-end end)
2443 (setq found-pat pat)
2444 (funcall set-found-data (match-data)))))))))
2445 (and found-data
2446 (let* ((command (nth 1 found-pat))
2447 (fields (nth 2 found-pat))
2448 (f1 (nth 0 fields))
2449 (f2 (nth 1 fields))
2450 (f3 (nth 2 fields))
2451 (get-field
2452 (function
2453 (lambda (fn)
2454 (and fn
2455 (let ((beg (match-beginning fn))
2456 (end (match-end fn)))
2457 (and beg end (> end beg)
2458 (if markers
2459 (cons (copy-marker beg) (copy-marker end))
2460 (buffer-substring beg end)))))))))
2461 (store-match-data found-data)
2462 (funcall set-found-data nil)
2463 (let ((file (funcall get-field f1))
2464 (line (funcall get-field f2))
2465 (diagnostic (funcall get-field f3))
2466 (mstart (match-beginning 0))
2467 (mend (match-end 0)))
2468 ;; (carefully use all match-data before calling string-match)
2469 (list
2470 file
2471 (if (and (stringp line)
2472 (prog1
2473 (string-match "\\`[0-9]+\\'" line)
2474 (store-match-data found-data)))
2475 (string-to-int line)
2476 line)
2477 command
2478 diagnostic
2479 mstart
2480 mend
2481 ))))
2482 )))
2483
2484 ;;; Commands for extracting source locations:
2485
2486 (defvar comint-find-source-code-max-lines 100
2487 "*Maximum number of lines to search backward for a source location,
2488 when using \\[comint-find-source-code\\] with an interactive prefix.")
2489
2490 (defvar comint-find-source-file-hook nil
2491 "*Function to call instead of comint-default-find-source-file
2492 when comint-find-source-code parses out a file name and then wants to
2493 visit its buffer. The sole argument is the file name. The function
2494 must find the file, setting the current buffer, and return the file
2495 name. It may also adjust the file name. If you change this variable,
2496 make it buffer local.")
2497
2498 (defvar comint-goto-source-line-hook nil
2499 "*Function to call instead of comint-default-goto-source-line
2500 after comint-find-source-code finds a file and then wants to
2501 go to a line number mentioned in a source location.
2502 The sole argument is the line number. The function must
2503 return the line number, possibly adjusted. If you change
2504 this variable, make it buffer local.")
2505
2506 (defun comint-find-source-code (multi-line)
2507 "Search backward from point for a source location.
2508 If a source location is found in the current line,
2509 go to that location.
2510
2511 If MULTI-LINE is false (this is the interactive prefix flag),
2512 then only look for source locations in the current line.
2513 Otherwise, look within comint-find-source-code-max-lines
2514 before point. If a source location is found on a previous line, move
2515 point to that location, so that another use of \\[comint-find-source-code\\]
2516 will go to the indicated place.
2517
2518 If no source location is found, then try to extract a filename
2519 around the point, using comint-extract-current-pathname.
2520
2521 In any case, if the file does not exist, prompt the user for
2522 a pathname that does. Sometimes the file's directory needs
2523 hand adjustment.
2524
2525 This command uses comint-extract-source-location, which is customizable.
2526 Also, once a source file and line have been extracted, it uses
2527 comint-find-source-file-hook and comint-goto-source-line-hook
2528 to interpret them."
2529 (interactive "P")
2530 (let* ((beg (save-excursion
2531 (if multi-line
2532 (forward-line (min 0 (- comint-find-source-code-max-lines)))
2533 (beginning-of-line))
2534 (point)))
2535 (end (save-excursion (end-of-line) (point)))
2536 (res (or (comint-extract-source-location beg end)
2537 ;; #### comint-extract-current-pathname doesn't exist
2538 (let ((file (comint-extract-current-pathname)))
2539 (and file
2540 (list file nil nil nil
2541 (match-beginning 0)
2542 (match-end 0))))
2543 (error "Not sitting on a source location."))))
2544 (let ((file (nth 0 res))
2545 (line (nth 1 res))
2546 ;;(cmd (nth 2 res))
2547 (info (nth 3 res))
2548 (mbeg (nth 4 res))
2549 (mend (nth 5 res))
2550 dofind)
2551 (setq dofind
2552 (not (and multi-line
2553 mend
2554 (< mend (save-excursion (beginning-of-line) (point))))))
2555 (if (not dofind)
2556 (goto-char mbeg)
2557 (progn
2558 (setq file
2559 (funcall (or comint-find-source-file-hook
2560 'comint-default-find-source-file)
2561 file))
2562 (if line
2563 (setq line
2564 (funcall (or comint-goto-source-line-hook
2565 'comint-default-goto-source-line)
2566 line)))
2567 ))
2568 (message "%s%s of %s%s%s"
2569 (if dofind
2570 "" (substitute-command-keys
2571 "Hit \\[comint-find-source-code] for "))
2572 (cond ((null line) "current line")
2573 ((numberp line) (format "line %s" line))
2574 (t line))
2575 (file-name-nondirectory file)
2576 (if info ": " "") (or info "")))))
2577
2578
2579 (defun comint-default-find-source-file (file)
2580 "Action taken by \\[comint-find-source-code] when find-source-file-hook is nil.
2581 It calls substitute-in-file-name. If the file does not exist, it prompts
2582 for the right pathname, using a similar pathname derived from a nearby
2583 buffer as a default. It then calls find-file-other-window and returns the
2584 amended file name."
2585 (setq file (substitute-in-file-name file))
2586 (if (not (file-readable-p file))
2587 (setq file (comint-fixup-source-file-name file)))
2588 (find-file-other-window file)
2589 file)
2590
2591 (defun comint-fixup-source-file-name (file)
2592 (let (dir ptr nondir bfile res)
2593 (setq nondir (file-name-nondirectory file))
2594 (setq ptr (buffer-list))
2595 (while (and ptr (not dir))
2596 (setq bfile (buffer-file-name (car ptr)))
2597 (if (and bfile (equal (file-name-nondirectory bfile) nondir))
2598 (setq dir (file-name-directory bfile)
2599 file (file-name-nondirectory bfile)))
2600 (setq ptr (cdr ptr)))
2601 (setq res
2602 (read-file-name "Source file: " dir t nil file))
2603 (if (eq res t)
2604 (expand-file-name file dir)
2605 res)))
2606
2607 (defun comint-default-goto-source-line (line)
2608 "Action taken by \\[comint-find-source-code] when goto-source-line-hook is nil.
2609 It widens & pushes the mark, then does goto-line in the current buffer.
2610 It returns its line argument."
2611 (widen)
2612 (setq line (max line 0))
2613 (setq line (min line (+ 1 (count-lines (point-min) (point-max)))))
2614 (push-mark)
2615 (goto-line line)
2616 line)
2617
2618 ;;; Converting process modes to use comint mode
2619 ;;; ===========================================================================
2620 ;;; The code in the Emacs 19 distribution has all been modified to use comint
2621 ;;; where needed. However, there are `third-party' packages out there that
2622 ;;; still use the old shell mode. Here's a guide to conversion.
2623 ;;;
2624 ;;; Renaming variables
2625 ;;; Most of the work is renaming variables and functions. These are the common
2626 ;;; ones:
2627 ;;; Local variables:
2628 ;;; last-input-start comint-last-input-start
2629 ;;; last-input-end comint-last-input-end
2630 ;;; shell-prompt-pattern comint-prompt-regexp
2631 ;;; shell-set-directory-error-hook <no equivalent>
2632 ;;; Miscellaneous:
2633 ;;; shell-set-directory <unnecessary>
2634 ;;; shell-mode-map comint-mode-map
2635 ;;; Commands:
2636 ;;; shell-send-input comint-send-input
2637 ;;; shell-send-eof comint-delchar-or-maybe-eof
2638 ;;; kill-shell-input comint-kill-input
2639 ;;; interrupt-shell-subjob comint-interrupt-subjob
2640 ;;; stop-shell-subjob comint-stop-subjob
2641 ;;; quit-shell-subjob comint-quit-subjob
2642 ;;; kill-shell-subjob comint-kill-subjob
2643 ;;; kill-output-from-shell comint-kill-output
2644 ;;; show-output-from-shell comint-show-output
2645 ;;; copy-last-shell-input Use comint-previous-input/comint-next-input
2646 ;;;
2647 ;;; SHELL-SET-DIRECTORY is gone, its functionality taken over by
2648 ;;; SHELL-DIRECTORY-TRACKER, the shell mode's comint-input-filter-functions.
2649 ;;; Comint mode does not provide functionality equivalent to
2650 ;;; shell-set-directory-error-hook; it is gone.
2651 ;;;
2652 ;;; comint-last-input-start is provided for modes which want to munge
2653 ;;; the buffer after input is sent, perhaps because the inferior
2654 ;;; insists on echoing the input. The LAST-INPUT-START variable in
2655 ;;; the old shell package was used to implement a history mechanism,
2656 ;;; but you should think twice before using comint-last-input-start
2657 ;;; for this; the input history ring often does the job better.
2658 ;;;
2659 ;;; If you are implementing some process-in-a-buffer mode, called foo-mode, do
2660 ;;; *not* create the comint-mode local variables in your foo-mode function.
2661 ;;; This is not modular. Instead, call comint-mode, and let *it* create the
2662 ;;; necessary comint-specific local variables. Then create the
2663 ;;; foo-mode-specific local variables in foo-mode. Set the buffer's keymap to
2664 ;;; be foo-mode-map, and its mode to be foo-mode. Set the comint-mode hooks
2665 ;;; (comint-{prompt-regexp, input-filter, input-filter-functions,
2666 ;;; get-old-input) that need to be different from the defaults. Call
2667 ;;; foo-mode-hook, and you're done. Don't run the comint-mode hook yourself;
2668 ;;; comint-mode will take care of it. The following example, from shell.el,
2669 ;;; is typical:
2670 ;;;
2671 ;;; (defvar shell-mode-map '())
2672 ;;; (cond ((not shell-mode-map)
2673 ;;; (setq shell-mode-map (copy-keymap comint-mode-map))
2674 ;;; (define-key shell-mode-map "\C-c\C-f" 'shell-forward-command)
2675 ;;; (define-key shell-mode-map "\C-c\C-b" 'shell-backward-command)
2676 ;;; (define-key shell-mode-map "\t" 'comint-dynamic-complete)
2677 ;;; (define-key shell-mode-map "\M-?"
2678 ;;; 'comint-dynamic-list-filename-completions)))
2679 ;;;
2680 ;;; (defun shell-mode ()
2681 ;;; (interactive)
2682 ;;; (comint-mode)
2683 ;;; (setq comint-prompt-regexp shell-prompt-pattern)
2684 ;;; (setq major-mode 'shell-mode)
2685 ;;; (setq mode-name "Shell")
2686 ;;; (use-local-map shell-mode-map)
2687 ;;; (make-local-variable 'shell-directory-stack)
2688 ;;; (setq shell-directory-stack nil)
2689 ;;; (add-hook 'comint-input-filter-functions 'shell-directory-tracker)
2690 ;;; (run-hooks 'shell-mode-hook))
2691 ;;;
2692 ;;;
2693 ;;; Note that make-comint is different from make-shell in that it
2694 ;;; doesn't have a default program argument. If you give make-shell
2695 ;;; a program name of NIL, it cleverly chooses one of explicit-shell-name,
2696 ;;; $ESHELL, $SHELL, or /bin/sh. If you give make-comint a program argument
2697 ;;; of NIL, it barfs. Adjust your code accordingly...
2698 ;;;
2699 ;;; Completion for comint-mode users
2700 ;;;
2701 ;;; For modes that use comint-mode, comint-dynamic-complete-functions is the
2702 ;;; hook to add completion functions to. Functions on this list should return
2703 ;;; non-nil if completion occurs (i.e., further completion should not occur).
2704 ;;; You could use comint-dynamic-simple-complete to do the bulk of the
2705 ;;; completion job.
2706
2707
2708 ;;; Do the user's customisation...
2709
2710 (defvar comint-load-hook nil
2711 "This hook is run when comint is loaded in.
2712 This is a good place to put keybindings.")
2713
2714 (run-hooks 'comint-load-hook)
2715
2716
2717 (provide 'comint)
2718
2719 ;;; comint.el ends here