]> code.delx.au - gnu-emacs/blobdiff - lisp/complete.el
(describe-mouse-briefly): Fix message spelling.
[gnu-emacs] / lisp / complete.el
index 03709c9a23a8dd81f59873567d5690042048dfd6..3230524e730f7f43d381677f37a4159f66042468 100644 (file)
@@ -1,8 +1,9 @@
-;; complete.el -- partial completion mechanism plus other goodies.
+;;; complete.el -- partial completion mechanism plus other goodies
 
 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
 
 ;; Author: Dave Gillespie <daveg@synaptics.com>
+;; Keywords: abbrev
 ;; Version: 2.02
 ;; Special thanks to Hallvard Furuseth for his many ideas and contributions.
 
@@ -22,7 +23,7 @@
 ;; along with GNU Emacs; see the file COPYING.  If not, write to
 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 
-;; Commentary:
+;;; Commentary:
 
 ;; Extended completion for the Emacs minibuffer.
 ;;
@@ -94,7 +95,7 @@
 ;; is supported in include file names.
 
 
-;; Code:
+;;; Code:
 
 (defvar PC-meta-flag t
   "*If nil, TAB does normal Emacs completion and M-TAB does Partial Completion.
@@ -109,7 +110,7 @@ Some arcane rules:  If `]' is in this string it must come first.
 If `^' is in this string it must NOT come first.  If `-' is in this
 string, it must come first or right after `]'.  In other words, if
 S is this string, then `[S]' must be a legal Emacs regular expression
-(not containing character ranges like `a-z').")
+\(not containing character ranges like `a-z').")
 
 
 (defvar PC-first-char 'x
@@ -228,7 +229,7 @@ See `PC-complete' for details."
           (if (or (eq flag 'complete)
                   (not minibuffer-completion-confirm))
               (exit-minibuffer)
-            (PC-temp-minibuffer-message " (Confirm)"))))))
+            (PC-temp-minibuffer-message " [Confirm]"))))))
 
 
 (defun PC-completion-help ()
@@ -263,6 +264,7 @@ See `PC-complete' for details."
         (filename (memq table '(read-file-name-internal
                                 read-directory-name-internal)))
         (dirname nil)
+        dirlength
         (str (buffer-substring beg end))
         (incname (and filename (string-match "<\\([^\"<>]*\\)>?$" str)))
         (ambig nil)
@@ -278,6 +280,13 @@ See `PC-complete' for details."
             (PC-is-complete-p str table pred))
        'complete
 
+      ;; Record how many characters at the beginning are not included
+      ;; in completion.
+      (setq dirlength
+           (if filename
+               (length (file-name-directory str))
+             0))
+
       ;; Do substitutions in directory names
       (and filename
           (not (equal str (setq p (substitute-in-file-name str))))
@@ -392,10 +401,10 @@ See `PC-complete' for details."
              (PC-do-completion 'word))
          (beep)
          (PC-temp-minibuffer-message (if ambig
-                                         " (Ambiguous dir name)"
+                                         " [Ambiguous dir name]"
                                        (if (eq mode 'help)
-                                           " (No completions)"
-                                         " (No match)")))
+                                           " [No completions]"
+                                         " [No match]")))
          nil))
 
        ;; More than one valid completion found
@@ -433,12 +442,12 @@ See `PC-complete' for details."
        (while (and p
                    (not (equal (car p) basestr)))
          (setq p (cdr p)))
-       (if p
-
-           (progn
-             (if (null mode)
-                 (PC-temp-minibuffer-message " (Complete, but not unique)"))
-             t)
+       (and p (null mode)
+            (PC-temp-minibuffer-message " [Complete, but not unique]"))
+       (if (and p
+                (not (and (null mode)
+                          (eq this-command last-command))))
+           t
 
          ;; If ambiguous, try for a partial completion
          (let ((improved nil)
@@ -475,7 +484,8 @@ See `PC-complete' for details."
                                             (delete-char 1)
                                             (setq end (1- end))))
                                      (setq improved t))
-                                   (insert (substring prefix i (1+ i)))
+                                   ;; Use format to discard text properties.
+                                   (insert (format "%s" (substring prefix i (1+ i))))
                                    (setq end (1+ end)))
                                  (setq i (1+ i)))
                                (or pt (equal (point) beg)
@@ -522,20 +532,27 @@ See `PC-complete' for details."
                ;; If totally ambiguous, display a list of completions
                (if (or completion-auto-help
                        (eq mode 'help))
-                   (with-output-to-temp-buffer " *Completions*"
-                     (display-completion-list (sort helpposs 'string-lessp)))
-                 (PC-temp-minibuffer-message " (Next char not unique)"))
+                   (with-output-to-temp-buffer "*Completions*"
+                     (display-completion-list (sort helpposs 'string-lessp))
+                     (save-excursion
+                       (set-buffer standard-output)
+                       ;; Record which part of the buffer we are completing
+                       ;; so that choosing a completion from the list
+                       ;; knows how much old text to replace.
+                       (setq completion-base-size dirlength)))
+                 (PC-temp-minibuffer-message " [Next char not unique]"))
                nil)))))
 
        ;; Only one possible completion
        (t
        (if (equal basestr (car poss))
            (if (null mode)
-               (PC-temp-minibuffer-message " (Sole completion)"))
+               (PC-temp-minibuffer-message " [Sole completion]"))
          (delete-region beg end)
-         (insert (if filename
-                     (substitute-in-file-name (concat dirname (car poss)))
-                   (car poss))))
+         (insert (format "%s"
+                         (if filename
+                             (substitute-in-file-name (concat dirname (car poss)))
+                           (car poss)))))
        t)))))