comint.el 155 KB
Newer Older
Eric S. Raymond's avatar
Eric S. Raymond committed
1
;;; comint.el --- general command interpreter in a window stuff
2

3
;; Copyright (C) 1988, 1990, 1992-2011  Free Software Foundation, Inc.
Eric S. Raymond's avatar
Eric S. Raymond committed
4

5
;; Author: Olin Shivers <shivers@cs.cmu.edu>
Karl Heuer's avatar
Karl Heuer committed
6
;;	Simon Marshall <simon@gnu.org>
Simon Marshall's avatar
Simon Marshall committed
7
;; Maintainer: FSF
Eric S. Raymond's avatar
Eric S. Raymond committed
8
;; Keywords: processes
9
;; Package: emacs
Eric S. Raymond's avatar
Eric S. Raymond committed
10

11
;; This file is part of GNU Emacs.
David Lawrence's avatar
David Lawrence committed
12

13
;; GNU Emacs is free software: you can redistribute it and/or modify
14
;; it under the terms of the GNU General Public License as published by
15 16
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
David Lawrence's avatar
David Lawrence committed
17

18 19 20 21
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
David Lawrence's avatar
David Lawrence committed
22

23
;; You should have received a copy of the GNU General Public License
24
;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
David Lawrence's avatar
David Lawrence committed
25

Eric S. Raymond's avatar
Eric S. Raymond committed
26 27
;;; Commentary:

Erik Naggum's avatar
Erik Naggum committed
28
;; This file defines a general command-interpreter-in-a-buffer package
Stefan Monnier's avatar
Stefan Monnier committed
29 30
;; (comint mode).  The idea is that you can build specific process-in-a-buffer
;; modes on top of comint mode -- e.g., Lisp, shell, scheme, T, soar, ....
Miles Bader's avatar
Miles Bader committed
31
;; This way, all these specific packages share a common base functionality,
Erik Naggum's avatar
Erik Naggum committed
32 33 34 35 36 37 38 39 40
;; and a common set of bindings, which makes them easier to use (and
;; saves code, implementation time, etc., etc.).

;; Several packages are already defined using comint mode:
;; - shell.el defines a shell-in-a-buffer mode.
;; - cmulisp.el defines a simple lisp-in-a-buffer mode.
;;
;; - The file cmuscheme.el defines a scheme-in-a-buffer mode.
;; - The file tea.el tunes scheme and inferior-scheme modes for T.
Stefan Monnier's avatar
Stefan Monnier committed
41 42 43 44
;; - The file soar.el tunes Lisp and inferior-lisp modes for Soar.
;; - cmutex.el defines TeX and LaTeX modes that invoke TeX, LaTeX, BibTeX,
;;   previewers, and printers from within Emacs.
;; - background.el allows csh-like job control inside Emacs.
Erik Naggum's avatar
Erik Naggum committed
45 46
;; It is pretty easy to make new derived modes for other processes.

Stefan Monnier's avatar
Stefan Monnier committed
47
;; For documentation on the functionality provided by Comint mode, and
Erik Naggum's avatar
Erik Naggum committed
48
;; the hooks available for customising it, see the comments below.
Miles Bader's avatar
Miles Bader committed
49
;; For further information on the standard derived modes (shell,
Erik Naggum's avatar
Erik Naggum committed
50 51 52 53 54
;; inferior-lisp, inferior-scheme, ...), see the relevant source files.

;; For hints on converting existing process modes (e.g., tex-mode,
;; background, dbx, gdb, kermit, prolog, telnet) to use comint-mode
;; instead of shell-mode, see the notes at the end of this file.
David Lawrence's avatar
David Lawrence committed
55 56


Erik Naggum's avatar
Erik Naggum committed
57 58 59 60 61
;; Brief Command Documentation:
;;============================================================================
;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp
;; mode)
;;
Stefan Monnier's avatar
Stefan Monnier committed
62 63
;; M-p	   comint-previous-input	   Cycle backwards in input history
;; M-n	   comint-next-input		   Cycle forwards
64
;; M-r     comint-history-isearch-backward-regexp  Isearch input regexp backward
Stefan Monnier's avatar
Stefan Monnier committed
65 66 67 68
;; M-C-l   comint-show-output		   Show last batch of process output
;; RET	   comint-send-input
;; C-d	   comint-delchar-or-maybe-eof     Delete char unless at end of buff
;; C-c C-a comint-bol-or-process-mark      First time, move point to bol;
69
;;					    second time, move to process-mark.
Stefan Monnier's avatar
Stefan Monnier committed
70 71 72 73 74 75 76 77
;; C-c C-u comint-kill-input		    ^u
;; C-c C-w backward-kill-word		    ^w
;; C-c C-c comint-interrupt-subjob	    ^c
;; C-c C-z comint-stop-subjob		    ^z
;; C-c C-\ comint-quit-subjob		    ^\
;; C-c C-o comint-delete-output		    Delete last batch of process output
;; C-c C-r comint-show-output		    Show last batch of process output
;; C-c C-l comint-dynamic-list-input-ring  List input history
Erik Naggum's avatar
Erik Naggum committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91
;;
;; Not bound by default in comint-mode (some are in shell mode)
;; comint-run				Run a program under comint-mode
;; send-invisible			Read a line w/o echo, and send to proc
;; comint-dynamic-complete-filename	Complete filename at point.
;; comint-dynamic-list-filename-completions List completions in help buffer.
;; comint-replace-by-expanded-filename	Expand and complete filename at point;
;;					replace with expanded/completed name.
;; comint-replace-by-expanded-history	Expand history at point;
;;					replace with expanded name.
;; comint-magic-space                  Expand history and add (a) space(s).
;; comint-kill-subjob			No mercy.
;; comint-show-maximum-output          Show as much output as possible.
;; comint-continue-subjob		Send CONT signal to buffer's process
Stefan Monnier's avatar
Stefan Monnier committed
92
;;					group.  Useful if you accidentally
Erik Naggum's avatar
Erik Naggum committed
93
;;					suspend your process (with C-c C-z).
94 95 96 97 98
;; comint-get-next-from-history        Fetch successive input history lines
;; comint-accumulate		       Combine lines to send them together
;;					as input.
;; comint-goto-process-mark	       Move point to where process-mark is.
;; comint-set-process-mark	       Set process-mark to point.
Erik Naggum's avatar
Erik Naggum committed
99

Stefan Monnier's avatar
Stefan Monnier committed
100
;; comint-mode-hook is the Comint mode hook.  Basically for your keybindings.
David Lawrence's avatar
David Lawrence committed
101

Eric S. Raymond's avatar
Eric S. Raymond committed
102 103
;;; Code:

Richard M. Stallman's avatar
Richard M. Stallman committed
104
(require 'ring)
David Lawrence's avatar
David Lawrence committed
105

Erik Naggum's avatar
Erik Naggum committed
106 107 108
;; Buffer Local Variables:
;;============================================================================
;; Comint mode buffer local variables:
Miles Bader's avatar
Miles Bader committed
109
;;  comint-prompt-regexp		string	comint-bol uses to match prompt
110 111
;;  comint-delimiter-argument-list	list	For delimiters and arguments
;;  comint-last-input-start		marker	Handy if inferior always echoes
112
;;  comint-last-input-end		marker	For comint-delete-output command
113 114 115
;;  comint-input-ring-size		integer	For the input history
;;  comint-input-ring			ring	mechanism
;;  comint-input-ring-index		number	...
116
;;  comint-save-input-ring-index	number	...
117 118 119 120
;;  comint-input-autoexpand		symbol	...
;;  comint-input-ignoredups		boolean	...
;;  comint-dynamic-complete-functions	hook   For the completion mechanism
;;  comint-completion-fignore		list	...
121
;;  comint-file-name-chars		string	...
122
;;  comint-file-name-quote-list		list	...
Miles Bader's avatar
Miles Bader committed
123
;;  comint-get-old-input		function Hooks for specific
124 125
;;  comint-input-filter-functions	hook	process-in-a-buffer
;;  comint-output-filter-functions	hook	function modes.
126
;;  comint-preoutput-filter-functions   hook
127 128 129 130 131
;;  comint-input-filter			function ...
;;  comint-input-sender			function ...
;;  comint-eol-on-send			boolean	...
;;  comint-process-echoes		boolean	...
;;  comint-scroll-to-bottom-on-input	symbol	For scroll behavior
Richard M. Stallman's avatar
Richard M. Stallman committed
132
;;  comint-move-point-for-output	symbol	...
Miles Bader's avatar
Miles Bader committed
133
;;  comint-scroll-show-maximum-output	boolean	...
134
;;  comint-accum-marker			maker	  For comint-accumulate
Erik Naggum's avatar
Erik Naggum committed
135 136
;;
;; Comint mode non-buffer local variables:
137 138 139
;;  comint-completion-addsuffix		boolean/cons	For file name
;;  comint-completion-autolist		boolean		completion behavior
;;  comint-completion-recexact		boolean		...
David Lawrence's avatar
David Lawrence committed
140

141 142 143 144 145
(defgroup comint nil
  "General command interpreter in a window stuff."
  :group 'processes)

(defgroup comint-completion nil
146
  "Completion facilities in comint."
147 148 149
  :group 'comint)

(defgroup comint-source nil
150
  "Source finding facilities in comint."
151 152 153
  :prefix "comint-"
  :group 'comint)

Jim Blandy's avatar
Jim Blandy committed
154
(defvar comint-prompt-regexp "^"
155
  "Regexp to recognize prompts in the inferior process.
Jim Blandy's avatar
Jim Blandy committed
156
Defaults to \"^\", the null string at BOL.
David Lawrence's avatar
David Lawrence committed
157

158
This variable is only used if the variable
159
`comint-use-prompt-regexp' is non-nil.
160

David Lawrence's avatar
David Lawrence committed
161
Good choices:
162
  Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
163 164
  Lucid Common Lisp: \"^\\\\(>\\\\|\\\\(->\\\\)+\\\\) *\"
  franz: \"^\\\\(->\\\\|<[0-9]*>:\\\\) *\"
Jim Blandy's avatar
Jim Blandy committed
165
  kcl: \"^>+ *\"
166
  shell: \"^[^#$%>\\n]*[#$%>] *\"
Jim Blandy's avatar
Jim Blandy committed
167
  T: \"^>+ *\"
David Lawrence's avatar
David Lawrence committed
168

Jim Blandy's avatar
Jim Blandy committed
169
This is a good thing to set in mode hooks.")
David Lawrence's avatar
David Lawrence committed
170

171 172
(defcustom comint-prompt-read-only nil
  "If non-nil, the comint prompt is read only.
173
The read only region includes the newline before the prompt.
174
This does not affect existing prompts.
175 176 177 178 179 180 181 182 183 184
Certain derived modes may override this option.

If you set this option to t, then the safe way to temporarily
override the read-only-ness of comint prompts is to call
`comint-kill-whole-line' or `comint-kill-region' with no
narrowing in effect.  This way you will be certain that none of
the remaining prompts will be accidentally messed up.  You may
wish to put something like the following in your `.emacs' file:

\(add-hook 'comint-mode-hook
185
	  (lambda ()
186
	    (define-key comint-mode-map \"\\C-w\" 'comint-kill-region)
187 188
	    (define-key comint-mode-map [C-S-backspace]
	      'comint-kill-whole-line)))
189

190
If you sometimes use comint-mode on text-only terminals or with `emacs -nw',
191
you might wish to use another binding for `comint-kill-whole-line'."
192 193
  :type 'boolean
  :group 'comint
194
  :version "22.1")
195

196
(defvar comint-delimiter-argument-list ()
197
  "List of characters to recognize as separate arguments in input.
198 199 200
Strings comprising a character in this list will separate the arguments
surrounding them, and also be regarded as arguments in their own right (unlike
whitespace).  See `comint-arguments'.
201
Defaults to the empty list.
202

203
For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?;).
204 205 206

This is a good thing to set in mode hooks.")

207
(defcustom comint-input-autoexpand nil
Lute Kamstra's avatar
Lute Kamstra committed
208
  "If non-nil, expand input command history references on completion.
Stefan Monnier's avatar
Stefan Monnier committed
209
This mirrors the optional behavior of tcsh (its autoexpand and histlist).
210 211 212 213 214 215

If the value is `input', then the expansion is seen on input.
If the value is `history', then the expansion is only when inserting
into the buffer's input ring.  See also `comint-magic-space' and
`comint-dynamic-complete'.

216 217 218
This variable is buffer-local."
  :type '(choice (const :tag "off" nil)
		 (const input)
219 220
		 (const history)
		 (other :tag "on" t))
221 222
  :group 'comint)

223
(defface comint-highlight-input '((t (:weight bold)))
224
  "Face to use to highlight user input."
225 226
  :group 'comint)

227
(defface comint-highlight-prompt
228
  '((t :inherit minibuffer-prompt))
229
  "Face to use to highlight prompts."
230 231
  :group 'comint)

232
(defcustom comint-input-ignoredups nil
Lute Kamstra's avatar
Lute Kamstra committed
233
  "If non-nil, don't add input matching the last on the input ring.
234
This mirrors the optional behavior of bash.
235

236 237 238
This variable is buffer-local."
  :type 'boolean
  :group 'comint)
239

240
(defcustom comint-input-ring-file-name nil
Lute Kamstra's avatar
Lute Kamstra committed
241
  "If non-nil, name of the file to read/write input history.
242
See also `comint-read-input-ring' and `comint-write-input-ring'.
243 244
`comint-mode' makes this a buffer-local variable.  You probably want
to set this in a mode hook, rather than customize the default value."
245 246
  :type '(choice (const :tag "nil" nil)
		 file)
247
  :group 'comint)
248

249
(defcustom comint-scroll-to-bottom-on-input nil
Lute Kamstra's avatar
Lute Kamstra committed
250
  "Controls whether input to interpreter causes window to scroll.
251 252 253
If nil, then do not scroll.  If t or `all', scroll all windows showing buffer.
If `this', scroll only the selected window.

254
The default is nil.
255

256 257 258 259 260 261
See `comint-preinput-scroll-to-bottom'.  This variable is buffer-local."
  :type '(choice (const :tag "off" nil)
		 (const t)
		 (const all)
		 (const this))
  :group 'comint)
262

263
(defcustom comint-move-point-for-output nil
Lute Kamstra's avatar
Lute Kamstra committed
264
  "Controls whether interpreter output moves point to the end of the output.
265 266 267 268 269
If nil, then output never moves point to the output.
 (If the output occurs at point, it is inserted before point.)
If t or `all', move point in all windows showing the buffer.
If `this', move point only the selected window.
If `others', move point only in other windows, not in the selected window.
270 271

The default is nil.
272

273 274
See the variable `comint-scroll-show-maximum-output' and the function
`comint-postoutput-scroll-to-bottom'.
Stefan Monnier's avatar
Stefan Monnier committed
275
This variable is buffer-local in all Comint buffers."
276 277 278 279 280 281 282
  :type '(choice (const :tag "off" nil)
		 (const t)
		 (const all)
		 (const this)
		 (const others))
  :group 'comint)

283
(defvaralias 'comint-scroll-to-bottom-on-output 'comint-move-point-for-output)
284

285
(defcustom comint-scroll-show-maximum-output t
Lute Kamstra's avatar
Lute Kamstra committed
286
  "Controls how to scroll due to interpreter output.
287
This variable applies when point is at the end of the buffer
288
\(either because it was originally there, or because
289 290 291 292 293
`comint-move-point-for-output' said to move it there)
and output from the subprocess is inserted.

Non-nil means scroll so that the window is full of text
and point is on the last line.  A value of nil
Stefan Monnier's avatar
Stefan Monnier committed
294
means don't do anything special--scroll normally.
295 296 297

See also the variable `comint-move-point-for-output' and the function
`comint-postoutput-scroll-to-bottom'.
Stefan Monnier's avatar
Stefan Monnier committed
298
This variable is buffer-local in all Comint buffers."
299 300
  :type 'boolean
  :group 'comint)
301

302
(defcustom comint-buffer-maximum-size 1024
Lute Kamstra's avatar
Lute Kamstra committed
303
  "The maximum size in lines for Comint buffers.
304
Comint buffers are truncated from the top to be no greater than this number, if
305 306 307
the function `comint-truncate-buffer' is on `comint-output-filter-functions'."
  :type 'integer
  :group 'comint)
308

309 310 311 312 313
(defcustom comint-input-ring-size 500
  "Size of the input history ring in `comint-mode'."
  :type 'integer
  :group 'comint
  :version "23.2")
David Lawrence's avatar
David Lawrence committed
314

315 316 317
(defvar comint-input-ring-separator "\n"
  "Separator between commands in the history file.")

318
(defvar comint-input-history-ignore "^#"
Stefan Monnier's avatar
Stefan Monnier committed
319
  "Regexp for history entries that should be ignored when Comint initializes.")
320

321
(defcustom comint-process-echoes nil
Lute Kamstra's avatar
Lute Kamstra committed
322
  "If non-nil, assume that the subprocess echoes any input.
Noah Friedman's avatar
Noah Friedman committed
323
If so, delete one copy of the input so that only one copy eventually
324
appears in the buffer.
Noah Friedman's avatar
Noah Friedman committed
325

326 327 328
This variable is buffer-local."
  :type 'boolean
  :group 'comint)
Noah Friedman's avatar
Noah Friedman committed
329

330
;; AIX puts the name of the person being su'd to in front of the prompt.
331
;; kinit prints a prompt like `Password for devnull@GNU.ORG: '.
332 333
;; ksu prints a prompt like `Kerberos password for devnull/root@GNU.ORG: '.
;; ssh-add prints a prompt like `Enter passphrase: '.
334
;; plink prints a prompt like `Passphrase for key "root@GNU.ORG": '.
335
;; Ubuntu's sudo prompts like `[sudo] password for user:'
336
;; Some implementations of passwd use "Password (again)" as the 2nd prompt.
337
;; Something called "perforce" uses "Enter password:".
338
;; See M-x comint-testsuite--test-comint-password-prompt-regexp.
339
(defcustom comint-password-prompt-regexp
340
  (concat
341
   "\\(^ *\\|"
342
   (regexp-opt
343 344 345 346
    '("Enter" "enter" "Enter same" "enter same" "Enter the" "enter the"
      "Old" "old" "New" "new" "'s" "login"
      "Kerberos" "CVS" "UNIX" " SMB" "LDAP" "[sudo]" "Repeat" "Bad") t)
   " +\\)"
347 348 349 350 351
   (regexp-opt
    '("password" "Password" "passphrase" "Passphrase"
      "pass phrase" "Pass phrase"))
   "\\(?:\\(?:, try\\)? *again\\| (empty for no passphrase)\\| (again)\\)?\
\\(?: for [^:]+\\)?:\\s *\\'")
Lute Kamstra's avatar
Lute Kamstra committed
352
  "Regexp matching prompts for passwords in the inferior process.
353
This is used by `comint-watch-for-password-prompt'."
354
  :version "24.1"
355 356
  :type 'regexp
  :group 'comint)
357

Erik Naggum's avatar
Erik Naggum committed
358
;; Here are the per-interpreter hooks.
Jim Blandy's avatar
Jim Blandy committed
359
(defvar comint-get-old-input (function comint-get-old-input-default)
Stefan Monnier's avatar
Stefan Monnier committed
360
  "Function that returns old text in Comint mode.
361 362 363 364 365
This function is called when return is typed while the point is in old
text.  It returns the text to be submitted as process input.  The
default is `comint-get-old-input-default', which either grabs the
current input field or grabs the current line and strips off leading
text matching `comint-prompt-regexp', depending on the value of
366
`comint-use-prompt-regexp'.")
David Lawrence's avatar
David Lawrence committed
367

368 369 370
(defvar comint-dynamic-complete-functions
  '(comint-replace-by-expanded-history comint-dynamic-complete-filename)
  "List of functions called to perform completion.
371
Works like `completion-at-point-functions'.
372
See also `comint-dynamic-complete'.
373 374 375

This is a good thing to set in mode hooks.")

Jim Blandy's avatar
Jim Blandy committed
376 377 378
(defvar comint-input-filter
  (function (lambda (str) (not (string-match "\\`\\s *\\'" str))))
  "Predicate for filtering additions to input history.
379 380 381
Takes one argument, the input.  If non-nil, the input may be saved on the input
history list.  Default is to save anything that isn't all whitespace.")

382
(defvar comint-input-filter-functions '()
383
  "Abnormal hook run before input is sent to the process.
384
These functions get one argument, a string containing the text to send.")
385

386
;;;###autoload
387
(defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom comint-watch-for-password-prompt)
388
  "Functions to call after output is inserted into the buffer.
389
One possible function is `comint-postoutput-scroll-to-bottom'.
390 391 392 393
These functions get one argument, a string containing the text as originally
inserted.  Note that this might not be the same as the buffer contents between
`comint-last-output-start' and the buffer's `process-mark', if other filter
functions have already modified the buffer.
394

395 396
See also `comint-preoutput-filter-functions'.

397 398
You can use `add-hook' to add functions to this list
either globally or locally.")
Jim Blandy's avatar
Jim Blandy committed
399

400 401 402
(defvar comint-input-sender-no-newline nil
  "Non-nil directs the `comint-input-sender' function not to send a newline.")

Jim Blandy's avatar
Jim Blandy committed
403 404
(defvar comint-input-sender (function comint-simple-send)
  "Function to actually send to PROCESS the STRING submitted by user.
Miles Bader's avatar
Miles Bader committed
405
Usually this is just `comint-simple-send', but if your mode needs to
406 407
massage the input string, put a different function here.
`comint-simple-send' just sends the string plus a newline.
408
\(If `comint-input-sender-no-newline' is non-nil, it omits the newline.)
409
This is called from the user command `comint-send-input'.")
Jim Blandy's avatar
Jim Blandy committed
410

411
(defcustom comint-eol-on-send t
Lute Kamstra's avatar
Lute Kamstra committed
412
  "Non-nil means go to the end of the line before sending input.
413 414 415
See `comint-send-input'."
  :type 'boolean
  :group 'comint)
David Lawrence's avatar
David Lawrence committed
416

Glenn Morris's avatar
Glenn Morris committed
417 418 419
(define-obsolete-variable-alias 'comint-use-prompt-regexp-instead-of-fields
  'comint-use-prompt-regexp "22.1")

420 421 422
;; Note: If it is decided to purge comint-prompt-regexp from the source
;; entirely, searching for uses of this variable will help to identify
;; places that need attention.
423
(defcustom comint-use-prompt-regexp nil
Lute Kamstra's avatar
Lute Kamstra committed
424
  "If non-nil, use `comint-prompt-regexp' to recognize prompts.
425
If nil, then program output and user-input are given different `field'
426
properties, which Emacs commands can use to distinguish them (in
427 428
particular, common movement commands such as `beginning-of-line'
respect field boundaries in a natural way)."
429 430 431
  :type 'boolean
  :group 'comint)

432
(defcustom comint-mode-hook nil
Stefan Monnier's avatar
Stefan Monnier committed
433
  "Hook run upon entry to `comint-mode'.
434 435 436
This is run before the process is cranked up."
  :type 'hook
  :group 'comint)
Jim Blandy's avatar
Jim Blandy committed
437

438
(defcustom comint-exec-hook '()
Stefan Monnier's avatar
Stefan Monnier committed
439
  "Hook run each time a process is exec'd by `comint-exec'.
Jim Blandy's avatar
Jim Blandy committed
440
This is called after the process is cranked up.  It is useful for things that
Stefan Monnier's avatar
Stefan Monnier committed
441
must be done each time a process is executed in a Comint mode buffer (e.g.,
442
`(process-kill-without-query)').  In contrast, the `comint-mode-hook' is only
443 444 445
executed once when the buffer is created."
  :type 'hook
  :group 'comint)
Jim Blandy's avatar
Jim Blandy committed
446

447 448 449 450 451 452 453
(defvar comint-mode-map
  (let ((map (make-sparse-keymap)))
    ;; Keys:
    (define-key map "\ep" 	  'comint-previous-input)
    (define-key map "\en" 	  'comint-next-input)
    (define-key map [C-up] 	  'comint-previous-input)
    (define-key map [C-down] 	  'comint-next-input)
454
    (define-key map "\er" 	  'comint-history-isearch-backward-regexp)
455 456 457 458 459
    (define-key map [?\C-c ?\M-r] 'comint-previous-matching-input-from-input)
    (define-key map [?\C-c ?\M-s] 'comint-next-matching-input-from-input)
    (define-key map "\e\C-l" 	  'comint-show-output)
    (define-key map "\C-m" 	  'comint-send-input)
    (define-key map "\C-d" 	  'comint-delchar-or-maybe-eof)
460 461 462 463
    ;; The following two are standardly aliased to C-d,
    ;; but they should never do EOF, just delete.
    (define-key map [delete] 	  'delete-char)
    (define-key map [kp-delete]	  'delete-char)
464 465 466 467 468 469 470 471
    (define-key map "\C-c " 	  'comint-accumulate)
    (define-key map "\C-c\C-x" 	  'comint-get-next-from-history)
    (define-key map "\C-c\C-a" 	  'comint-bol-or-process-mark)
    (define-key map "\C-c\C-u" 	  'comint-kill-input)
    (define-key map "\C-c\C-w" 	  'backward-kill-word)
    (define-key map "\C-c\C-c" 	  'comint-interrupt-subjob)
    (define-key map "\C-c\C-z" 	  'comint-stop-subjob)
    (define-key map "\C-c\C-\\"   'comint-quit-subjob)
472
    (define-key map "\C-c\C-m" 	  'comint-copy-old-input)
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
    (define-key map "\C-c\C-o" 	  'comint-delete-output)
    (define-key map "\C-c\C-r" 	  'comint-show-output)
    (define-key map "\C-c\C-e" 	  'comint-show-maximum-output)
    (define-key map "\C-c\C-l" 	  'comint-dynamic-list-input-ring)
    (define-key map "\C-c\C-n" 	  'comint-next-prompt)
    (define-key map "\C-c\C-p" 	  'comint-previous-prompt)
    (define-key map "\C-c\C-d" 	  'comint-send-eof)
    (define-key map "\C-c\C-s" 	  'comint-write-output)
    (define-key map "\C-c." 	  'comint-insert-previous-argument)
    ;; Mouse Buttons:
    (define-key map [mouse-2]     'comint-insert-input)
    ;; Menu bars:
    ;; completion:
    (define-key map [menu-bar completion]
      (cons "Complete" (make-sparse-keymap "Complete")))
    (define-key map [menu-bar completion complete-expand]
      '("Expand File Name" . comint-replace-by-expanded-filename))
    (define-key map [menu-bar completion complete-listing]
      '("File Completion Listing" . comint-dynamic-list-filename-completions))
    (define-key map [menu-bar completion complete-file]
      '("Complete File Name" . comint-dynamic-complete-filename))
    (define-key map [menu-bar completion complete]
      '("Complete Before Point" . comint-dynamic-complete))
    ;; Input history:
    (define-key map [menu-bar inout]
      (cons "In/Out" (make-sparse-keymap "In/Out")))
    (define-key map [menu-bar inout delete-output]
      '("Delete Current Output Group" . comint-delete-output))
    (define-key map [menu-bar inout append-output-to-file]
      '("Append Current Output Group to File" . comint-append-output-to-file))
    (define-key map [menu-bar inout write-output]
      '("Write Current Output Group to File" . comint-write-output))
    (define-key map [menu-bar inout next-prompt]
      '("Forward Output Group" . comint-next-prompt))
    (define-key map [menu-bar inout previous-prompt]
      '("Backward Output Group" . comint-previous-prompt))
    (define-key map [menu-bar inout show-maximum-output]
      '("Show Maximum Output" . comint-show-maximum-output))
    (define-key map [menu-bar inout show-output]
      '("Show Current Output Group" . comint-show-output))
    (define-key map [menu-bar inout kill-input]
      '("Kill Current Input" . comint-kill-input))
    (define-key map [menu-bar inout copy-input]
516
      '("Copy Old Input" . comint-copy-old-input))
517 518 519 520
    (define-key map [menu-bar inout history-isearch-backward-regexp]
      '("Isearch Input Regexp Backward..." . comint-history-isearch-backward-regexp))
    (define-key map [menu-bar inout history-isearch-backward]
      '("Isearch Input String Backward..." . comint-history-isearch-backward))
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
    (define-key map [menu-bar inout forward-matching-history]
      '("Forward Matching Input..." . comint-forward-matching-input))
    (define-key map [menu-bar inout backward-matching-history]
      '("Backward Matching Input..." . comint-backward-matching-input))
    (define-key map [menu-bar inout next-matching-history]
      '("Next Matching Input..." . comint-next-matching-input))
    (define-key map [menu-bar inout previous-matching-history]
      '("Previous Matching Input..." . comint-previous-matching-input))
    (define-key map [menu-bar inout next-matching-history-from-input]
      '("Next Matching Current Input" . comint-next-matching-input-from-input))
    (define-key map [menu-bar inout previous-matching-history-from-input]
      '("Previous Matching Current Input" . comint-previous-matching-input-from-input))
    (define-key map [menu-bar inout next-history]
      '("Next Input" . comint-next-input))
    (define-key map [menu-bar inout previous-history]
      '("Previous Input" . comint-previous-input))
    (define-key map [menu-bar inout list-history]
      '("List Input History" . comint-dynamic-list-input-ring))
    (define-key map [menu-bar inout expand-history]
      '("Expand History Before Point" . comint-replace-by-expanded-history))
    ;; Signals
    (let ((signals-map (make-sparse-keymap "Signals")))
      (define-key map [menu-bar signals] (cons "Signals" signals-map))
      (define-key signals-map [eof]   '("EOF"   . comint-send-eof))
      (define-key signals-map [kill]  '("KILL"  . comint-kill-subjob))
      (define-key signals-map [quit]  '("QUIT"  . comint-quit-subjob))
      (define-key signals-map [cont]  '("CONT"  . comint-continue-subjob))
      (define-key signals-map [stop]  '("STOP"  . comint-stop-subjob))
      (define-key signals-map [break] '("BREAK" . comint-interrupt-subjob)))
    ;; Put them in the menu bar:
    (setq menu-bar-final-items (append '(completion inout signals)
				       menu-bar-final-items))
    map))
David Lawrence's avatar
David Lawrence committed
554

Stefan Monnier's avatar
Stefan Monnier committed
555
;; Fixme: Is this still relevant?
Richard M. Stallman's avatar
Richard M. Stallman committed
556
(defvar comint-ptyp t
557
  "Non-nil if communications via pty; false if by pipe.  Buffer local.
558
This is to work around a bug in Emacs process signaling.")
Richard M. Stallman's avatar
Richard M. Stallman committed
559

560
(defvar comint-input-ring nil)
Stefan Monnier's avatar
Stefan Monnier committed
561 562 563
(defvar comint-last-input-start nil)
(defvar comint-last-input-end nil)
(defvar comint-last-output-start nil)
564 565 566 567
(defvar comint-input-ring-index nil
  "Index of last matched history element.")
(defvar comint-matching-input-from-input-string ""
  "Input previously used to match input history.")
568
(defvar comint-save-input-ring-index nil
569 570 571 572 573 574
  "Last input ring index which you copied.
This is to support the command \\[comint-get-next-from-history].")

(defvar comint-accum-marker nil
  "Non-nil if you are accumulating input lines to send as input together.
The command \\[comint-accumulate] sets this.")
575

576 577 578
(defvar comint-stored-incomplete-input nil
  "Stored input for history cycling.")

579
(put 'comint-replace-by-expanded-history 'menu-enable 'comint-input-autoexpand)
Richard M. Stallman's avatar
Richard M. Stallman committed
580
(put 'comint-input-ring 'permanent-local t)
581
(put 'comint-input-ring-index 'permanent-local t)
582
(put 'comint-save-input-ring-index 'permanent-local t)
583
(put 'comint-input-autoexpand 'permanent-local t)
584 585
(put 'comint-input-filter-functions 'permanent-local t)
(put 'comint-output-filter-functions 'permanent-local t)
586
(put 'comint-preoutput-filter-functions 'permanent-local t)
587
(put 'comint-scroll-to-bottom-on-input 'permanent-local t)
588
(put 'comint-move-point-for-output 'permanent-local t)
589
(put 'comint-scroll-show-maximum-output 'permanent-local t)
Richard M. Stallman's avatar
Richard M. Stallman committed
590
(put 'comint-ptyp 'permanent-local t)
591

592 593
(put 'comint-mode 'mode-class 'special)

594
(define-derived-mode comint-mode fundamental-mode "Comint"
David Lawrence's avatar
David Lawrence committed
595 596 597 598
  "Major mode for interacting with an inferior interpreter.
Interpreter name is same as buffer name, sans the asterisks.
Return at end of buffer sends line as input.
Return not at end copies rest of line to end and sends it.
599
Setting variable `comint-eol-on-send' means jump to the end of the line
Jim Blandy's avatar
Jim Blandy committed
600
before submitting new input.
David Lawrence's avatar
David Lawrence committed
601

602
This mode is customized to create major modes such as Inferior Lisp
603
mode, Shell mode, etc.  This can be done by setting the hooks
604
`comint-input-filter-functions', `comint-input-filter', `comint-input-sender'
605
and `comint-get-old-input' to appropriate functions, and the variable
606
`comint-prompt-regexp' to the appropriate regular expression.
David Lawrence's avatar
David Lawrence committed
607

608 609 610
The mode maintains an input history of size `comint-input-ring-size'.
You can access this with the commands \\[comint-next-input],
\\[comint-previous-input], and \\[comint-dynamic-list-input-ring].
611 612 613 614 615
Input ring history expansion can be achieved with the commands
\\[comint-replace-by-expanded-history] or \\[comint-magic-space].
Input ring expansion is controlled by the variable `comint-input-autoexpand',
and addition is controlled by the variable `comint-input-ignoredups'.

616
Commands with no default key bindings include `send-invisible',
Miles Bader's avatar
Miles Bader committed
617
`comint-dynamic-complete', `comint-dynamic-list-filename-completions', and
618 619 620
`comint-magic-space'.

Input to, and output from, the subprocess can cause the window to scroll to
621
the end of the buffer.  See variables `comint-output-filter-functions',
622
`comint-preoutput-filter-functions', `comint-scroll-to-bottom-on-input',
623
and `comint-move-point-for-output'.
David Lawrence's avatar
David Lawrence committed
624 625 626 627 628 629

If you accidentally suspend your process, use \\[comint-continue-subjob]
to continue it.

\\{comint-mode-map}

630
Entry to this mode runs the hooks on `comint-mode-hook'."
631
  (setq mode-line-process '(":%s"))
632
  (set (make-local-variable 'window-point-insertion-type) t)
Stefan Monnier's avatar
Stefan Monnier committed
633 634 635
  (set (make-local-variable 'comint-last-input-start) (point-min-marker))
  (set (make-local-variable 'comint-last-input-end) (point-min-marker))
  (set (make-local-variable 'comint-last-output-start) (make-marker))
636
  (make-local-variable 'comint-last-prompt-overlay)
637 638 639 640 641 642 643
  (make-local-variable 'comint-prompt-regexp)        ; Don't set; default
  (make-local-variable 'comint-input-ring-size)      ; ...to global val.
  (make-local-variable 'comint-input-ring)
  (make-local-variable 'comint-input-ring-file-name)
  (or (and (boundp 'comint-input-ring) comint-input-ring)
      (setq comint-input-ring (make-ring comint-input-ring-size)))
  (make-local-variable 'comint-input-ring-index)
644
  (make-local-variable 'comint-save-input-ring-index)
645 646
  (or (and (boundp 'comint-input-ring-index) comint-input-ring-index)
      (setq comint-input-ring-index nil))
647 648
  (or (and (boundp 'comint-save-input-ring-index) comint-save-input-ring-index)
      (setq comint-save-input-ring-index nil))
649 650 651 652
  (make-local-variable 'comint-matching-input-from-input-string)
  (make-local-variable 'comint-input-autoexpand)
  (make-local-variable 'comint-input-ignoredups)
  (make-local-variable 'comint-delimiter-argument-list)
653
  (make-local-variable 'comint-completion-fignore)
654 655 656 657 658
  (make-local-variable 'comint-get-old-input)
  (make-local-variable 'comint-input-filter)
  (make-local-variable 'comint-input-sender)
  (make-local-variable 'comint-eol-on-send)
  (make-local-variable 'comint-scroll-to-bottom-on-input)
659
  (make-local-variable 'comint-move-point-for-output)
660
  (make-local-variable 'comint-scroll-show-maximum-output)
661
  (make-local-variable 'comint-stored-incomplete-input)
662 663 664 665 666 667
  ;; Following disabled because it seems to break the case when
  ;; comint-scroll-show-maximum-output is nil, and no-one can remember
  ;; what the original problem was.  If there are problems with point
  ;; not going to the end, consider re-enabling this.
  ;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00827.html
  ;;
668
  ;; This makes it really work to keep point at the bottom.
669 670
  ;; (make-local-variable 'scroll-conservatively)
  ;; (setq scroll-conservatively 10000)
671
  (add-hook 'pre-command-hook 'comint-preinput-scroll-to-bottom t t)
672 673
  (make-local-variable 'comint-ptyp)
  (make-local-variable 'comint-process-echoes)
674
  (make-local-variable 'comint-file-name-chars)
675
  (make-local-variable 'comint-file-name-quote-list)
676 677 678
  ;; dir tracking on remote files
  (set (make-local-variable 'comint-file-name-prefix)
       (or (file-remote-p default-directory) ""))
679 680 681
  (make-local-variable 'comint-accum-marker)
  (setq comint-accum-marker (make-marker))
  (make-local-variable 'font-lock-defaults)
682
  (setq font-lock-defaults '(nil t))
683
  (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
684
  (add-hook 'isearch-mode-hook 'comint-history-isearch-setup nil t)
685 686
  ;; This behavior is not useful in comint buffers, and is annoying
  (set (make-local-variable 'next-line-add-newlines) nil))
David Lawrence's avatar
David Lawrence committed
687

Jim Blandy's avatar
Jim Blandy committed
688
(defun comint-check-proc (buffer)
689
  "Return non-nil if there is a living process associated w/buffer BUFFER.
690
Living means the status is `open', `run', or `stop'.
691
BUFFER can be either a buffer or the name of one."
Jim Blandy's avatar
Jim Blandy committed
692
  (let ((proc (get-buffer-process buffer)))
693
    (and proc (memq (process-status proc) '(open run stop)))))
David Lawrence's avatar
David Lawrence committed
694

695 696
;;;###autoload
(defun make-comint-in-buffer (name buffer program &optional startfile &rest switches)
Stefan Monnier's avatar
Stefan Monnier committed
697
  "Make a Comint process NAME in BUFFER, running PROGRAM.
698 699
If BUFFER is nil, it defaults to NAME surrounded by `*'s.
PROGRAM should be either a string denoting an executable program to create
700 701 702
via `start-file-process', or a cons pair of the form (HOST . SERVICE) denoting
a TCP connection to be opened via `open-network-stream'.  If there is already
a running process in that buffer, it is not restarted.  Optional fourth arg
703 704
STARTFILE is the name of a file, whose contents are sent to the
process as its initial input.
705

Štěpán Němec's avatar
Štěpán Němec committed
706 707 708
If PROGRAM is a string, any more args are arguments to PROGRAM.

Returns the (possibly newly created) process buffer."
709
  (or (fboundp 'start-file-process)
710 711 712 713 714 715
      (error "Multi-processing is not supported for this system"))
  (setq buffer (get-buffer-create (or buffer (concat "*" name "*"))))
  ;; If no process, or nuked process, crank up a new one and put buffer in
  ;; comint mode.  Otherwise, leave buffer and existing process alone.
  (unless (comint-check-proc buffer)
    (with-current-buffer buffer
Stefan Monnier's avatar
Stefan Monnier committed
716 717
      (unless (derived-mode-p 'comint-mode)
	(comint-mode))) ; Install local vars, mode, keymap, ...
718 719 720
    (comint-exec buffer name program startfile switches))
  buffer)

721
;;;###autoload
David Lawrence's avatar
David Lawrence committed
722
(defun make-comint (name program &optional startfile &rest switches)
Stefan Monnier's avatar
Stefan Monnier committed
723
  "Make a Comint process NAME in a buffer, running PROGRAM.
724
The name of the buffer is made by surrounding NAME with `*'s.
725
PROGRAM should be either a string denoting an executable program to create
726 727 728
via `start-file-process', or a cons pair of the form (HOST . SERVICE) denoting
a TCP connection to be opened via `open-network-stream'.  If there is already
a running process in that buffer, it is not restarted.  Optional third arg
729 730
STARTFILE is the name of a file, whose contents are sent to the
process as its initial input.
731

Štěpán Němec's avatar
Štěpán Němec committed
732 733 734
If PROGRAM is a string, any more args are arguments to PROGRAM.

Returns the (possibly newly created) process buffer."
735
  (apply #'make-comint-in-buffer name nil program startfile switches))
David Lawrence's avatar
David Lawrence committed
736

737
;;;###autoload
738
(defun comint-run (program)
Stefan Monnier's avatar
Stefan Monnier committed
739
  "Run PROGRAM in a Comint buffer and switch to it.
740 741 742 743 744 745 746 747 748
The buffer name is made by surrounding the file name of PROGRAM with `*'s.
The file name is used to make a symbol name, such as `comint-sh-hook', and any
hooks on this symbol are run in the buffer.
See `make-comint' and `comint-exec'."
  (interactive "sRun program: ")
  (let ((name (file-name-nondirectory program)))
    (switch-to-buffer (make-comint name program))
    (run-hooks (intern-soft (concat "comint-" name "-hook")))))

David Lawrence's avatar
David Lawrence committed
749
(defun comint-exec (buffer name command startfile switches)
Stefan Monnier's avatar
Stefan Monnier committed
750
  "Start up a process named NAME in buffer BUFFER for Comint modes.
751
Runs the given COMMAND with SWITCHES, and initial input from STARTFILE.
752
Blasts any old process running in the buffer.  Doesn't set the buffer mode.
Stefan Monnier's avatar
Stefan Monnier committed
753
You can use this to cheaply run a series of processes in the same Comint
754
buffer.  The hook `comint-exec-hook' is run after each exec."
755
  (with-current-buffer buffer
David Lawrence's avatar
David Lawrence committed
756 757 758
    (let ((proc (get-buffer-process buffer)))	; Blast any old process.
      (if proc (delete-process proc)))
    ;; Crank up a new process
759 760 761 762
    (let ((proc
	   (if (consp command)
	       (open-network-stream name buffer (car command) (cdr command))
	     (comint-exec-1 name buffer command switches))))
763
      (set-process-filter proc 'comint-output-filter)
Jim Blandy's avatar
Jim Blandy committed
764
      (make-local-variable 'comint-ptyp)
Pavel Janík's avatar
Pavel Janík committed
765
      (setq comint-ptyp process-connection-type) ; t if pty, nil if pipe.
David Lawrence's avatar
David Lawrence committed
766
      ;; Jump to the end, and set the process mark.
Jim Blandy's avatar
Jim Blandy committed
767
      (goto-char (point-max))
Jim Blandy's avatar
Jim Blandy committed
768
      (set-marker (process-mark proc) (point))
David Lawrence's avatar
David Lawrence committed
769 770 771 772 773 774 775 776 777 778 779 780
      ;; Feed it the startfile.
      (cond (startfile
	     ;;This is guaranteed to wait long enough
	     ;;but has bad results if the comint does not prompt at all
	     ;;	     (while (= size (buffer-size))
	     ;;	       (sleep-for 1))
	     ;;I hope 1 second is enough!
	     (sleep-for 1)
	     (goto-char (point-max))
	     (insert-file-contents startfile)
	     (setq startfile (buffer-substring (point) (point-max)))
	     (delete-region (point) (point-max))
Jim Blandy's avatar
Jim Blandy committed
781
	     (comint-send-string proc startfile)))
782 783
      (run-hooks 'comint-exec-hook)
      buffer)))
David Lawrence's avatar
David Lawrence committed
784

Erik Naggum's avatar
Erik Naggum committed
785 786
;; This auxiliary function cranks up the process for comint-exec in
;; the appropriate environment.
David Lawrence's avatar
David Lawrence committed
787 788

(defun comint-exec-1 (name buffer command switches)
789
  (let ((process-environment
790
	 (nconc
Richard M. Stallman's avatar
Richard M. Stallman committed
791 792
	  ;; If using termcap, we specify `emacs' as the terminal type
	  ;; because that lets us specify a width.
793
	  ;; If using terminfo, we specify `dumb' because that is
Richard M. Stallman's avatar
Richard M. Stallman committed
794 795 796 797
	  ;; a defined terminal type.  `emacs' is not a defined terminal type
	  ;; and there is no way for us to define it here.
	  ;; Some programs that use terminfo get very confused
	  ;; if TERM is not a valid terminal type.
Richard M. Stallman's avatar
Richard M. Stallman committed
798
	  ;; ;; There is similar code in compile.el.
799
	  (if (and (boundp 'system-uses-terminfo) system-uses-terminfo)
800
	      (list "TERM=dumb" "TERMCAP="
801
		    (format "COLUMNS=%d" (window-width)))
802
	    (list "TERM=emacs"
803
		  (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width))))
804
	  (unless (getenv "EMACS")
805
	    (list "EMACS=t"))
806
	  (list (format "INSIDE_EMACS=%s,comint" emacs-version))
807 808
	  process-environment))
	(default-directory
809
	  (if (file-accessible-directory-p default-directory)
810
	      default-directory
811
	    "/"))
812
	proc decoding encoding changed)
813
    (let ((exec-path (if (and command (file-name-directory command))
814 815 816
			 ;; If the command has slashes, make sure we
			 ;; first look relative to the current directory.
			 (cons default-directory exec-path) exec-path)))
817
      (setq proc (apply 'start-file-process name buffer command switches)))
818 819
    ;; Some file name handler cannot start a process, fe ange-ftp.
    (unless (processp proc) (error "No process started"))
820 821 822
    (let ((coding-systems (process-coding-system proc)))
      (setq decoding (car coding-systems)
	    encoding (cdr coding-systems)))
823
    ;; Even if start-file-process left the coding system for encoding data
824 825 826 827 828 829 830 831 832
    ;; sent from the process undecided, we had better use the same one
    ;; as what we use for decoding.  But, we should suppress EOL
    ;; conversion.
    (if (and decoding (not encoding))
	(setq encoding (coding-system-change-eol-conversion decoding 'unix)
	      changed t))
    (if changed
	(set-process-coding-system proc decoding encoding))
    proc))
833

834
(defun comint-insert-input (event)
835 836
  "In a Comint buffer, set the current input to the previous input at point.
If there is no previous input at point, run the command specified
Glenn Morris's avatar
Glenn Morris committed
837
by the global keymap (usually `mouse-yank-at-click')."
838
  (interactive "e")
839 840 841
  ;; Don't set the mouse here, since it may otherwise change the behavior
  ;; of the command on which we fallback if there's no field at point.
  ;; (mouse-set-point event)
842 843 844
  (let ((pos (posn-point (event-end event)))
	field input)
    (with-selected-window (posn-window (event-end event))
845 846 847 848
      ;; If pos is at the very end of a field, the mouse-click was
      ;; probably outside (to the right) of the field.
      (and (< pos (field-end pos))
           (setq field (field-at-pos pos))
849 850 851 852 853 854 855
	   (setq input (field-string-no-properties pos))))
    (if (or (null comint-accum-marker)
	    (not (eq field 'input)))
	;; Fall back to the global definition if (i) the selected
	;; buffer is not a comint buffer (which can happen if a
	;; non-comint window was selected and we clicked in a comint
	;; window), or (ii) there is no input at POS.
856 857 858
	(let* ((keys (this-command-keys))
	       (last-key (and (vectorp keys) (aref keys (1- (length keys)))))
	       (fun (and last-key (lookup-key global-map (vector last-key)))))
859 860
	  (and fun (not (eq fun 'comint-insert-input))
	       (call-interactively fun)))
861 862 863 864 865 866 867 868 869 870
      (with-selected-window (posn-window (event-end event))
        ;; Otherwise, insert the previous input.
        (goto-char (point-max))
        ;; First delete any old unsent input at the end
        (delete-region
         (or (marker-position comint-accum-marker)
             (process-mark (get-buffer-process (current-buffer))))
         (point))
        ;; Insert the input at point
        (insert input)))))
David Lawrence's avatar
David Lawrence committed
871

Erik Naggum's avatar
Erik Naggum committed
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893
;; Input history processing in a buffer
;; ===========================================================================
;; Useful input history functions, courtesy of the Ergo group.

;; Eleven commands:
;; comint-dynamic-list-input-ring	List history in help buffer.
;; comint-previous-input		Previous input...
;; comint-previous-matching-input	...matching a string.
;; comint-previous-matching-input-from-input ... matching the current input.
;; comint-next-input			Next input...
;; comint-next-matching-input		...matching a string.
;; comint-next-matching-input-from-input     ... matching the current input.
;; comint-backward-matching-input      Backwards input...
;; comint-forward-matching-input       ...matching a string.
;; comint-replace-by-expanded-history	Expand history at point;
;;					replace with expanded history.
;; comint-magic-space			Expand history and insert space.
;;
;; Three functions:
;; comint-read-input-ring              Read into comint-input-ring...
;; comint-write-input-ring             Write to comint-input-ring-file-name.
;; comint-replace-by-expanded-history-before-point Workhorse function.
894

895
(defun comint-read-input-ring (&optional silent)
Stefan Monnier's avatar
Stefan Monnier committed
896
  "Set the buffer's `comint-input-ring' from a history file.
897 898 899 900
The name of the file is given by the variable `comint-input-ring-file-name'.
The history ring is of size `comint-input-ring-size', regardless of file size.
If `comint-input-ring-file-name' is nil this function does nothing.

901 902
If the optional argument SILENT is non-nil, we say nothing about a
failure to read the history file.