Subject: Re: bug#17467: 24.3; locate-library returning spurious path

From: Alex Kosorukoff <[email-masked]>
Date: Sun, 11 May 2014 21:36:22 -0700

I like the idea of optimizing out the second string-match, though that
variant matched tramp.el.old which is not a valid library name. Here is a
modifed version using the same idea except it skips files like tramp.el.old.

# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: [email-masked]
# target_branch: :parent
# testament_sha1: 330ab5b4527e49ea46d8d16a6d47e5822247ce77
# timestamp: 2014-05-11 21:23:50 -0700
# base_revision_id: [email-masked]\
#   1mzcrftziwhrw9hl
#
# Begin patch
=== modified file 'lisp/subr.el'
--- lisp/subr.el        2014-04-09 01:48:07 +0000
+++ lisp/subr.el        2014-05-12 04:22:18 +0000
@@ -1857,10 +1857,14 @@
                                        load-path (get-load-suffixes)))
                     nil nil
                     t))
-  (let ((file (locate-file library
-                          (or path load-path)
-                          (append (unless nosuffix (get-load-suffixes))
-                                  load-file-rep-suffixes))))
+  (let ((file
+         (locate-file
+          library
+          (or path load-path)
+          (unless nosuffix
+            (if (string-match "\\.elc?\\(\\.gz\\)?\\'" library)
+                (if (= 2 (length (match-data))) load-file-rep-suffixes)
+              (get-load-suffixes))))))
     (if interactive-call
        (if file
            (message "Library is file %s" (abbreviate-file-name file))

# Begin bundle

On Sun, May 11, 2014 at 7:18 PM, Stefan Monnier <[email-masked]>wrote:

> > I think these file names are more appropriate for data files, not
> > executable ones.  It is undesirable that a name "tramp.gz" will shadow a
> > valid library file "tramp.elc" that won't be found as a result.
>
> I think I'm beginning to see what you mean.  So far we have simply
> considered "if it hurts, don't do it".  And it worked well enough.
>
> > When you say those names aren't spurious, do you have a particular
> > example of an emacs elisp library in mind which file name ends with
> > a suffix other than .el .elc .el.gz .elc.gz?
>
> There are a few (~/.emacs being the most obvious), but admittedly,
> I think they all share the property of not being searched for in
> load-path.  So we could probably strengthen the search along the lines
> you suggest without (hopefully) breaking existing code with a hack along
> the lines of the one below.
>
>
>         Stefan
>
>
> === modified file 'lisp/subr.el'
> --- lisp/subr.el        2014-04-15 17:03:15 +0000
> +++ lisp/subr.el        2014-05-12 02:15:04 +0000
> @@ -1878,10 +1878,15 @@
>                                         load-path (get-load-suffixes)))
>                      nil nil
>                      t))
> -  (let ((file (locate-file library
> -                          (or path load-path)
> -                          (append (unless nosuffix (get-load-suffixes))
> -                                  load-file-rep-suffixes))))
> +  (let* ((suffixes
> +          (nconc (unless nosuffix (get-load-suffixes))
> +                 (when (or (file-name-absolute-p library)
> +                           ;; (load "foo.el") should find /bar/foo.el.gz,
> +                           ;; but (load "foo") should not find
> /bar/foo.gz.
> +                           (string-match "\\.el\\(\\.[[:alnum:]]+\\)?"
> +                                         library))
> +                   load-file-rep-suffixes)))
> +         (file (locate-file library (or path load-path) suffixes)))
>      (if interactive-call
>         (if file
>             (message "Library is file %s" (abbreviate-file-name file))
>
>