summaryrefslogtreecommitdiff
path: root/lisp/comint.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/comint.el')
-rw-r--r--lisp/comint.el94
1 files changed, 53 insertions, 41 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 57df6bfb19f..7af8e8fd2a5 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -54,7 +54,7 @@
;; instead of shell-mode, see the notes at the end of this file.
-;; Brief Command Documentation:
+;;; Brief Command Documentation:
;;============================================================================
;; Comint Mode Commands: (common to all derived modes, like shell & cmulisp
;; mode)
@@ -104,8 +104,9 @@
(require 'ring)
(require 'ansi-color)
(require 'regexp-opt) ;For regexp-opt-charset.
+(eval-when-compile (require 'subr-x))
-;; Buffer Local Variables:
+;;; Buffer Local Variables:
;;============================================================================
;; Comint mode buffer local variables:
;; comint-prompt-regexp string comint-bol uses to match prompt
@@ -149,10 +150,10 @@
:group 'comint)
;; Unused.
-;;; (defgroup comint-source nil
-;;; "Source finding facilities in comint."
-;;; :prefix "comint-"
-;;; :group 'comint)
+;; (defgroup comint-source nil
+;; "Source finding facilities in comint."
+;; :prefix "comint-"
+;; :group 'comint)
(defvar comint-prompt-regexp "^"
"Regexp to recognize prompts in the inferior process.
@@ -365,23 +366,25 @@ This variable is buffer-local."
;; OpenBSD doas prints "doas (user@host) password:".
;; See ert test `comint-test-password-regexp'.
(defcustom comint-password-prompt-regexp
+ ;; When extending this, please also add a corresponding test where
+ ;; possible (see `comint-testsuite-password-strings').
(concat
"\\(^ *\\|"
(regexp-opt
'("Enter" "enter" "Enter same" "enter same" "Enter the" "enter the"
"Enter Auth" "enter auth" "Old" "old" "New" "new" "'s" "login"
"Kerberos" "CVS" "UNIX" " SMB" "LDAP" "PEM" "SUDO"
- "[sudo]" "doas" "Repeat" "Bad" "Retype")
+ "[sudo]" "doas" "Repeat" "Bad" "Retype" "Verify")
t)
;; Allow for user name to precede password equivalent (Bug#31075).
" +.*\\)"
"\\(?:" (regexp-opt password-word-equivalents) "\\|Response\\)"
"\\(?:\\(?:, try\\)? *again\\| (empty for no passphrase)\\| (again)\\)?"
;; "[[:alpha:]]" used to be "for", which fails to match non-English.
- "\\(?: [[:alpha:]]+ .+\\)?[[:blank:]]*[::៖][[:blank:]]*\\'")
+ "\\(?: [[:alpha:]]+ .+\\)?[[:blank:]]*[::៖][[:space:]]*\\'")
"Regexp matching prompts for passwords in the inferior process.
This is used by `comint-watch-for-password-prompt'."
- :version "27.1"
+ :version "28.1"
:type 'regexp
:group 'comint)
@@ -921,8 +924,8 @@ by the global keymap (usually `mouse-yank-at-click')."
;; Insert the input at point
(insert input)))))
-;; Input history processing in a buffer
-;; ===========================================================================
+;;; Input history processing in a buffer
+;;============================================================================
;; Useful input history functions, courtesy of the Ergo group.
;; Eleven commands:
@@ -1624,7 +1627,6 @@ or to the last history element for a backward search."
(if isearch-forward
(comint-goto-input (1- (ring-length comint-input-ring)))
(comint-goto-input nil))
- (setq isearch-success t)
(goto-char (if isearch-forward (comint-line-beginning-position) (point-max))))
(defun comint-history-isearch-push-state ()
@@ -1795,6 +1797,10 @@ Ignore duplicates if `comint-input-ignoredups' is non-nil."
(min size (- comint-input-ring-size size)))))
(ring-insert comint-input-ring cmd)))
+(defconst comint--prompt-rear-nonsticky
+ '(field inhibit-line-move-field-capture read-only font-lock-face)
+ "Text properties we set on the prompt and don't want to leak past it.")
+
(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
@@ -1914,7 +1920,8 @@ Similarly for Soar, Scheme, etc."
(unless (or no-newline comint-use-prompt-regexp)
;; Cover the terminating newline
(add-text-properties end (1+ end)
- '(rear-nonsticky t
+ `(rear-nonsticky
+ ,comint--prompt-rear-nonsticky
field boundary
inhibit-line-move-field-capture t)))))
@@ -2121,9 +2128,10 @@ Make backspaces delete the previous character."
(unless comint-use-prompt-regexp
(with-silent-modifications
(add-text-properties comint-last-output-start (point)
- '(front-sticky
+ `(rear-nonsticky
+ ,comint--prompt-rear-nonsticky
+ front-sticky
(field inhibit-line-move-field-capture)
- rear-nonsticky t
field output
inhibit-line-move-field-capture t))))
@@ -2149,10 +2157,12 @@ Make backspaces delete the previous character."
'comint-highlight-prompt))
(setq comint-last-prompt
(cons (copy-marker prompt-start) (point-marker)))
- (font-lock-prepend-text-property prompt-start (point)
- 'font-lock-face
- 'comint-highlight-prompt)
- (add-text-properties prompt-start (point) '(rear-nonsticky t)))
+ (font-lock-append-text-property prompt-start (point)
+ 'font-lock-face
+ 'comint-highlight-prompt)
+ (add-text-properties prompt-start (point)
+ `(rear-nonsticky
+ ,comint--prompt-rear-nonsticky)))
(goto-char saved-point)))))))
(defun comint-preinput-scroll-to-bottom ()
@@ -2248,23 +2258,23 @@ This function could be on `comint-output-filter-functions' or bound to a key."
(let ((inhibit-read-only t))
(delete-region (point-min) (point)))))
-(defun comint-strip-ctrl-m (&optional _string)
+(defun comint-strip-ctrl-m (&optional _string interactive)
"Strip trailing `^M' characters from the current output group.
This function could be on `comint-output-filter-functions' or bound to a key."
- (interactive)
+ (interactive (list nil t))
(let ((process (get-buffer-process (current-buffer))))
(if (not process)
;; This function may be used in
;; `comint-output-filter-functions', and in that case, if
;; there's no process, then we should do nothing. If
;; interactive, report an error.
- (when (called-interactively-p 'interactive)
+ (when interactive
(error "No process in the current buffer"))
(let ((pmark (process-mark process)))
(save-excursion
(condition-case nil
(goto-char
- (if (called-interactively-p 'interactive)
+ (if interactive
comint-last-input-end comint-last-output-start))
(error nil))
(while (re-search-forward "\r+$" pmark t)
@@ -2429,13 +2439,12 @@ carriage returns (\\r) in STRING.
This function could be in the list `comint-output-filter-functions'."
(when (let ((case-fold-search t))
(string-match comint-password-prompt-regexp
- (replace-regexp-in-string "\r" "" string)))
- (when (string-match "^[ \n\r\t\v\f\b\a]+" string)
- (setq string (replace-match "" t t string)))
+ (string-replace "\r" "" string)))
(let ((comint--prompt-recursion-depth (1+ comint--prompt-recursion-depth)))
(if (> comint--prompt-recursion-depth 10)
(message "Password prompt recursion too deep")
- (comint-send-invisible string)))))
+ (comint-send-invisible
+ (string-trim string "[ \n\r\t\v\f\b\a]+" "\n+"))))))
;; Low-level process communication
@@ -2462,10 +2471,13 @@ This function could be in the list `comint-output-filter-functions'."
;; Random input hackage
-(defun comint-delete-output ()
+(defun comint-delete-output (&optional kill)
"Delete all output from interpreter since last input.
-Does not delete the prompt."
- (interactive)
+If KILL (interactively, the prefix), save the killed text in the
+kill ring.
+
+This command does not delete the prompt."
+ (interactive "P")
(let ((proc (get-buffer-process (current-buffer)))
(replacement nil)
(inhibit-read-only t))
@@ -2473,6 +2485,8 @@ Does not delete the prompt."
(let ((pmark (progn (goto-char (process-mark proc))
(forward-line 0)
(point-marker))))
+ (when kill
+ (copy-region-as-kill comint-last-input-end pmark))
(delete-region comint-last-input-end pmark)
(goto-char (process-mark proc))
(setq replacement (concat "*** output flushed ***\n"
@@ -2838,7 +2852,7 @@ updated using `comint-update-fence', if necessary."
(kill-region beg end)
(comint-update-fence))))))
-;; Support for source-file processing commands.
+;;; Support for source-file processing commands.
;;============================================================================
;; Many command-interpreters (e.g., Lisp, Scheme, Soar) have
;; commands that process files of source text (e.g. loading or compiling
@@ -2944,7 +2958,7 @@ 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:
- (interactive (comint-get-source \"Compile file: \" prev-lisp-dir/file
+ (interactive (comint-get-source \"Compile file\" prev-lisp-dir/file
\\='(lisp-mode) t))"
(let* ((def (comint-source-default prev-dir/file source-modes))
(stringfile (comint-extract-string))
@@ -2957,9 +2971,7 @@ A typical use:
(car def)))
(deffile (if sfile-p (file-name-nondirectory stringfile)
(cdr def)))
- (ans (read-file-name (if deffile (format "%s(default %s) "
- prompt deffile)
- prompt)
+ (ans (read-file-name (format-prompt prompt deffile)
defdir
(concat defdir deffile)
mustmatch-p)))
@@ -2974,8 +2986,8 @@ A typical use:
;; -Olin
-;; Simple process query facility.
-;; ===========================================================================
+;;; Simple process query facility.
+;;============================================================================
;; This function is for commands that want to send a query to the process
;; and show the response to the user. For example, a command to get the
;; arglist for a Common Lisp function might send a "(arglist 'foo)" query
@@ -3011,8 +3023,8 @@ its response can be seen."
(set-window-point proc-win opoint)))))))
-;; Filename/command/history completion in a buffer
-;; ===========================================================================
+;;; Filename/command/history completion in a buffer
+;;============================================================================
;; Useful completion functions, courtesy of the Ergo group.
;; Six commands:
@@ -3876,8 +3888,8 @@ REGEXP-GROUP is the regular expression group in REGEXP to use."
(forward-line 1)))
(nreverse results))))
-;; Converting process modes to use comint mode
-;; ===========================================================================
+;;; Converting process modes to use comint mode
+;;============================================================================
;; The code in the Emacs 19 distribution has all been modified to use comint
;; where needed. However, there are `third-party' packages out there that
;; still use the old shell mode. Here's a guide to conversion.