Subject: bug#5955: completions in M-x find-library include .elc files

From: Stefan Monnier <[email-masked]>
Date: Mon, 26 Jul 2010 01:58:49 +0200

>>>>> "Stefan" == Stefan Monnier <[email-masked]> writes:

>>>> Typing TAB or ? in M-x find-library shows .el and .elc files when it
>>>> probably should just be the name of the library without the extension.
>>> I added the `push' because in load-library I often want to
>>> select a particular file (i.e. either the .el or the .elc file).
>> Doesn't M-x load-library and specifying no extension load the .elc?

> Usually, yes.

BTW, please try the patch below, to see if you like the
resulting behavior.

        Stefan

=== modified file 'lisp/files.el'
--- lisp/files.el	2010-06-13 19:52:42 +0000
+++ lisp/files.el	2010-07-25 23:57:51 +0000
@@ -777,9 +777,12 @@
                (if x (1- (length x)) (length suffix))))))
    (t
     (let ((names nil)
+          (stripsuffix t)
 	  (suffix (concat (regexp-opt suffixes t) "\\'"))
 	  (string-dir (file-name-directory string))
           (string-file (file-name-nondirectory string)))
+      (while
+          (progn
       (dolist (dir dirs)
 	(unless dir
 	  (setq dir default-directory))
@@ -787,10 +790,15 @@
 	(when (file-directory-p dir)
 	  (dolist (file (file-name-all-completions
 			 string-file dir))
+                  (if (not (string-match suffix file))
 	    (push file names)
-	    (when (string-match suffix file)
+                    (unless stripsuffix (push file names))
 	      (setq file (substring file 0 (match-beginning 0)))
               (push file names)))))
+            ;; Remove duplicates of the first element.
+            (setq names (cons (car names) (delete (car names) (cdr names))))
+            (prog1 (and stripsuffix (= 1 (length names)))
+              (setq stripsuffix nil))))
       (completion-table-with-context
        string-dir names string-file pred action)))))