commit c795c6be03c0a06352a42b1257a0532149171799 parent 23f5d27619540bf7b8ffa09a1f81d387d7e4eef0 Author: Wilfred Hughes <me@wilfred.me.uk> Date: Sat, 26 Aug 2017 21:00:08 +0100 Gracefully fail if we can't find variable definitions Diffstat:
| M | helpful.el | | | 7 | ++++--- |
| M | test/unit-test.el | | | 8 | ++++++++ |
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/helpful.el b/helpful.el @@ -307,10 +307,11 @@ If the source code cannot be found, return the sexp used." ;; If it's defined interactively, it may have an edebug property ;; that tells us where it's defined. (-when-let (marker (get sym 'edebug)) - (cons (marker-buffer marker) - (marker-position marker))))) + (setq buf-and-pos + (cons (marker-buffer marker) + (marker-position marker)))))) (when (not callable-p) - (let ((filename (find-lisp-object-file-name sym 'defvar))) + (-when-let (filename (find-lisp-object-file-name sym 'defvar)) (setq buf-and-pos (find-variable-noselect sym filename)))) buf-and-pos)) diff --git a/test/unit-test.el b/test/unit-test.el @@ -93,3 +93,11 @@ (should (not (get-text-property m-position 'button formatted))) ;; But we should always remove the backticks. (should (equal formatted "foo messagexxx.")))) + +(setq helpful-var-without-defvar 'foo) + +(ert-deftest helpful--definition () + "Ensure we don't crash on calling `helpful--definition' on +variables defined without `defvar'." + (helpful--definition 'helpful-var-without-defvar nil)) +