GNU bug report logs - #26355
26.0.50; find-library doesn't handle load-history entries with nil FILE-NAME

Previous Next

Package: emacs;

Reported by: npostavs <at> users.sourceforge.net

Date: Tue, 4 Apr 2017 01:27:02 UTC

Severity: minor

Tags: fixed, patch

Found in version 26.0.50

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 26355 in the body.
You can then email your comments to 26355 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#26355; Package emacs. (Tue, 04 Apr 2017 01:27:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to npostavs <at> users.sourceforge.net:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 04 Apr 2017 01:27:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: bug-gnu-emacs <at> gnu.org
Subject: 26.0.50;
 find-library doesn't handle load-history entries with nil FILE-NAME
Date: Mon, 03 Apr 2017 21:27:31 -0400
[Message part 1 (text/plain, inline)]
Severiy: minor
Tags: patch

emacs -Q

Insert (defun foo ()) and C-M-x on it.
M-x find-library blah RET gives "Wrong type argument: stringp, nil"
Expected "find-library-name: Can’t find library blah"

Here is a patch.

[v1-0001-Let-find-library-name-handle-load-history-entries.patch (text/x-diff, inline)]
From bbd991199206e9d23170d47e0ae2bfb616ba6fff Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Sat, 25 Mar 2017 22:41:34 -0400
Subject: [PATCH v1] Let find-library-name handle load-history entries with nil
 file-name

* lisp/emacs-lisp/find-func.el (find-library--from-load-history):
Rename from find-library--from-load-path.  Check for `load-history'
entries with nil FILE-NAMEs.  Simplify by not double checking for
suffixes and making use of `locate-file'.
---
 lisp/emacs-lisp/find-func.el | 48 ++++++++++++--------------------------------
 1 file changed, 13 insertions(+), 35 deletions(-)

diff --git a/lisp/emacs-lisp/find-func.el b/lisp/emacs-lisp/find-func.el
index 6699e3fd2b..d0acc14775 100644
--- a/lisp/emacs-lisp/find-func.el
+++ b/lisp/emacs-lisp/find-func.el
@@ -43,7 +43,7 @@
 
 ;;; Code:
 
-(require 'seq)
+(eval-when-compile (require 'cl-lib))
 
 ;;; User variables:
 
@@ -203,43 +203,21 @@ find-library-name
           (locate-file rel
                        (or find-function-source-path load-path)
                        load-file-rep-suffixes)))))
-   (find-library--from-load-path library)
+   (find-library--from-load-history library)
    (error "Can't find library %s" library)))
 
-(defun find-library--from-load-path (library)
+(defun find-library--from-load-history (library)
   ;; In `load-history', the file may be ".elc", ".el", ".el.gz", and
-  ;; LIBRARY may be "foo.el" or "foo", so make sure that we get all
-  ;; potential matches, and then see whether any of them lead us to an
-  ;; ".el" or an ".el.gz" file.
-  (let* ((elc-regexp "\\.el\\(c\\(\\..*\\)?\\)\\'")
-         (suffix-regexp
-          (concat "\\("
-                  (mapconcat 'regexp-quote (find-library-suffixes) "\\'\\|")
-                  "\\|" elc-regexp "\\)\\'"))
-         (potentials
-          (mapcar
-           (lambda (entry)
-             (if (string-match suffix-regexp (car entry))
-                 (replace-match "" t t (car entry))
-               (car entry)))
-           (seq-filter
-            (lambda (entry)
-              (string-match
-               (concat "\\`"
-                       (regexp-quote
-                        (replace-regexp-in-string suffix-regexp "" library))
-                       suffix-regexp)
-               (file-name-nondirectory (car entry))))
-            load-history)))
-         result)
-    (dolist (file potentials)
-      (dolist (suffix (find-library-suffixes))
-        (when (not result)
-          (cond ((file-exists-p file)
-                 (setq result file))
-                ((file-exists-p (concat file suffix))
-                 (setq result (concat file suffix)))))))
-    result))
+  ;; LIBRARY may be "foo.el" or "foo".
+  (let ((load-re
+         (concat "\\(" (regexp-quote (file-name-sans-extension library)) "\\)"
+                 (regexp-opt (get-load-suffixes)) "\\'")))
+    (cl-loop
+     for (file . _) in load-history thereis
+     (and (stringp file) (string-match load-re file)
+          (let ((dir (substring file 0 (match-beginning 1)))
+                (basename (match-string 1 file)))
+            (locate-file basename (list dir) (find-library-suffixes)))))))
 
 (defvar find-function-C-source-directory
   (let ((dir (expand-file-name "src" source-directory)))
-- 
2.11.1


Severity set to 'minor' from 'normal' Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Tue, 04 Apr 2017 01:30:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#26355; Package emacs. (Tue, 18 Apr 2017 12:07:02 GMT) Full text and rfc822 format available.

Message #10 received at 26355 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: 26355 <at> debbugs.gnu.org
Subject: Re: bug#26355: 26.0.50;
 find-library doesn't handle load-history entries with nil FILE-NAME
Date: Tue, 18 Apr 2017 08:07:41 -0400
tags 26355 fixed
close 26355 
quit

npostavs <at> users.sourceforge.net writes:

> emacs -Q
>
> Insert (defun foo ()) and C-M-x on it.
> M-x find-library blah RET gives "Wrong type argument: stringp, nil"
> Expected "find-library-name: Can’t find library blah"
>
> Here is a patch.

Pushed to master [1: 861824dbec].

1: 2017-04-18 07:54:28 -0400 861824dbecc96339c68b1e15008a21c31e04721b
  Fix find-library-name for load-history entries with nil FILE-NAME (Bug#26355)




Added tag(s) fixed. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Tue, 18 Apr 2017 12:07:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 26355 <at> debbugs.gnu.org and npostavs <at> users.sourceforge.net Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Tue, 18 Apr 2017 12:07:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 17 May 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 32 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.