commit 0caa886420a3211d153847fd5f1e80bc6677369e
parent a7260fb844924481abf01ac5796354ced084c1f8
Author: Wilfred Hughes <me@wilfred.me.uk>
Date: Sat, 28 Jul 2018 19:05:54 +0100
Fix an issue with detecting autoloaded core Emacs functions
Diffstat:
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
@@ -10,6 +10,9 @@ functions.
Helpful now shows keybindings for aliases of the current command too.
+Fixed an issue where functions defined in .el.gz files were not
+recognised as being autoloaded.
+
# v0.12
Added a 'pretty view' for string values, keymap values, and hooks.
diff --git a/helpful.el b/helpful.el
@@ -1565,6 +1565,17 @@ OBJ may be a symbol or a compiled function object."
'symbol sym
'source source))
+;; TODO: this only reports if a function is autoloaded because we
+;; autoloaded it. This ignores newly defined functions that are
+;; autoloaded. Built-in help has this limitation too, but if we can
+;; find the source, we should instead see if there's an autoload
+;; cookie.
+(defun helpful--autoloaded-p (sym buf)
+ "Return non-nil if function SYM is autoloaded."
+ (-when-let (file-name (buffer-file-name buf))
+ (setq file-name (s-chop-suffix ".gz" file-name))
+ (help-fns--autoloaded-p sym file-name)))
+
(defun helpful--summary (sym callable-p buf pos)
"Return a one sentence summary for SYM."
(-let* ((primitive-p (helpful--primitive-p sym callable-p))
@@ -1603,14 +1614,8 @@ OBJ may be a symbol or a compiled function object."
"buffer-local"
'helpful-info-button
'info-node "(elisp)Buffer-Local Variables"))
- ;; TODO: this only reports if a function is autoloaded
- ;; because we autoloaded it. This ignores newly defined
- ;; functions that are autoloaded. Built-in help has this
- ;; limitation too, but if we can find the source, we should
- ;; instead see if there's an autoload cookie.
(autoloaded-p
- (if (and callable-p buf (buffer-file-name buf))
- (help-fns--autoloaded-p sym (buffer-file-name buf))))
+ (and callable-p buf (helpful--autoloaded-p sym buf)))
(description
(cond
(alias-p
diff --git a/test/unit-test.el b/test/unit-test.el
@@ -769,3 +769,9 @@ find the source code."
(insert button)
(goto-char (point-min))
(push-button))))
+
+(ert-deftest helpful--autoloaded-p ()
+ (-let [(buf pos opened) (helpful--definition 'rx-to-string t)]
+ (should (helpful--autoloaded-p 'rx-to-string buf))
+ (when opened
+ (kill-buffer buf))))