]> code.delx.au - gnu-emacs/blobdiff - lisp/complete.el
(Custom-set, Custom-save, Custom-reset-current)
[gnu-emacs] / lisp / complete.el
index d897c78afa164ddf475d26d5efc5840027a5a4dc..5b77c72ff0176bf8a01abc1ab5bed98364ffd293 100644 (file)
@@ -1,10 +1,9 @@
 ;;; complete.el --- partial completion mechanism plus other goodies
 
-;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1991, 1992, 1993, 1999 Free Software Foundation, Inc.
 
 ;; Author: Dave Gillespie <daveg@synaptics.com>
-;; Keywords: abbrev
-;; Version: 2.03
+;; Keywords: abbrev convenience
 ;; Special thanks to Hallvard Furuseth for his many ideas and contributions.
 
 ;; This file is part of GNU Emacs.
 ;; The regular M-TAB (lisp-complete-symbol) command also supports
 ;; partial completion in this package.
 
-;; This package also contains a wildcard feature for C-x C-f (find-file).
-;; For example, `C-x C-f *.c RET' loads all .c files at once, exactly
-;; as if you had typed C-x C-f separately for each file.  Completion
-;; is supported in connection with wildcards.  Currently only the `*'
-;; wildcard character works.
-
 ;; File name completion does not do partial completion of directories
 ;; on the path, e.g., "/u/b/f" will not complete to "/usr/bin/foo",
 ;; but you can put *'s in the path to accomplish this:  "/u*/b*/f".
 (defgroup partial-completion nil
   "Partial Completion of items."
   :prefix "pc-"
-  :group 'minibuffer)
+  :group 'minibuffer
+  :group 'convenience)
 
 (defcustom partial-completion-mode nil
   "Toggle Partial Completion mode.
@@ -109,7 +103,8 @@ When Partial Completion mode is enabled, TAB (or M-TAB if `PC-meta-flag' is
 nil) is enhanced so that if some string is divided into words and each word is
 delimited by a character in `PC-word-delimiters', partial words are completed
 as much as possible and `*' characters are treated likewise in file names.
-You must modify via \\[customize] for this variable to have an effect."
+This variable should be set only with \\[customize], which is equivalent
+to using the function `partial-completion-mode'."
   :set (lambda (symbol value)
         (partial-completion-mode (or value 0)))
   :initialize 'custom-initialize-default
@@ -127,7 +122,7 @@ If non-nil and non-t, the first character is taken literally only for file name
 completion."
   :type '(choice (const :tag "delimiter" nil)
                 (const :tag "literal" t)
-                (sexp :tag "find-file" :format "%t\n" find-file))
+                (other :tag "find-file" find-file))
   :group 'partial-completion)
 
 (defcustom PC-meta-flag t
@@ -153,11 +148,6 @@ If nil, means use the colon-separated path in the variable $INCPATH instead."
   :type '(repeat directory)
   :group 'partial-completion)
 
-(defcustom PC-disable-wildcards nil
-  "*If non-nil, wildcard support in \\[find-file] is disabled."
-  :type 'boolean
-  :group 'partial-completion)
-
 (defcustom PC-disable-includes nil
   "*If non-nil, include-file support in \\[find-file] is disabled."
   :type 'boolean
@@ -178,16 +168,11 @@ nil) is enhanced so that if some string is divided into words and each word is
 delimited by a character in `PC-word-delimiters', partial words are completed
 as much as possible.
 
-For example, M-x p-c-b expands to M-x partial-completion-mode since no other
+For example, M-x p-c-m expands to M-x partial-completion-mode since no other
 command begins with that sequence of characters, and
 \\[find-file] f_b.c TAB might complete to foo_bar.c if that file existed and no
 other file in that directory begin with that sequence of characters.
 
-Unless `PC-disable-wildcards' is non-nil, the \"*\" wildcard is interpreted
-specially when entering file or directory names.  For example,
-\\[find-file] *.c RET finds each C file in the currenty directory, and
-\\[find-file] */foo_bar.c TAB completes the directory name as far as possible.
-
 Unless `PC-disable-includes' is non-nil, the \"<...>\" sequence is interpreted
 specially in \\[find-file].  For example,
 \\[find-file] <sys/time.h> RET finds the file /usr/include/sys/time.h.
@@ -198,11 +183,6 @@ See also the variable `PC-include-file-path'."
                (not partial-completion-mode))))
     ;; Deal with key bindings...
     (PC-bindings on-p)
-    ;; Deal with wildcard file feature...
-    (cond ((not on-p)
-          (remove-hook 'find-file-not-found-hooks 'PC-try-load-many-files))
-         ((not PC-disable-wildcards)
-          (add-hook 'find-file-not-found-hooks 'PC-try-load-many-files)))
     ;; Deal with include file feature...
     (cond ((not on-p)
           (remove-hook 'find-file-not-found-hooks 'PC-look-for-include-file))
@@ -346,7 +326,7 @@ See `PC-complete' for details."
     (PC-do-complete-and-exit)))
 
 (defun PC-do-complete-and-exit ()
-  (if (= (buffer-size) 0)  ; Duplicate the "bug" that Info-menu relies on...
+  (if (= (point-max) (minibuffer-prompt-end))  ; Duplicate the "bug" that Info-menu relies on...
       (exit-minibuffer)
     (let ((flag (PC-do-completion 'exit)))
       (and flag
@@ -390,7 +370,7 @@ 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 beg (setq beg (minibuffer-prompt-end)))
   (or end (setq end (point-max)))
   (let* ((table minibuffer-completion-table)
         (pred minibuffer-completion-predicate)
@@ -466,7 +446,11 @@ of `minibuffer-completion-table' and the minibuffer contents.")
              (setq basestr (substring str incname)
                    dirname (substring str 0 incname))
            (setq basestr (file-name-nondirectory str)
-                 dirname (file-name-directory str)))
+                 dirname (file-name-directory str))
+           ;; Make sure str is consistent with its directory and basename
+           ;; parts.  This is important on DOZe'NT systems when str only
+           ;; includes a drive letter, like in "d:".
+           (setq str (concat dirname basestr)))
        (setq basestr str))
 
       ;; Convert search pattern to a standard regular expression
@@ -561,10 +545,12 @@ of `minibuffer-completion-table' and the minibuffer contents.")
                                  "\\|")
                                 "\\)\\'")))
 
-              ;; Check if there are any without an ignored extension
+              ;; Check if there are any without an ignored extension.
+              ;; Also ignore `.' and `..'.
               (setq p nil)
               (while p2
                 (or (string-match PC-ignored-regexp (car p2))
+                    (string-match "\\(\\`\\|/\\)[.][.]?/?\\'" (car p2))
                     (setq p (cons (car p2) p)))
                 (setq p2 (cdr p2)))
 
@@ -660,7 +646,7 @@ of `minibuffer-completion-table' and the minibuffer contents.")
 
                  ;; We changed it... enough to be complete?
                  (and (eq mode 'exit)
-                      (PC-is-complete-p (buffer-string) table pred))
+                      (PC-is-complete-p (field-string) table pred))
 
                ;; If totally ambiguous, display a list of completions
                (if (or completion-auto-help
@@ -767,58 +753,8 @@ or properties are considered."
         (PC-not-minibuffer t))
     (PC-do-completion nil beg end)))
 
-
-;;; Wildcards in `C-x C-f' command.  This is independent from the main
-;;; completion code, except for `PC-expand-many-files' which is called
-;;; when "*"'s are found in the path during filename completion.  (The
-;;; above completion code always understands "*"'s, except in file paths,
-;;; without relying on the following code.)
-
-(defvar PC-many-files-list nil)
-
-(defun PC-try-load-many-files ()
-  (if (string-match "\\*" buffer-file-name)
-      (let* ((pat buffer-file-name)
-            (files (PC-expand-many-files pat))
-            (first (car files))
-            (next (reverse (cdr files))))
-       (kill-buffer (current-buffer))
-       (or files
-           (error "No matching files"))
-       ;; Bring the other files (not the first) into buffers.
-       (save-window-excursion
-         (while next
-           (let ((buf (find-file-noselect (car next))))
-             ;; Put this buffer at the front of the buffer list.
-             (switch-to-buffer buf))
-           (setq next (cdr next))))
-       ;; 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))
-       (if (cdr files)
-           (setq PC-many-files-list (mapconcat
-                                     (if (string-match "\\*.*/" pat)
-                                         'identity
-                                       'file-name-nondirectory)
-                                     (cdr files) ", ")
-                 find-file-hooks (cons 'PC-after-load-many-files
-                                       find-file-hooks)))
-       ;; This modifies the "error" variable inside find-file-noselect.
-       (setq error nil)
-       t)
-    nil))
-
-(defun PC-after-load-many-files ()
-  (setq find-file-hooks (delq 'PC-after-load-many-files find-file-hooks))
-  (message "Also loaded %s." PC-many-files-list))
+;;; Use the shell to do globbing.
+;;; This could now use file-expand-wildcards instead.
 
 (defun PC-expand-many-files (name)
   (save-excursion
@@ -910,7 +846,7 @@ or properties are considered."
                       default-directory)))
            (if (file-exists-p (concat dir name))
                (setq name (concat dir name))
-             (error "No such include file: \"%s\"" name))))
+             (error "No such include file: `%s'" name))))
        (setq new-buf (get-file-buffer name))
        (if new-buf
            ;; no need to verify last-modified time for this!
@@ -919,9 +855,8 @@ or properties are considered."
          (set-buffer new-buf)
          (erase-buffer)
          (insert-file-contents name t))
-       (setq filename name
-             error nil
-             buf new-buf)
+       ;; Returning non-nil with the new buffer current
+       ;; is sufficient to tell find-file to use it.
        t)
     nil))