all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: npostavs@users.sourceforge.net
To: 26355@debbugs.gnu.org
Subject: bug#26355: 26.0.50; find-library doesn't handle load-history entries with nil FILE-NAME
Date: Mon, 03 Apr 2017 21:27:31 -0400	[thread overview]
Message-ID: <87efx9vu64.fsf@users.sourceforge.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 231 bytes --]

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pathc --]
[-- Type: text/x-diff, Size: 3308 bytes --]

From bbd991199206e9d23170d47e0ae2bfb616ba6fff Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@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


             reply	other threads:[~2017-04-04  1:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-04  1:27 npostavs [this message]
2017-04-18 12:07 ` bug#26355: 26.0.50; find-library doesn't handle load-history entries with nil FILE-NAME npostavs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87efx9vu64.fsf@users.sourceforge.net \
    --to=npostavs@users.sourceforge.net \
    --cc=26355@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.