]> code.delx.au - gnu-emacs/blobdiff - lisp/comint.el
; Fix breakage from previous commit
[gnu-emacs] / lisp / comint.el
index 2c4168474ab90698910e1b56ee13f94c4549d401..88fc0b2d197e737536ab458e6eb769d6c74e01bd 100644 (file)
@@ -1,6 +1,6 @@
 ;;; comint.el --- general command interpreter in a window stuff -*- lexical-binding: t -*-
 
-;; Copyright (C) 1988, 1990, 1992-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1988, 1990, 1992-2016 Free Software Foundation, Inc.
 
 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
 ;;     Simon Marshall <simon@gnu.org>
@@ -184,11 +184,11 @@ 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 init file:
 
-\(add-hook 'comint-mode-hook
-         (lambda ()
-           (define-key comint-mode-map [remap kill-region] 'comint-kill-region)
-           (define-key comint-mode-map [remap kill-whole-line]
-             'comint-kill-whole-line)))
+\(add-hook \\='comint-mode-hook
+          (lambda ()
+            (define-key comint-mode-map [remap kill-region] \\='comint-kill-region)
+            (define-key comint-mode-map [remap kill-whole-line]
+              \\='comint-kill-whole-line)))
 
 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'."
@@ -345,14 +345,15 @@ This variable is buffer-local."
    (regexp-opt
     '("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)
+      "Kerberos" "CVS" "UNIX" " SMB" "LDAP" "[sudo]" "Repeat" "Bad" "Retype")
+    t)
    " +\\)"
    "\\(?:" (regexp-opt password-word-equivalents) "\\|Response\\)"
    "\\(?:\\(?:, try\\)? *again\\| (empty for no passphrase)\\| (again)\\)?\
 \\(?: for [^::៖]+\\)?[::៖]\\s *\\'")
   "Regexp matching prompts for passwords in the inferior process.
 This is used by `comint-watch-for-password-prompt'."
-  :version "24.4"
+  :version "25.2"
   :type 'regexp
   :group 'comint)
 
@@ -816,8 +817,6 @@ series of processes in the same Comint buffer.  The hook
                    (format "COLUMNS=%d" (window-width)))
            (list "TERM=emacs"
                  (format "TERMCAP=emacs:co#%d:tc=unknown:" (window-width))))
-         (unless (getenv "EMACS")
-           (list "EMACS=t"))
          (list (format "INSIDE_EMACS=%s,comint" emacs-version))
          process-environment))
        (default-directory
@@ -1053,7 +1052,7 @@ See also `comint-read-input-ring'."
       (let ((ch (read-event)))
        (if (eq ch ?\s)
            (set-window-configuration conf)
-         (setq unread-command-events (list ch)))))))
+         (push ch unread-command-events))))))
 
 
 (defun comint-regexp-arg (prompt)
@@ -1476,7 +1475,7 @@ Intended to be added to `isearch-mode-hook' in `comint-mode'."
       (or
        ;; 1. First try searching in the initial comint text
        (funcall search-fun string
-               (if isearch-forward bound (field-beginning))
+               (if isearch-forward bound (comint-line-beginning-position))
                noerror)
        ;; 2. If the above search fails, start putting next/prev history
        ;; elements in the comint successively, and search the string
@@ -1492,7 +1491,7 @@ Intended to be added to `isearch-mode-hook' in `comint-mode'."
                        (when (null comint-input-ring-index)
                          (error "End of history; no next item"))
                        (comint-next-input 1)
-                       (goto-char (field-beginning)))
+                       (goto-char (comint-line-beginning-position)))
                       (t
                        ;; Signal an error here explicitly, because
                        ;; `comint-previous-input' doesn't signal an error.
@@ -1510,7 +1509,7 @@ Intended to be added to `isearch-mode-hook' in `comint-mode'."
                                      (unless isearch-forward
                                        ;; For backward search, don't search
                                        ;; in the comint prompt
-                                       (field-beginning))
+                                       (comint-line-beginning-position))
                                      noerror)))
               ;; Return point of the new search result
               (point))
@@ -1534,16 +1533,16 @@ the function `isearch-message'."
     (if (overlayp comint-history-isearch-message-overlay)
        (move-overlay comint-history-isearch-message-overlay
                      (save-excursion
-                       (goto-char (field-beginning))
+                       (goto-char (comint-line-beginning-position))
                        (forward-line 0)
                        (point))
-                      (field-beginning))
+                      (comint-line-beginning-position))
       (setq comint-history-isearch-message-overlay
            (make-overlay (save-excursion
-                           (goto-char (field-beginning))
+                           (goto-char (comint-line-beginning-position))
                            (forward-line 0)
                            (point))
-                          (field-beginning)))
+                          (comint-line-beginning-position)))
       (overlay-put comint-history-isearch-message-overlay 'evaporate t))
     (overlay-put comint-history-isearch-message-overlay
                 'display (isearch-message-prefix ellipsis isearch-nonincremental))
@@ -1564,7 +1563,7 @@ or to the last history element for a backward search."
       (comint-goto-input (1- (ring-length comint-input-ring)))
     (comint-goto-input nil))
   (setq isearch-success t)
-  (goto-char (if isearch-forward (field-beginning) (point-max))))
+  (goto-char (if isearch-forward (comint-line-beginning-position) (point-max))))
 
 (defun comint-history-isearch-push-state ()
   "Save a function restoring the state of input history search.
@@ -1583,7 +1582,7 @@ Go to the history element by the absolute history position HIST-POS."
 (defun comint-within-quotes (beg end)
   "Return t if the number of quotes between BEG and END is odd.
 Quotes are single and double."
-  (let ((countsq (comint-how-many-region "\\(^\\|[^\\\\]\\)\'" beg end))
+  (let ((countsq (comint-how-many-region "\\(^\\|[^\\\\]\\)'" beg end))
        (countdq (comint-how-many-region "\\(^\\|[^\\\\]\\)\"" beg end)))
     (or (= (mod countsq 2) 1) (= (mod countdq 2) 1))))
 
@@ -1788,7 +1787,10 @@ Similarly for Soar, Scheme, etc."
       (widen)
       (let* ((pmark (process-mark proc))
              (intxt (if (>= (point) (marker-position pmark))
-                        (progn (if comint-eol-on-send (goto-char (field-end)))
+                        (progn (if comint-eol-on-send
+                                  (if comint-use-prompt-regexp
+                                      (end-of-line)
+                                    (goto-char (field-end))))
                                (buffer-substring pmark (point)))
                       (let ((copy (funcall comint-get-old-input)))
                         (goto-char pmark)
@@ -1927,10 +1929,10 @@ the start, the cdr to the end of the last prompt recognized.")
 Freezes the `font-lock-face' text property in place."
   (when comint-last-prompt
     (with-silent-modifications
-      (add-text-properties
+      (font-lock-prepend-text-property
        (car comint-last-prompt)
        (cdr comint-last-prompt)
-       '(font-lock-face comint-highlight-prompt)))
+       'font-lock-face 'comint-highlight-prompt))
     ;; Reset comint-last-prompt so later on comint-output-filter does
     ;; not remove the font-lock-face text property of the previous
     ;; (this) prompt.
@@ -2081,14 +2083,19 @@ Make backspaces delete the previous character."
                  (add-text-properties prompt-start (point)
                                       '(read-only t front-sticky (read-only)))))
              (when comint-last-prompt
-               (remove-text-properties (car comint-last-prompt)
-                                       (cdr comint-last-prompt)
-                                       '(font-lock-face)))
+               ;; There might be some keywords here waiting for
+               ;; fontification, so no `with-silent-modifications'.
+               (font-lock--remove-face-from-text-property
+                (car comint-last-prompt)
+                (cdr comint-last-prompt)
+                'font-lock-face
+                'comint-highlight-prompt))
              (setq comint-last-prompt
                    (cons (copy-marker prompt-start) (point-marker)))
-             (add-text-properties prompt-start (point)
-                                  '(rear-nonsticky t
-                                    font-lock-face comint-highlight-prompt)))
+             (font-lock-prepend-text-property prompt-start (point)
+                                              'font-lock-face
+                                              'comint-highlight-prompt)
+             (add-text-properties prompt-start (point) '(rear-nonsticky t)))
            (goto-char saved-point)))))))
 
 (defun comint-preinput-scroll-to-bottom ()
@@ -2219,7 +2226,10 @@ the current line with any initial string matching the regexp
              (null (get-char-property (setq bof (field-beginning)) 'field)))
        (field-string-no-properties bof)
       (comint-bol)
-      (buffer-substring-no-properties (point) (line-end-position)))))
+      (buffer-substring-no-properties (point)
+                                     (if comint-use-prompt-regexp
+                                         (line-end-position)
+                                       (field-end))))))
 
 (defun comint-copy-old-input ()
   "Insert after prompt old input at point as new input to be edited.
@@ -2277,7 +2287,10 @@ a buffer local variable."
     ;; if there are two fields on a line, then the first one is the
     ;; prompt, and the second one is an input field, and is front-sticky
     ;; (as input fields should be).
-    (constrain-to-field (line-beginning-position) (line-end-position))))
+    (constrain-to-field (if (eq (field-at-pos (point)) 'output)
+                            (line-beginning-position)
+                          (field-beginning))
+                        (line-end-position))))
 
 (defun comint-bol (&optional arg)
   "Go to the beginning of line, then skip past the prompt, if any.
@@ -2838,7 +2851,7 @@ then the filename reader will only accept a file that exists.
 
 A typical use:
  (interactive (comint-get-source \"Compile file: \" prev-lisp-dir/file
-                                 '(lisp-mode) t))"
+                                 \\='(lisp-mode) t))"
   (let* ((def (comint-source-default prev-dir/file source-modes))
         (stringfile (comint-extract-string))
         (sfile-p (and stringfile
@@ -3353,7 +3366,8 @@ the completions."
            (set-window-configuration comint-dynamic-list-completions-config))
        (if (eq first ?\s)
            (set-window-configuration comint-dynamic-list-completions-config)
-         (setq unread-command-events (listify-key-sequence key)))))))
+         (setq unread-command-events
+                (nconc (listify-key-sequence key) unread-command-events)))))))
 \f
 (defun comint-get-next-from-history ()
   "After fetching a line from input history, this fetches the following line.