]> code.delx.au - gnu-emacs/blobdiff - lisp/complete.el
Add defgroups, and use defcustom.
[gnu-emacs] / lisp / complete.el
index 3230524e730f7f43d381677f37a4159f66042468..c12e2ce95cb66c423aa381c04821a7f383912d0f 100644 (file)
@@ -1,4 +1,4 @@
-;;; 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.
 
@@ -20,8 +20,9 @@
 ;; GNU General Public License for more details.
 
 ;; 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; 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.
 
 ;;; Commentary:
 
@@ -177,7 +178,21 @@ Word-delimiters for the purposes of Partial Completion are \"-\", \"_\",
   (interactive)
   (if (PC-was-meta-key)
       (minibuffer-complete)
-    (PC-do-completion nil)))
+    ;; If the previous command was not this one,
+    ;; never scroll, always retry completion.
+    (or (eq last-command this-command)
+       (setq minibuffer-scroll-window nil))
+    (let ((window minibuffer-scroll-window))
+      ;; If there's a fresh completion window with a live buffer,
+      ;; and this command is repeated, scroll that window.
+      (if (and window (window-buffer window)
+              (buffer-name (window-buffer window)))
+         (save-excursion
+           (set-buffer (window-buffer window))
+           (if (pos-visible-in-window-p (point-max) window)
+               (set-window-start window (point-min) nil)
+             (scroll-other-window)))
+       (PC-do-completion nil)))))
 
 
 (defun PC-complete-word ()
@@ -256,13 +271,21 @@ See `PC-complete' for details."
 (defvar PC-ndelims-regex nil)
 (defvar PC-delims-list nil)
 
+(defvar PC-completion-as-file-name-predicate
+  (function
+   (lambda ()
+     (memq minibuffer-completion-table
+          '(read-file-name-internal read-directory-name-internal))))
+   "A function testing whether a minibuffer completion now will work filename-style.
+The function takes no arguments, and typically looks at the value
+of `minibuffer-completion-table' and the minibuffer contents.")
+
 (defun PC-do-completion (&optional mode beg end)
   (or beg (setq beg (point-min)))
   (or end (setq end (point-max)))
   (let* ((table minibuffer-completion-table)
         (pred minibuffer-completion-predicate)
-        (filename (memq table '(read-file-name-internal
-                                read-directory-name-internal)))
+        (filename (funcall PC-completion-as-file-name-predicate))
         (dirname nil)
         dirlength
         (str (buffer-substring beg end))
@@ -386,7 +409,9 @@ See `PC-complete' for details."
          (setq p compl)
          (while p
            (and (string-match regex (car p))
-                (setq poss (cons (car p) poss)))
+                (progn
+                  (set-text-properties 0 (length (car p)) '() (car p))
+                  (setq poss (cons (car p) poss))))
            (setq p (cdr p)))))
 
       ;; Now we have a list of possible completions
@@ -440,7 +465,7 @@ See `PC-complete' for details."
        ;; Is the actual string one of the possible completions?
        (setq p (and (not (eq mode 'help)) poss))
        (while (and p
-                   (not (equal (car p) basestr)))
+                   (not (string-equal (car p) basestr)))
          (setq p (cdr p)))
        (and p (null mode)
             (PC-temp-minibuffer-message " [Complete, but not unique]"))
@@ -484,8 +509,7 @@ See `PC-complete' for details."
                                             (delete-char 1)
                                             (setq end (1- end))))
                                      (setq improved t))
-                                   ;; Use format to discard text properties.
-                                   (insert (format "%s" (substring prefix i (1+ i))))
+                                   (insert (substring prefix i (1+ i)))
                                    (setq end (1+ end)))
                                  (setq i (1+ i)))
                                (or pt (equal (point) beg)
@@ -652,16 +676,20 @@ or properties are considered."
        (kill-buffer (current-buffer))
        (or files
            (error "No matching files"))
+       ;; Bring the other files (not the first) into buffers.
        (save-window-excursion
          (while (setq next (cdr next))
            (let ((buf (find-file-noselect (car next))))
+             ;; Put this buffer at the front of the buffer list.
              (switch-to-buffer buf))))
-       ;; This modifies the "buf" variable inside find-file-noselect.
+       ;; This modifies the `buf' variable inside find-file-noselect.
        (setq buf (get-file-buffer first))
        (if buf
            nil   ; should do verify-visited-file-modtime stuff.
          (setq filename first)
          (setq buf (create-file-buffer filename))
+         ;; This modified `truename' inside find-file-noselect.
+         (setq truename (abbreviate-file-name (file-truename filename)))
          (set-buffer buf)
          (erase-buffer)
          (insert-file-contents filename t))