aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2017-12-10 20:05:41 +0000
committerWilfred Hughes <me@wilfred.me.uk>2017-12-10 20:05:41 +0000
commit910675601f39075ea1069bb136fcd13e0cd2fbe2 (patch)
treec7e7c3ed40f89e3aa1f59ae31a432e54eca10e2f
parent2c8044f377378fade7dbc613a605f608bca3c97f (diff)
Ensure that we handle interactively defined functions
Also add a test
-rw-r--r--helpful.el9
-rw-r--r--test/unit-test.el5
2 files changed, 10 insertions, 4 deletions
diff --git a/helpful.el b/helpful.el
index b69c509..11676da 100644
--- 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
index 88602d3..cf50f35 100644
--- 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)