]> code.delx.au - gnu-emacs/blobdiff - lisp/comint.el
* simple.el (minibuffer-default): Add defvar.
[gnu-emacs] / lisp / comint.el
index 68745dcb4af59da1e6338013575fd42147bfc38c..d8a4a032ad964c320c703147facc1d9ff8dcdfb5 100644 (file)
@@ -1,7 +1,8 @@
 ;;; comint.el --- general command interpreter in a window stuff
 
 ;; Copyright (C) 1988, 1990, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
+;;   Free Software Foundation, Inc.
 
 ;; Author: Olin Shivers <shivers@cs.cmu.edu>
 ;;     Simon Marshall <simon@gnu.org>
@@ -206,7 +207,7 @@ For shells, a good value is (?\\| ?& ?< ?> ?\\( ?\\) ?;).
 This is a good thing to set in mode hooks.")
 
 (defcustom comint-input-autoexpand nil
-  "*If non-nil, expand input command history references on completion.
+  "If non-nil, expand input command history references on completion.
 This mirrors the optional behavior of tcsh (its autoexpand and histlist).
 
 If the value is `input', then the expansion is seen on input.
@@ -233,7 +234,7 @@ This variable is buffer-local."
   :group 'comint)
 
 (defcustom comint-input-ignoredups nil
-  "*If non-nil, don't add input matching the last on the input ring.
+  "If non-nil, don't add input matching the last on the input ring.
 This mirrors the optional behavior of bash.
 
 This variable is buffer-local."
@@ -241,7 +242,7 @@ This variable is buffer-local."
   :group 'comint)
 
 (defcustom comint-input-ring-file-name nil
-  "*If non-nil, name of the file to read/write input history.
+  "If non-nil, name of the file to read/write input history.
 See also `comint-read-input-ring' and `comint-write-input-ring'.
 
 This variable is buffer-local, and is a good thing to set in mode hooks."
@@ -250,7 +251,7 @@ This variable is buffer-local, and is a good thing to set in mode hooks."
   :group 'comint)
 
 (defcustom comint-scroll-to-bottom-on-input nil
-  "*Controls whether input to interpreter causes window to scroll.
+  "Controls whether input to interpreter causes window to scroll.
 If nil, then do not scroll.  If t or `all', scroll all windows showing buffer.
 If `this', scroll only the selected window.
 
@@ -264,7 +265,7 @@ See `comint-preinput-scroll-to-bottom'.  This variable is buffer-local."
   :group 'comint)
 
 (defcustom comint-move-point-for-output nil
-  "*Controls whether interpreter output moves point to the end of the output.
+  "Controls whether interpreter output moves point to the end of the output.
 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.
@@ -286,7 +287,7 @@ This variable is buffer-local in all Comint buffers."
 (defvaralias 'comint-scroll-to-bottom-on-output 'comint-move-point-for-output)
 
 (defcustom comint-scroll-show-maximum-output t
-  "*Controls how to scroll due to interpreter output.
+  "Controls how to scroll due to interpreter output.
 This variable applies when point is at the end of the buffer
 \(either because it was originally there, or because
 `comint-move-point-for-output' said to move it there)
@@ -303,7 +304,7 @@ This variable is buffer-local in all Comint buffers."
   :group 'comint)
 
 (defcustom comint-buffer-maximum-size 1024
-  "*The maximum size in lines for Comint buffers.
+  "The maximum size in lines for Comint buffers.
 Comint buffers are truncated from the top to be no greater than this number, if
 the function `comint-truncate-buffer' is on `comint-output-filter-functions'."
   :type 'integer
@@ -319,7 +320,7 @@ the function `comint-truncate-buffer' is on `comint-output-filter-functions'."
   "Regexp for history entries that should be ignored when Comint initializes.")
 
 (defcustom comint-process-echoes nil
-  "*If non-nil, assume that the subprocess echoes any input.
+  "If non-nil, assume that the subprocess echoes any input.
 If so, delete one copy of the input so that only one copy eventually
 appears in the buffer.
 
@@ -341,7 +342,7 @@ Kerberos \\|CVS \\|UNIX \\| SMB \\|LDAP \\|\\[sudo] \\|^\\)\
 \[Pp]assword\\( (again)\\)?\\|\
 pass phrase\\|\\(Enter \\|Repeat \\|Bad \\)?[Pp]assphrase\\)\
 \\(?:, try again\\)?\\(?: for [^:]+\\)?:\\s *\\'"
-  "*Regexp matching prompts for passwords in the inferior process.
+  "Regexp matching prompts for passwords in the inferior process.
 This is used by `comint-watch-for-password-prompt'."
   :type 'regexp
   :group 'comint)
@@ -400,7 +401,7 @@ massage the input string, put a different function here.
 This is called from the user command `comint-send-input'.")
 
 (defcustom comint-eol-on-send t
-  "*Non-nil means go to the end of the line before sending input.
+  "Non-nil means go to the end of the line before sending input.
 See `comint-send-input'."
   :type 'boolean
   :group 'comint)
@@ -409,7 +410,7 @@ See `comint-send-input'."
 ;; entirely, searching for uses of this variable will help to identify
 ;; places that need attention.
 (defcustom comint-use-prompt-regexp nil
-  "*If non-nil, use `comint-prompt-regexp' to recognize prompts.
+  "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 `beginning-of-line'
@@ -555,7 +556,7 @@ This is to work around a bug in Emacs process signaling.")
   "Index of last matched history element.")
 (defvar comint-matching-input-from-input-string ""
   "Input previously used to match input history.")
-(defvar comint-save-input-ring-index
+(defvar comint-save-input-ring-index nil
   "Last input ring index which you copied.
 This is to support the command \\[comint-get-next-from-history].")
 
@@ -618,6 +619,7 @@ to continue it.
 
 Entry to this mode runs the hooks on `comint-mode-hook'."
   (setq mode-line-process '(":%s"))
+  (set (make-local-variable 'window-point-insertion-type) t)
   (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))
@@ -1739,12 +1741,8 @@ Make backspaces delete the previous character."
 
        ;; Insert STRING
        (let ((inhibit-read-only t)
-             ;; Avoid the overhead of save-excursion, since we just
-             ;; fiddle with the point
-             (saved-point (point-marker)))
-
-         ;; The point should float after any insertion we do
-         (set-marker-insertion-type saved-point t)
+              ;; The point should float after any insertion we do.
+             (saved-point (copy-marker (point) t)))
 
          ;; We temporarly remove any buffer narrowing, in case the
          ;; process mark is outside of the restriction
@@ -1755,48 +1753,9 @@ Make backspaces delete the previous character."
            (set-marker comint-last-output-start (point))
 
            ;; insert-before-markers is a bad thing. XXX
-           ;;
-           ;; It is used here to force window-point markers (used to
-           ;; store the value of point in non-selected windows) to
-           ;; advance, but it also screws up any other markers that we
-           ;; don't _want_ to advance, such as the start-marker of some
-           ;; of the overlays we create.
-           ;;
-           ;; We work around the problem with the overlays by
-           ;; explicitly adjusting them after we do the insertion, but
-           ;; in the future this problem should be solved correctly, by
-           ;; using `insert', and making the insertion-type of
-           ;; window-point markers settable (via a buffer-local
-           ;; variable).  In comint buffers, this variable would be set
-           ;; to `t', to cause point in non-select windows to advance.
-           (insert-before-markers string)
-           ;; Fixup markers and overlays that got screwed up because we
-           ;; used `insert-before-markers'.
-           (let ((old-point (- (point) (length string))))
-             ;; comint-last-output-start
-             (set-marker comint-last-output-start old-point)
-             ;; comint-last-input-end
-             (when (and comint-last-input-end
-                        (equal (marker-position comint-last-input-end)
-                               (point)))
-               (set-marker comint-last-input-end old-point))
-             ;; No overlays we create are set to advance upon insertion
-             ;; (at the start/end), so we assume that any overlay which
-             ;; is at the current point was incorrectly advanced by
-             ;; insert-before-markers.  First fixup overlays that might
-             ;; start at point:
-             (dolist (over (overlays-at (point)))
-               (when (= (overlay-start over) (point))
-                 (let ((end (overlay-end over)))
-                   (move-overlay over
-                                 old-point
-                                 (if (= end (point)) old-point end)))))
-             ;; Then do overlays that might end at point:
-             (dolist (over (overlays-at (1- (point))))
-               (when (= (overlay-end over) (point))
-                 (move-overlay over
-                               (min (overlay-start over) old-point)
-                               old-point))))
+           ;; Luckily we don't have to use it any more, we use
+           ;; window-point-insertion-type instead.
+           (insert string)
 
            ;; Advance process-mark
            (set-marker (process-mark process) (point))
@@ -1816,7 +1775,9 @@ Make backspaces delete the previous character."
               (let ((inhibit-read-only t)
                    (inhibit-modification-hooks t))
                 (add-text-properties comint-last-output-start (point)
-                                     '(rear-nonsticky t
+                                     '(front-sticky
+                                      (field inhibit-line-move-field-capture)
+                                      rear-nonsticky t
                                       field output
                                       inhibit-line-move-field-capture t))))
 
@@ -2165,11 +2126,7 @@ Sets mark to the value of point when this command is run."
           (set-window-start (selected-window) (point))
           (comint-skip-prompt))
          (t
-          (let* ((beg (field-beginning pos))
-                 (pt (if (= (point-min) beg)
-                         (point-min)
-                       (1+ beg))))
-            (goto-char pt))
+          (goto-char (field-beginning pos))
           (set-window-start (selected-window) (point))))))
 
 
@@ -2671,13 +2628,13 @@ its response can be seen."
 ;; want them present in specific modes.
 
 (defcustom comint-completion-autolist nil
-  "*If non-nil, automatically list possibilities on partial completion.
+  "If non-nil, automatically list possibilities on partial completion.
 This mirrors the optional behavior of tcsh."
   :type 'boolean
   :group 'comint-completion)
 
 (defcustom comint-completion-addsuffix t
-  "*If non-nil, add a `/' to completed directories, ` ' to file names.
+  "If non-nil, add a `/' to completed directories, ` ' to file names.
 If a cons pair, it should be of the form (DIRSUFFIX . FILESUFFIX) where
 DIRSUFFIX and FILESUFFIX are strings added on unambiguous or exact completion.
 This mirrors the optional behavior of tcsh."
@@ -2689,7 +2646,7 @@ This mirrors the optional behavior of tcsh."
   :group 'comint-completion)
 
 (defcustom comint-completion-recexact nil
-  "*If non-nil, use shortest completion if characters cannot be added.
+  "If non-nil, use shortest completion if characters cannot be added.
 This mirrors the optional behavior of tcsh.
 
 A non-nil value is useful if `comint-completion-autolist' is non-nil too."
@@ -2697,7 +2654,7 @@ A non-nil value is useful if `comint-completion-autolist' is non-nil too."
   :group 'comint-completion)
 
 (defcustom comint-completion-fignore nil
-  "*List of suffixes to be disregarded during file completion.
+  "List of suffixes to be disregarded during file completion.
 This mirrors the optional behavior of bash and tcsh.
 
 Note that this applies to `comint-dynamic-complete-filename' only."
@@ -2863,7 +2820,10 @@ See `comint-dynamic-complete-filename'.  Returns t if successful."
                            " ")
                           (t
                            (cdr comint-completion-addsuffix))))
-        (filename (or (comint-match-partial-filename) ""))
+        (filename (comint-match-partial-filename))
+        (filename-beg (if filename (match-beginning 0) (point)))
+        (filename-end (if filename (match-end 0) (point)))
+        (filename (or filename ""))
         (filedir (file-name-directory filename))
         (filenondir (file-name-nondirectory filename))
         (directory (if filedir (comint-directory filedir) default-directory))
@@ -2881,9 +2841,12 @@ See `comint-dynamic-complete-filename'.  Returns t if successful."
           (comint-dynamic-list-filename-completions))
          (t                            ; Completion string returned.
           (let ((file (concat (file-name-as-directory directory) completion)))
-            (insert (comint-quote-filename
-                     (substring (directory-file-name completion)
-                                (length filenondir))))
+            ;; Insert completion.  Note that the completion string
+            ;; may have a different case than what's in the prompt,
+            ;; if read-file-name-completion-ignore-case is non-nil,
+            (delete-region filename-beg filename-end)
+            (if filedir (insert (comint-quote-filename filedir)))
+            (insert (comint-quote-filename (directory-file-name completion)))
             (cond ((symbolp (file-name-completion completion directory))
                    ;; We inserted a unique completion.
                    (insert (if (file-directory-p file) dirsuffix filesuffix))
@@ -2997,7 +2960,7 @@ See also `comint-dynamic-complete-filename'."
          (message "No completions of %s" filename))
       (comint-dynamic-list-completions
        (mapcar 'comint-quote-filename completions)
-       filenondir))))
+       (comint-quote-filename filenondir)))))
 
 
 ;; This is bound locally in a *Completions* buffer to the list of
@@ -3172,7 +3135,7 @@ the process mark is at the beginning of the accumulated input."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (defcustom comint-redirect-verbose nil
-  "*If non-nil, print messages each time the redirection filter is invoked.
+  "If non-nil, print messages each time the redirection filter is invoked.
 Also print a message when redirection is completed."
   :group 'comint
   :type 'boolean)