emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r101141: * lisp/files.el (locate-file


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r101141: * lisp/files.el (locate-file-completion-table): Only list the .el and .elc
Date: Thu, 19 Aug 2010 23:21:21 +0200
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 101141
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Thu 2010-08-19 23:21:21 +0200
message:
  * lisp/files.el (locate-file-completion-table): Only list the .el and .elc
  extensions if there's no other choice.
modified:
  lisp/ChangeLog
  lisp/files.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-08-19 15:43:45 +0000
+++ b/lisp/ChangeLog    2010-08-19 21:21:21 +0000
@@ -1,5 +1,8 @@
 2010-08-19  Stefan Monnier  <address@hidden>
 
+       * files.el (locate-file-completion-table): Only list the .el and .elc
+       extensions if there's no other choice (bug#5955).
+
        * facemenu.el (facemenu-self-insert-data): New var.
        (facemenu-post-self-insert-function, facemenu-set-self-insert-face):
        New functions.

=== modified file 'lisp/files.el'
--- a/lisp/files.el     2010-07-31 15:46:58 +0000
+++ b/lisp/files.el     2010-08-19 21:21:21 +0000
@@ -757,21 +757,44 @@
              (let ((x (file-name-directory suffix)))
                (if x (1- (length x)) (length suffix))))))
    (t
-    (let ((names nil)
+    (let ((names '())
+          ;; If we have files like "foo.el" and "foo.elc", we could load one of
+          ;; them with "foo.el", "foo.elc", or "foo", where just "foo" is the
+          ;; preferred way.  So if we list all 3, that gives a lot of redundant
+          ;; entries for the poor soul looking just for "foo".  OTOH, sometimes
+          ;; the user does want to pay attention to the extension.  We try to
+          ;; diffuse this tension by stripping the suffix, except when the
+          ;; result is a single element (i.e. usually we only list "foo" unless
+          ;; it's the only remaining element in the list, in which case we do
+          ;; list "foo", "foo.elc" and "foo.el").
+          (fullnames '())
          (suffix (concat (regexp-opt suffixes t) "\\'"))
          (string-dir (file-name-directory string))
           (string-file (file-name-nondirectory string)))
       (dolist (dir dirs)
-       (unless dir
-         (setq dir default-directory))
-       (if string-dir (setq dir (expand-file-name string-dir dir)))
-       (when (file-directory-p dir)
-         (dolist (file (file-name-all-completions
-                        string-file dir))
-           (push file names)
-           (when (string-match suffix file)
-             (setq file (substring file 0 (match-beginning 0)))
-              (push file names)))))
+        (unless dir
+          (setq dir default-directory))
+        (if string-dir (setq dir (expand-file-name string-dir dir)))
+        (when (file-directory-p dir)
+          (dolist (file (file-name-all-completions
+                         string-file dir))
+            (if (not (string-match suffix file))
+                (push file names)
+              (push file fullnames)
+              (push (substring file 0 (match-beginning 0)) names)))))
+      ;; Switching from names to names+fullnames creates a non-monotonicity
+      ;; which can cause problems with things like partial-completion.
+      ;; To minimize the problem, filter out completion-regexp-list, so that
+      ;; M-x load-library RET t/x.e TAB finds some files.
+      (if completion-regexp-list
+          (setq names (all-completions "" names)))
+      ;; Remove duplicates of the first element, so that we can easily check
+      ;; if `names' really only contains a single element.
+      (when (cdr names) (setcdr names (delete (car names) (cdr names))))
+      (unless (cdr names)
+        ;; There's no more than one matching non-suffixed element, so expand
+        ;; the list by adding the suffixed elements as well.
+        (setq names (nconc names fullnames)))
       (completion-table-with-context
        string-dir names string-file pred action)))))
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]