From e2609e4ae9e058bd8be6239681b2f22195628f28 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Tue, 1 Oct 2019 01:09:06 +0100 Subject: Handle byte-compiled functions bound to keys Fixes #212 --- CHANGELOG.md | 2 ++ helpful.el | 11 ++++++++--- test/helpful-unit-test.el | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5432d85..fef5657 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Show the original value for custom variables whose value has changed. Report the package version when custom variables were added. +Fixed a crash on assigning byte-compiled objects to keybindings. + # v0.17 Fixed a minor docstring formatting issue when keymap references were diff --git a/helpful.el b/helpful.el index 1cff11b..7a71f4e 100644 --- a/helpful.el +++ b/helpful.el @@ -2373,9 +2373,14 @@ For example, \"(some-func FOO &optional BAR)\"." (gethash (symbol-function sym) advertised-signature-table)))) ;; Get the usage from the function definition. (let* ((function-args - (if (symbolp sym) - (help-function-arglist sym) - (cadr sym))) + (cond + ((symbolp sym) + (help-function-arglist sym)) + ((byte-code-function-p sym) + (aref sym 0)) + (t + ;; Interpreted function (lambda ...) + (cadr sym)))) (formatted-args (cond (advertised-args diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el index 14d44dc..596bd8c 100644 --- a/test/helpful-unit-test.el +++ b/test/helpful-unit-test.el @@ -533,6 +533,20 @@ associated a lambda with a keybinding." (with-current-buffer buf (helpful-update)))) +(ert-deftest helpful--unnamed-compiled-func () + "Ensure we handle unnamed byte-compiled functions. + +This is important for `helpful-key', where a user may have +associated a lambda with a keybinding." + (let* ((fun (byte-compile (lambda (x) x))) + (buf (helpful--buffer fun t))) + ;; There's no name, so just show lambda in the buffer name. + (should + (equal (buffer-name buf) "*helpful lambda*")) + ;; Don't crash when we show the buffer. + (with-current-buffer buf + (helpful-update)))) + (ert-deftest helpful--obsolete-variable () "Test display of obsolete variable." (let* ((var 'helpful-test-var-obsolete) -- cgit v1.0