commit 910675601f39075ea1069bb136fcd13e0cd2fbe2 parent 2c8044f377378fade7dbc613a605f608bca3c97f Author: Wilfred Hughes <me@wilfred.me.uk> Date: Sun, 10 Dec 2017 20:05:41 +0000 Ensure that we handle interactively defined functions Also add a test Diffstat:
| M | helpful.el | | | 9 | +++++---- |
| M | test/unit-test.el | | | 5 | +++++ |
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/helpful.el b/helpful.el @@ -400,10 +400,11 @@ for killing the newly created buffer." ;; ;; Narrowing has been fixed upstream: ;; http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=abd18254aec76b26e86ae27e91d2c916ec20cc46 - (-let* (((base-sym . path) (find-function-library sym)) - (src-buf (find-file-noselect path))) - (with-current-buffer src-buf - ;; Ignore the current narrowing and point position in `src-buf'. + (-when-let ((base-sym . path) (find-function-library sym)) + ;; Open `path' ourselves. If the user has already opened it, + ;; we ensure that we don't change their narrowing or point + ;; position when we search it. + (with-current-buffer (find-file-noselect path) (save-excursion (save-restriction (widen) diff --git a/test/unit-test.el b/test/unit-test.el @@ -40,6 +40,11 @@ "We should not crash on a function without a docstring." (should (null (helpful--docstring #'test-foo-no-docstring t)))) +(ert-deftest helpful--interacively-defined-fn () + "We should not crash on a function without source code." + (eval '(defun test-foo-defined-interactively () 42)) + (helpful-function #'test-foo-defined-interactively)) + (defun test-foo-usage-docstring () "\n\n(fn &rest ARGS)" nil)