helpful

a fork of Wilfred's helpful
git clone https://git.trogloxene.org/helpful.git
Log | Files | Refs | README

commit e2609e4ae9e058bd8be6239681b2f22195628f28
parent 3b0f42e77d05cf38a90a34dca76600df800d02b7
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Tue,  1 Oct 2019 01:09:06 +0100

Handle byte-compiled functions bound to keys

Fixes #212

Diffstat:
MCHANGELOG.md | 2++
Mhelpful.el | 11++++++++---
Mtest/helpful-unit-test.el | 14++++++++++++++
3 files changed, 24 insertions(+), 3 deletions(-)

diff --git 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 @@ -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 @@ -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)