;;; comint.el --- general command interpreter in a window stuff
-;; Copyright (C) 1988,90,92,93,94,95,96,97,98,99,2000,01,02,03,2004
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1990, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+;; 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
;; Author: Olin Shivers <shivers@cs.cmu.edu>
;; Simon Marshall <simon@gnu.org>
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
:group 'processes)
(defgroup comint-completion nil
- "Completion facilities in comint"
+ "Completion facilities in comint."
:group 'comint)
(defgroup comint-source nil
- "Source finding facilities in comint"
+ "Source finding facilities in comint."
:prefix "comint-"
:group 'comint)
(defvar comint-prompt-regexp "^"
- "Regexp to recognise prompts in the inferior process.
+ "Regexp to recognize prompts in the inferior process.
Defaults to \"^\", the null string at BOL.
This variable is only used if the variable
-`comint-use-prompt-regexp-instead-of-fields' is non-nil.
+`comint-use-prompt-regexp' is non-nil.
Good choices:
Canonical Lisp: \"^[^> \\n]*>+:? *\" (Lucid, franz, kcl, T, cscheme, oaklisp)
wish to put something like the following in your `.emacs' file:
\(add-hook 'comint-mode-hook
- '(lambda ()
- (define-key comint-mode-map \"\C-w\" 'comint-kill-region)
- (define-key comint-mode-map [C-S-backspace]
- 'comint-kill-whole-line)))
+ (lambda ()
+ (define-key comint-mode-map \"\\C-w\" 'comint-kill-region)
+ (define-key comint-mode-map [C-S-backspace]
+ 'comint-kill-whole-line)))
-If you sometimes use comint-mode on text-only terminals or with `emacs-nw',
+If you sometimes use comint-mode on text-only terminals or with `emacs -nw',
you might wish to use another binding for `comint-kill-whole-line'."
:type 'boolean
:group 'comint
- :version "21.4")
+ :version "22.1")
(defvar comint-delimiter-argument-list ()
- "List of characters to recognise as separate arguments in input.
+ "List of characters to recognize as separate arguments in input.
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'.
:group 'comint)
(defface comint-highlight-prompt
- '((((background dark)) (:foreground "cyan"))
+ '((((min-colors 88) (background dark)) (:foreground "cyan1"))
+ (((background dark)) (:foreground "cyan"))
(t (:foreground "dark blue")))
"Face to use to highlight prompts."
:group 'comint)
:type 'integer
:group 'comint)
-(defvar comint-input-ring-size 32
+(defvar comint-input-ring-size 150
"Size of input history ring.")
(defvar comint-input-ring-separator "\n"
"\\(\\([Oo]ld \\|[Nn]ew \\|'s \\|login \\|\
Kerberos \\|CVS \\|UNIX \\| SMB \\|^\\)\
\[Pp]assword\\( (again)\\)?\\|\
-pass phrase\\|\\(Enter\\|Repeat\\) passphrase\\)\
-\\( for [^:]+\\)?:\\s *\\'"
+pass phrase\\|\\(Enter\\|Repeat\\|Bad\\) passphrase\\)\
+\\(?:, try again\\)?\\(?: for [^:]+\\)?:\\s *\\'"
"*Regexp matching prompts for passwords in the inferior process.
This is used by `comint-watch-for-password-prompt'."
:type 'regexp
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
-`comint-use-prompt-regexp-instead-of-fields'.")
+`comint-use-prompt-regexp'.")
(defvar comint-dynamic-complete-functions
'(comint-replace-by-expanded-history comint-dynamic-complete-filename)
history list. Default is to save anything that isn't all whitespace.")
(defvar comint-input-filter-functions '()
- "Functions to call before input is sent to the process.
-These functions get one argument, a string containing the text to send.
+ "Abnormal hook run before input is sent to the process.
+These functions get one argument, a string containing the text to send.")
-You can use `add-hook' to add functions to this list
-either globally or locally.")
-
-(defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom)
+;;;###autoload
+(defvar comint-output-filter-functions '(comint-postoutput-scroll-to-bottom comint-watch-for-password-prompt)
"Functions to call after output is inserted into the buffer.
One possible function is `comint-postoutput-scroll-to-bottom'.
These functions get one argument, a string containing the text as originally
;; 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.
-(defcustom comint-use-prompt-regexp-instead-of-fields nil
- "*If non-nil, use `comint-prompt-regexp' to distinguish prompts from user-input.
+(defcustom comint-use-prompt-regexp nil
+ "*If non-nil, use `comint-prompt-regexp' to recognize prompts.
If nil, then program output and user-input are given different `field'
-properties, which emacs commands can use to distinguish them (in
-particular, common movement commands such as begining-of-line respect
-field boundaries in a natural way)."
+properties, which Emacs commands can use to distinguish them (in
+particular, common movement commands such as `beginning-of-line'
+respect field boundaries in a natural way)."
:type 'boolean
:group 'comint)
-(defcustom comint-mode-hook '(turn-on-font-lock)
+;; Autoload is necessary for Custom to recognize old alias.
+;;;###autoload
+(define-obsolete-variable-alias 'comint-use-prompt-regexp-instead-of-fields
+ 'comint-use-prompt-regexp "22.1")
+
+(defcustom comint-mode-hook nil
"Hook run upon entry to `comint-mode'.
This is run before the process is cranked up."
:type 'hook
:type 'hook
:group 'comint)
-(defvar comint-mode-map nil)
+(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)
+ (define-key map "\er" 'comint-previous-matching-input)
+ (define-key map "\es" 'comint-next-matching-input)
+ (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)
+ (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)
+ (define-key map "\C-c\C-m" 'comint-insert-input)
+ (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]
+ '("Copy Old Input" . comint-insert-input))
+ (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))
;; Fixme: Is this still relevant?
(defvar comint-ptyp t
Setting variable `comint-eol-on-send' means jump to the end of the line
before submitting new input.
-This mode is customised to create major modes such as Inferior Lisp
+This mode is customized to create major modes such as Inferior Lisp
mode, Shell mode, etc. This can be done by setting the hooks
`comint-input-filter-functions', `comint-input-filter', `comint-input-sender'
and `comint-get-old-input' to appropriate functions, and the variable
;; This behavior is not useful in comint buffers, and is annoying
(set (make-local-variable 'next-line-add-newlines) nil))
-(if comint-mode-map
- nil
- ;; Keys:
- (setq comint-mode-map (make-sparse-keymap))
- (define-key comint-mode-map "\ep" 'comint-previous-input)
- (define-key comint-mode-map "\en" 'comint-next-input)
- (define-key comint-mode-map [C-up] 'comint-previous-input)
- (define-key comint-mode-map [C-down] 'comint-next-input)
- (define-key comint-mode-map "\er" 'comint-previous-matching-input)
- (define-key comint-mode-map "\es" 'comint-next-matching-input)
- (define-key comint-mode-map [?\C-c ?\M-r] 'comint-previous-matching-input-from-input)
- (define-key comint-mode-map [?\C-c ?\M-s] 'comint-next-matching-input-from-input)
- (define-key comint-mode-map "\e\C-l" 'comint-show-output)
- (define-key comint-mode-map "\C-m" 'comint-send-input)
- (define-key comint-mode-map "\C-d" 'comint-delchar-or-maybe-eof)
- (define-key comint-mode-map "\C-c " 'comint-accumulate)
- (define-key comint-mode-map "\C-c\C-x" 'comint-get-next-from-history)
- (define-key comint-mode-map "\C-c\C-a" 'comint-bol-or-process-mark)
- (define-key comint-mode-map "\C-c\C-u" 'comint-kill-input)
- (define-key comint-mode-map "\C-c\C-w" 'backward-kill-word)
- (define-key comint-mode-map "\C-c\C-c" 'comint-interrupt-subjob)
- (define-key comint-mode-map "\C-c\C-z" 'comint-stop-subjob)
- (define-key comint-mode-map "\C-c\C-\\" 'comint-quit-subjob)
- (define-key comint-mode-map "\C-c\C-m" 'comint-copy-old-input)
- (define-key comint-mode-map "\C-c\C-o" 'comint-delete-output)
- (define-key comint-mode-map "\C-c\C-r" 'comint-show-output)
- (define-key comint-mode-map "\C-c\C-e" 'comint-show-maximum-output)
- (define-key comint-mode-map "\C-c\C-l" 'comint-dynamic-list-input-ring)
- (define-key comint-mode-map "\C-c\C-n" 'comint-next-prompt)
- (define-key comint-mode-map "\C-c\C-p" 'comint-previous-prompt)
- (define-key comint-mode-map "\C-c\C-d" 'comint-send-eof)
- (define-key comint-mode-map "\C-c\C-s" 'comint-write-output)
- (define-key comint-mode-map "\C-c." 'comint-insert-previous-argument)
- ;; Mouse Buttons:
- (define-key comint-mode-map [mouse-2] 'comint-insert-clicked-input)
- ;; Menu bars:
- ;; completion:
- (define-key comint-mode-map [menu-bar completion]
- (cons "Complete" (make-sparse-keymap "Complete")))
- (define-key comint-mode-map [menu-bar completion complete-expand]
- '("Expand File Name" . comint-replace-by-expanded-filename))
- (define-key comint-mode-map [menu-bar completion complete-listing]
- '("File Completion Listing" . comint-dynamic-list-filename-completions))
- (define-key comint-mode-map [menu-bar completion complete-file]
- '("Complete File Name" . comint-dynamic-complete-filename))
- (define-key comint-mode-map [menu-bar completion complete]
- '("Complete Before Point" . comint-dynamic-complete))
- ;; Input history:
- (define-key comint-mode-map [menu-bar inout]
- (cons "In/Out" (make-sparse-keymap "In/Out")))
- (define-key comint-mode-map [menu-bar inout delete-output]
- '("Delete Current Output Group" . comint-delete-output))
- (define-key comint-mode-map [menu-bar inout append-output-to-file]
- '("Append Current Output Group to File" . comint-append-output-to-file))
- (define-key comint-mode-map [menu-bar inout write-output]
- '("Write Current Output Group to File" . comint-write-output))
- (define-key comint-mode-map [menu-bar inout next-prompt]
- '("Forward Output Group" . comint-next-prompt))
- (define-key comint-mode-map [menu-bar inout previous-prompt]
- '("Backward Output Group" . comint-previous-prompt))
- (define-key comint-mode-map [menu-bar inout show-maximum-output]
- '("Show Maximum Output" . comint-show-maximum-output))
- (define-key comint-mode-map [menu-bar inout show-output]
- '("Show Current Output Group" . comint-show-output))
- (define-key comint-mode-map [menu-bar inout kill-input]
- '("Kill Current Input" . comint-kill-input))
- (define-key comint-mode-map [menu-bar inout copy-input]
- '("Copy Old Input" . comint-copy-old-input))
- (define-key comint-mode-map [menu-bar inout forward-matching-history]
- '("Forward Matching Input..." . comint-forward-matching-input))
- (define-key comint-mode-map [menu-bar inout backward-matching-history]
- '("Backward Matching Input..." . comint-backward-matching-input))
- (define-key comint-mode-map [menu-bar inout next-matching-history]
- '("Next Matching Input..." . comint-next-matching-input))
- (define-key comint-mode-map [menu-bar inout previous-matching-history]
- '("Previous Matching Input..." . comint-previous-matching-input))
- (define-key comint-mode-map [menu-bar inout next-matching-history-from-input]
- '("Next Matching Current Input" . comint-next-matching-input-from-input))
- (define-key comint-mode-map [menu-bar inout previous-matching-history-from-input]
- '("Previous Matching Current Input" . comint-previous-matching-input-from-input))
- (define-key comint-mode-map [menu-bar inout next-history]
- '("Next Input" . comint-next-input))
- (define-key comint-mode-map [menu-bar inout previous-history]
- '("Previous Input" . comint-previous-input))
- (define-key comint-mode-map [menu-bar inout list-history]
- '("List Input History" . comint-dynamic-list-input-ring))
- (define-key comint-mode-map [menu-bar inout expand-history]
- '("Expand History Before Point" . comint-replace-by-expanded-history))
- ;; Signals
- (define-key comint-mode-map [menu-bar signals]
- (cons "Signals" (make-sparse-keymap "Signals")))
- (define-key comint-mode-map [menu-bar signals eof]
- '("EOF" . comint-send-eof))
- (define-key comint-mode-map [menu-bar signals kill]
- '("KILL" . comint-kill-subjob))
- (define-key comint-mode-map [menu-bar signals quit]
- '("QUIT" . comint-quit-subjob))
- (define-key comint-mode-map [menu-bar signals cont]
- '("CONT" . comint-continue-subjob))
- (define-key comint-mode-map [menu-bar signals stop]
- '("STOP" . comint-stop-subjob))
- (define-key comint-mode-map [menu-bar signals break]
- '("BREAK" . comint-interrupt-subjob))
- ;; Put them in the menu bar:
- (setq menu-bar-final-items (append '(completion inout signals)
- menu-bar-final-items))
- )
-
(defun comint-check-proc (buffer)
- "Return t if there is a living process associated w/buffer BUFFER.
+ "Return non-nil if there is a living process associated w/buffer BUFFER.
Living means the status is `open', `run', or `stop'.
BUFFER can be either a buffer or the name of one."
(let ((proc (get-buffer-process buffer)))
PROGRAM should be either a string denoting an executable program to create
via `start-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
+running process in that buffer, it is not restarted. Optional fourth arg
STARTFILE is the name of a file to send the contents of to the process.
If PROGRAM is a string, any more args are arguments to PROGRAM."
(set-process-coding-system proc decoding encoding))
proc))
-
-(defun comint-insert-clicked-input (event)
- "In a Comint buffer, set the current input to the clicked-on previous input."
- (interactive "e")
- (let ((pos (posn-point (event-end event))))
- (if (not (eq (get-char-property pos 'field) 'input))
+(defun comint-insert-input (&optional event)
+ "In a Comint buffer, set the current input to the previous input at point."
+ ;; This doesn't use "e" because it is supposed to work
+ ;; for events without parameters.
+ (interactive (list last-input-event))
+ (let ((pos (point)))
+ (if event (mouse-set-point event))
+ (if (not (eq (get-char-property (point) 'field) 'input))
;; No input at POS, fall back to the global definition.
(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)))))
+ (goto-char pos)
(and fun (call-interactively fun)))
+ (setq pos (point))
;; There's previous input at POS, insert it at the end of the buffer.
(goto-char (point-max))
;; First delete any old unsent input at the end
(or (marker-position comint-accum-marker)
(process-mark (get-buffer-process (current-buffer))))
(point))
- ;; Insert the clicked-upon input
+ ;; Insert the input at point
(insert (buffer-substring-no-properties
(previous-single-char-property-change (1+ pos) 'field)
(next-single-char-property-change pos 'field))))))
-
\f
;; Input history processing in a buffer
;; ===========================================================================
(message "Hit space to flush")
(setq comint-dynamic-list-input-ring-window-conf conf)
(let ((ch (read-event)))
- (if (eq ch ?\ )
+ (if (eq ch ?\s)
(set-window-configuration conf)
(setq unread-command-events (list ch)))))))
(if (string-match regexp (ring-ref comint-input-ring n))
n)))
-(defun comint-previous-matching-input (regexp arg)
+(defun comint-previous-matching-input (regexp n)
"Search backwards through input history for match for REGEXP.
\(Previous history elements are earlier commands.)
With prefix argument N, search for Nth previous match.
If N is negative, find the next or Nth next match."
(interactive (comint-regexp-arg "Previous input matching (regexp): "))
- (setq arg (comint-search-arg arg))
- (let ((pos (comint-previous-matching-input-string-position regexp arg)))
+ (setq n (comint-search-arg n))
+ (let ((pos (comint-previous-matching-input-string-position regexp n)))
;; Has a match been found?
(if (null pos)
(error "Not found")
(point))
(insert (ring-ref comint-input-ring pos)))))
-(defun comint-next-matching-input (regexp arg)
+(defun comint-next-matching-input (regexp n)
"Search forwards through input history for match for REGEXP.
\(Later history elements are more recent commands.)
With prefix argument N, search for Nth following match.
If N is negative, find the previous or Nth previous match."
(interactive (comint-regexp-arg "Next input matching (regexp): "))
- (comint-previous-matching-input regexp (- arg)))
+ (comint-previous-matching-input regexp (- n)))
-(defun comint-previous-matching-input-from-input (arg)
+(defun comint-previous-matching-input-from-input (n)
"Search backwards through input history for match for current input.
\(Previous history elements are earlier commands.)
With prefix argument N, search for Nth previous match.
comint-input-ring-index nil))
(comint-previous-matching-input
(concat "^" (regexp-quote comint-matching-input-from-input-string))
- arg))
+ n))
-(defun comint-next-matching-input-from-input (arg)
+(defun comint-next-matching-input-from-input (n)
"Search forwards through input history for match for current input.
\(Following history elements are more recent commands.)
With prefix argument N, search for Nth following match.
If N is negative, search backwards for the -Nth previous match."
(interactive "p")
- (comint-previous-matching-input-from-input (- arg)))
+ (comint-previous-matching-input-from-input (- n)))
(defun comint-replace-by-expanded-history (&optional silent start)
Returns t if successful."
(interactive)
(if (and comint-input-autoexpand
- (if comint-use-prompt-regexp-instead-of-fields
+ (if comint-use-prompt-regexp
;; Use comint-prompt-regexp
(save-excursion
(beginning-of-line)
than the logical beginning of line."
(save-excursion
(let ((toend (- (line-end-position) (point)))
- (start (comint-line-beginning-position)))
+ (start (or start (comint-line-beginning-position))))
(goto-char start)
(while (progn
(skip-chars-forward "^!^" (- (line-end-position) toend))
cmd))))
(ring-insert comint-input-ring cmd)))
-(defun comint-send-input (&optional no-newline)
+(defun comint-send-input (&optional no-newline artificial)
"Send input to process.
After the process output mark, sends all text from the process mark to
point as input to the process. Before the process output mark, calls
value of variable `comint-get-old-input' to retrieve old input, copies
-it to the process mark, and sends it. A terminal newline is also
-inserted into the buffer and sent to the process unless NO-NEWLINE is
-non-nil.
+it to the process mark, and sends it.
+
+This command also sends and inserts a final newline, unless
+NO-NEWLINE is non-nil.
Any history reference may be expanded depending on the value of the variable
`comint-input-autoexpand'. The list of function names contained in the value
After the input has been sent, if `comint-process-echoes' is non-nil,
then `comint-send-input' waits to see if the process outputs a string
matching the input, and if so, deletes that part of the output.
+If ARTIFICIAL is non-nil, it inhibits such deletion.
+Callers sending input not from the user should use ARTIFICIAL = t.
The values of `comint-get-old-input', `comint-input-filter-functions', and
`comint-input-filter' are chosen according to the command interpreter running
If the interpreter is the csh,
`comint-get-old-input' is the default:
- If `comint-use-prompt-regexp-instead-of-fields' is nil, then
+ If `comint-use-prompt-regexp' is nil, then
either return the current input field, if point is on an input
field, or the current line, if point is on an output field.
- If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then
+ If `comint-use-prompt-regexp' is non-nil, then
return the current line with any initial string matching the
regexp `comint-prompt-regexp' removed.
`comint-input-filter-functions' monitors input for \"cd\", \"pushd\", and
- \"popd\" commands. When it sees one, it cd's the buffer.
- comint-input-filter is the default: returns t if the input isn't all white
+ \"popd\" commands. When it sees one, it cd's the buffer.
+ `comint-input-filter' is the default: returns t if the input isn't all white
space.
If the Comint is Lucid Common Lisp,
- comint-get-old-input snarfs the sexp ending at point.
- comint-input-filter-functions does nothing.
- comint-input-filter returns nil if the input matches input-filter-regexp,
+ `comint-get-old-input' snarfs the sexp ending at point.
+ `comint-input-filter-functions' does nothing.
+ `comint-input-filter' returns nil if the input matches input-filter-regexp,
which matches (1) all whitespace (2) :a, :c, etc.
Similarly for Soar, Scheme, etc."
(concat input "\n")))
(let ((beg (marker-position pmark))
- (end (if no-newline (point) (1- (point)))))
+ (end (if no-newline (point) (1- (point))))
+ (inhibit-modification-hooks t))
(when (> end beg)
;; Set text-properties for the input field
(add-text-properties
font-lock-face comint-highlight-input
mouse-face highlight
help-echo "mouse-2: insert after prompt as new input"))
- (unless comint-use-prompt-regexp-instead-of-fields
+ (unless comint-use-prompt-regexp
;; Give old user input a field property of `input', to
;; distinguish it from both process output and unsent
;; input. The terminating newline is put into a special
;; `boundary' field to make cursor movement between input
;; and output fields smoother.
(put-text-property beg end 'field 'input)))
- (unless (or no-newline comint-use-prompt-regexp-instead-of-fields)
+ (unless (or no-newline comint-use-prompt-regexp)
;; Cover the terminating newline
(add-text-properties end (1+ end)
'(rear-nonsticky t
(funcall comint-input-sender proc input))
;; Optionally delete echoed input (after checking it).
- (when comint-process-echoes
+ (when (and comint-process-echoes (not artificial))
(let ((echo-len (- comint-last-input-end
comint-last-input-start)))
;; Wait for all input to be echoed:
nil comint-last-input-start comint-last-input-end
nil comint-last-input-end
(+ comint-last-input-end echo-len))))
- (delete-region comint-last-input-end
- (+ comint-last-input-end echo-len)))))
+ ;; Certain parts of the text to be deleted may have
+ ;; been mistaken for prompts. We have to prevent
+ ;; problems when `comint-prompt-read-only' is non-nil.
+ (let ((inhibit-read-only t))
+ (delete-region comint-last-input-end
+ (+ comint-last-input-end echo-len))))))
;; This used to call comint-output-filter-functions,
;; but that scrolled the buffer in undesirable ways.
(defun comint-snapshot-last-prompt ()
"`snapshot' any current `comint-last-prompt-overlay'.
-freeze its attributes in place, even when more input comes a long
+Freeze its attributes in place, even when more input comes along
and moves the prompt overlay."
(when comint-last-prompt-overlay
- (let ((inhibit-read-only t))
+ (let ((inhibit-read-only t)
+ (inhibit-modification-hooks t))
(add-text-properties (overlay-start comint-last-prompt-overlay)
(overlay-end comint-last-prompt-overlay)
(overlay-properties comint-last-prompt-overlay)))))
;; Interpret any carriage motion characters (newline, backspace)
(comint-carriage-motion comint-last-output-start (point)))
+ ;; Run these hooks with point where the user had it.
+ (goto-char saved-point)
(run-hook-with-args 'comint-output-filter-functions string)
+ (set-marker saved-point (point))
(goto-char (process-mark process)) ; in case a filter moved it
- (unless comint-use-prompt-regexp-instead-of-fields
- (let ((inhibit-read-only t))
+ (unless comint-use-prompt-regexp
+ (let ((inhibit-read-only t)
+ (inhibit-modification-hooks t))
(add-text-properties comint-last-output-start (point)
'(rear-nonsticky t
field output
;; Highlight the prompt, where we define `prompt' to mean
;; the most recent output that doesn't end with a newline.
(let ((prompt-start (save-excursion (forward-line 0) (point)))
- (inhibit-read-only t))
+ (inhibit-read-only t)
+ (inhibit-modification-hooks t))
(when comint-prompt-read-only
(or (= (point-min) prompt-start)
(get-text-property (1- prompt-start) 'read-only)
(1- prompt-start) prompt-start 'read-only 'fence))
(add-text-properties
prompt-start (point)
- '(read-only t rear-non-sticky t front-sticky (read-only))))
+ '(read-only t rear-nonsticky t front-sticky (read-only))))
(unless (and (bolp) (null comint-last-prompt-overlay))
;; Need to create or move the prompt overlay (in the case
;; where there is no prompt ((bolp) == t), we still do
(defun comint-preinput-scroll-to-bottom ()
"Go to the end of buffer in all windows showing it.
Movement occurs if point in the selected window is not after the process mark,
-and `this-command' is an insertion command. Insertion commands recognised
+and `this-command' is an insertion command. Insertion commands recognized
are `self-insert-command', `comint-magic-space', `yank', and `hilit-yank'.
Depends on the value of `comint-scroll-to-bottom-on-input'.
(= (point) (point-max)))
(save-excursion
(goto-char (point-max))
- (recenter -1)))
+ (recenter (- -1 scroll-margin))))
(select-window selected)))))
nil t))
(set-buffer current))))
"Put the end of the buffer at the bottom of the window."
(interactive)
(goto-char (point-max))
- (recenter -1))
+ (recenter (- -1 scroll-margin)))
(defun comint-get-old-input-default ()
"Default for `comint-get-old-input'.
-If `comint-use-prompt-regexp-instead-of-fields' is nil, then either
+If `comint-use-prompt-regexp' is nil, then either
return the current input field, if point is on an input field, or the
current line, if point is on an output field.
-If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then return
+If `comint-use-prompt-regexp' is non-nil, then return
the current line with any initial string matching the regexp
`comint-prompt-regexp' removed."
(let ((bof (field-beginning)))
(comint-bol)
(buffer-substring-no-properties (point) (line-end-position)))))
-(defun comint-copy-old-input ()
- "Insert after prompt old input at point as new input to be edited.
-Calls `comint-get-old-input' to get old input."
- (interactive)
- (let ((input (funcall comint-get-old-input))
- (process (get-buffer-process (current-buffer))))
- (if (not process)
- (error "Current buffer has no process")
- (goto-char (process-mark process))
- (insert input))))
-
(defun comint-skip-prompt ()
"Skip past the text matching regexp `comint-prompt-regexp'.
If this takes us past the end of the current line, don't skip at all."
(defun comint-line-beginning-position ()
"Return the buffer position of the beginning of the line, after any prompt.
-If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the
-prompt skip is done by skipping text matching the regular expression
-`comint-prompt-regexp', a buffer local variable."
- (if comint-use-prompt-regexp-instead-of-fields
+If `comint-use-prompt-regexp' is non-nil, then the prompt skip is done by
+skipping text matching the regular expression `comint-prompt-regexp',
+a buffer local variable."
+ (if comint-use-prompt-regexp
;; Use comint-prompt-regexp
(save-excursion
(beginning-of-line)
(defun comint-bol (&optional arg)
"Go to the beginning of line, then skip past the prompt, if any.
If prefix argument is given (\\[universal-argument]) the prompt is not skipped.
-If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then the
-prompt skip is done by skipping text matching the regular expression
-`comint-prompt-regexp', a buffer local variable."
+If `comint-use-prompt-regexp' is non-nil, then the prompt skip is done
+by skipping text matching the regular expression `comint-prompt-regexp',
+a buffer local variable."
(interactive "P")
(if arg
;; Unlike `beginning-of-line', forward-line ignores field boundaries
(forward-line 0)
(goto-char (comint-line-beginning-position))))
+;; For compatibility.
+(defun comint-read-noecho (prompt &optional ignore)
+ (read-passwd prompt))
+
;; These three functions are for entering text you don't want echoed or
;; saved -- typically passwords to ftp, telnet, or somesuch.
-;; Just enter m-x send-invisible and type in your line, or add
-;; `comint-watch-for-password-prompt' to `comint-output-filter-functions'.
-
-(defun comint-read-noecho (prompt &optional stars)
- "Read a single line of text from user without echoing, and return it.
-Prompt with argument PROMPT, a string. Optional argument STARS causes
-input to be echoed with '*' characters on the prompt line. Input ends with
-RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. C-g aborts (if
-`inhibit-quit' is set because e.g. this function was called from a process
-filter and C-g is pressed, this function returns nil rather than a string).
-
-Note that the keystrokes comprising the text can still be recovered
-\(temporarily) with \\[view-lossage]. Some people find this worrisome (see,
-however, `clear-this-command-keys').
-Once the caller uses the password, it can erase the password
-by doing (clear-string STRING)."
- (let ((ans "")
- (newans nil)
- (c 0)
- (echo-keystrokes 0)
- (cursor-in-echo-area t)
- (message-log-max nil)
- (done nil))
- (while (not done)
- (if stars
- (message "%s%s" prompt (make-string (length ans) ?*))
- (message "%s" prompt))
- ;; Use this instead of `read-char' to avoid "Non-character input-event".
- (setq c (read-char-exclusive))
- (cond ((= c ?\C-g)
- ;; This function may get called from a process filter, where
- ;; inhibit-quit is set. In later versions of emacs read-char
- ;; may clear quit-flag itself and return C-g. That would make
- ;; it impossible to quit this loop in a simple way, so
- ;; re-enable it here (for backward-compatibility the check for
- ;; quit-flag below would still be necessary, so this seems
- ;; like the simplest way to do things).
- (setq quit-flag t
- done t))
- ((or (= c ?\r) (= c ?\n) (= c ?\e))
- (setq done t))
- ((= c ?\C-u)
- (clear-string ans)
- (setq ans ""))
- ((and (/= c ?\b) (/= c ?\177))
- (setq newans (concat ans (char-to-string c)))
- (clear-string ans)
- (setq ans newans))
- ((> (length ans) 0)
- (aset ans (1- (length ans)) 0)
- (setq ans (substring ans 0 -1)))))
- (if quit-flag
- ;; Emulate a true quit, except that we have to return a value.
- (prog1
- (setq quit-flag nil)
- (message "Quit")
- (beep t))
- (message "")
- ans)))
+;; Just enter m-x send-invisible and type in your line.
(defun send-invisible (&optional prompt)
"Read a string without echoing.
Security bug: your string can still be temporarily recovered with
\\[view-lossage]; `clear-this-command-keys' can fix that."
(interactive "P") ; Defeat snooping via C-x ESC ESC
- (let ((proc (get-buffer-process (current-buffer))))
+ (let ((proc (get-buffer-process (current-buffer)))
+ (prefix
+ (if (eq (window-buffer (selected-window)) (current-buffer))
+ ""
+ (format "(In buffer %s) "
+ (current-buffer)))))
(if proc
- (let ((str (comint-read-noecho (or prompt "Non-echoed text: ") t)))
+ (let ((str (read-passwd (concat prefix
+ (or prompt "Non-echoed text: ")))))
(if (stringp str)
(progn
(comint-snapshot-last-prompt)
(funcall comint-input-sender proc str))
(message "Warning: text will be echoed")))
- (error "Current buffer has no process"))))
+ (error "Buffer %s has no process" (current-buffer)))))
(defun comint-watch-for-password-prompt (string)
"Prompt in the minibuffer for password and send without echoing.
(delete-region pmark (point))))
;; Output message and put back prompt
(comint-output-filter proc replacement)))
-(defalias 'comint-kill-output 'comint-delete-output)
-(make-obsolete 'comint-kill-output 'comint-delete-output "21.1")
+(define-obsolete-function-alias 'comint-kill-output
+ 'comint-delete-output "21.1")
(defun comint-write-output (filename &optional append mustbenew)
"Write output from interpreter since last input to FILENAME.
(interactive)
(push-mark)
(let ((pos (or (marker-position comint-last-input-end) (point-max))))
- (cond (comint-use-prompt-regexp-instead-of-fields
+ (cond (comint-use-prompt-regexp
(goto-char pos)
(beginning-of-line 0)
(set-window-start (selected-window) (point))
between the process mark and point.
WARNING: if there is no current subjob, you can end up suspending
-the top-level process running in the buffer. If you accidentally do
-this, use \\[comint-continue-subjob] to resume the process. (This
+the top-level process running in the buffer. If you accidentally do
+this, use \\[comint-continue-subjob] to resume the process. (This
is not a problem with most shells, since they ignore this signal.)"
(interactive)
(comint-skip-input)
This means mark it as if it had been sent as input, without sending it."
(let ((comint-input-sender 'ignore)
(comint-input-filter-functions nil))
- (comint-send-input t))
+ (comint-send-input t t))
(end-of-line)
(let ((pos (point))
(marker (process-mark (get-buffer-process (current-buffer)))))
(defun comint-send-eof ()
"Send an EOF to the current buffer's process."
(interactive)
- (comint-send-input t)
+ (comint-send-input t t)
(process-send-eof))
(defun comint-backward-matching-input (regexp n)
"Search backward through buffer for input fields that match REGEXP.
-If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then input
-fields are identified by lines that match `comint-prompt-regexp'.
+If `comint-use-prompt-regexp' is non-nil, then input fields are identified
+by lines that match `comint-prompt-regexp'.
With prefix argument N, search for Nth previous match.
If N is negative, find the next or Nth next match."
(interactive (comint-regexp-arg "Backward input matching (regexp): "))
- (if comint-use-prompt-regexp-instead-of-fields
+ (if comint-use-prompt-regexp
;; Use comint-prompt-regexp
(let* ((re (concat comint-prompt-regexp ".*" regexp))
(pos (save-excursion (end-of-line (if (> n 0) 0 1))
(goto-char pos))))
-(defun comint-forward-matching-input (regexp arg)
+(defun comint-forward-matching-input (regexp n)
"Search forward through buffer for input fields that match REGEXP.
-If `comint-use-prompt-regexp-instead-of-fields' is non-nil, then input
-fields are identified by lines that match `comint-prompt-regexp'.
+If `comint-use-prompt-regexp' is non-nil, then input fields are identified
+by lines that match `comint-prompt-regexp'.
With prefix argument N, search for Nth following match.
If N is negative, find the previous or Nth previous match."
(interactive (comint-regexp-arg "Forward input matching (regexp): "))
- (comint-backward-matching-input regexp (- arg)))
+ (comint-backward-matching-input regexp (- n)))
(defun comint-next-prompt (n)
"Move to end of Nth next prompt in the buffer.
-If `comint-use-prompt-regexp-instead-of-fields' is nil, then this means
-the beginning of the Nth next `input' field, otherwise, it means the Nth
-occurrence of text matching `comint-prompt-regexp'."
+If `comint-use-prompt-regexp' is nil, then this means the beginning of
+the Nth next `input' field, otherwise, it means the Nth occurrence of
+text matching `comint-prompt-regexp'."
(interactive "p")
- (if comint-use-prompt-regexp-instead-of-fields
+ (if comint-use-prompt-regexp
;; Use comint-prompt-regexp
(let ((paragraph-start comint-prompt-regexp))
(end-of-line (if (> n 0) 1 0))
(defun comint-previous-prompt (n)
"Move to end of Nth previous prompt in the buffer.
-If `comint-use-prompt-regexp-instead-of-fields' is nil, then this means
-the beginning of the Nth previous `input' field, otherwise, it means the Nth
-occurrence of text matching `comint-prompt-regexp'."
+If `comint-use-prompt-regexp' is nil, then this means the beginning of
+the Nth previous `input' field, otherwise, it means the Nth occurrence of
+text matching `comint-prompt-regexp'."
(interactive "p")
(comint-next-prompt (- n)))
If the character after point does not have a front-sticky
read-only property, any read-only property of `fence' on the
preceding newline is removed."
- (let* ((pt (point)) (lst (get-text-property pt 'front-sticky)))
+ (let* ((pt (point)) (lst (get-text-property pt 'front-sticky))
+ (inhibit-modification-hooks t))
(and (bolp)
(not (bobp))
(if (and (get-text-property pt 'read-only)
"Kill current line, ignoring read-only and field properties.
With prefix arg, kill that many lines starting from the current line.
If arg is negative, kill backward. Also kill the preceding newline,
-instead of the trailing one. \(This is meant to make C-x z work well
+instead of the trailing one. \(This is meant to make \\[repeat] work well
with negative arguments.)
If arg is zero, kill current line but exclude the trailing newline.
The read-only status of newlines is updated with `comint-update-fence',
(defun comint-source-default (previous-dir/file source-modes)
"Compute the defaults for `load-file' and `compile-file' commands.
-PREVIOUS-DIR/FILE is a pair (directory . filename) from the last
-source-file processing command. nil if there hasn't been one yet.
+PREVIOUS-DIR/FILE is a pair (DIRECTORY . FILENAME) from the last
+source-file processing command, or nil if there hasn't been one yet.
SOURCE-MODES is a list used to determine what buffers contain source
files: if the major mode of the buffer is in SOURCE-MODES, it's source.
Typically, (lisp-mode) or (scheme-mode).
the command has been run (PREVIOUS-DIR/FILE is nil), the default directory
is the cwd, with no default file. (\"no default file\" = nil)
-SOURCE-REGEXP is typically going to be something like (tea-mode)
+SOURCE-MODES is typically going to be something like (tea-mode)
for T programs, (lisp-mode) for Lisp programs, (soar-mode lisp-mode)
for Soar programs, etc.
(set-buffer old-buffer)))))
(defun comint-extract-string ()
- "Return string around POINT, or nil."
+ "Return string around point, or nil."
(let ((syntax (syntax-ppss)))
(when (nth 3 syntax)
(condition-case ()
See `comint-source-default' for more on determining defaults.
-PROMPT is the prompt string. PREV-DIR/FILE is the (directory . file) pair
+PROMPT is the prompt string. PREV-DIR/FILE is the (DIRECTORY . FILE) pair
from the last source processing command. SOURCE-MODES is a list of major
modes used to determine what file buffers contain source files. (These
-two arguments are used for determining defaults). If MUSTMATCH-P is true,
+two arguments are used for determining defaults.) If MUSTMATCH-P is true,
then the filename reader will only accept a file that exists.
A typical use:
:type '(repeat (string :tag "Suffix"))
:group 'comint-completion)
+;;;###autoload
(defvar comint-file-name-prefix ""
"Prefix prepended to absolute file names taken from process input.
This is used by Comint's and shell's completion functions, and by shell's
(defun comint-word (word-chars)
"Return the word of WORD-CHARS at point, or nil if none is found.
Word constituents are considered to be those in WORD-CHARS, which is like the
-inside of a \"[...]\" (see `skip-chars-forward'),
-plus all non-ASCII characters."
+inside of a \"[...]\" (see `skip-chars-forward'), plus all non-ASCII characters."
(save-excursion
(let ((here (point))
giveup)
(defun comint-replace-by-expanded-filename ()
"Dynamically expand and complete the filename at point.
-Replace the filename with an expanded, canonicalised and completed replacement.
+Replace the filename with an expanded, canonicalized and completed replacement.
\"Expanded\" means environment variables (e.g., $HOME) and `~'s are replaced
-with the corresponding directories. \"Canonicalised\" means `..' and `.' are
+with the corresponding directories. \"Canonicalized\" means `..' and `.' are
removed, and the filename is made absolute instead of relative. For expansion
see `expand-file-name' and `substitute-in-file-name'. For completion see
`comint-dynamic-complete-filename'."
;; Read the next key, to process SPC.
(let (key first)
- (if (save-excursion
- (set-buffer (get-buffer "*Completions*"))
- (set (make-local-variable
- 'comint-displayed-dynamic-completions)
+ (if (with-current-buffer (get-buffer "*Completions*")
+ (set (make-local-variable 'comint-displayed-dynamic-completions)
completions)
(setq key (read-key-sequence nil)
first (aref key 0))
(progn
(mouse-choose-completion first)
(set-window-configuration comint-dynamic-list-completions-config))
- (unless (eq first ?\ )
+ (unless (eq first ?\s)
(setq unread-command-events (listify-key-sequence key)))
(unless (eq first ?\t)
(set-window-configuration comint-dynamic-list-completions-config))))))
;; appropriate magic default by examining what we think is the prompt)?
;;
;; Fixme: look for appropriate fields, rather than regexp, if
-;; `comint-use-prompt-regexp-instead-of-fields' is true.
+;; `comint-use-prompt-regexp' is true.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables
;; (make-local-variable 'shell-directory-stack)
;; (setq shell-directory-stack nil)
;; (add-hook 'comint-input-filter-functions 'shell-directory-tracker)
-;; (run-hooks 'shell-mode-hook))
+;; (run-mode-hooks 'shell-mode-hook))
;;
;;
;; Completion for comint-mode users
(provide 'comint)
-;;; arch-tag: 1793314c-09db-40be-9549-9aeae3e75164
+;; arch-tag: 1793314c-09db-40be-9549-9aeae3e75164
;;; comint.el ends here