helpful

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

commit 7e4b1f0d5572a4e2b8ee7a9b084ef863d0315a73
parent 716c116d6a9fafb16a5b1e6be5dbd8e82f357c7e
Author: Dario Gjorgjevski <dario.gjorgjevski+git@gmail.com>
Date:   Tue,  2 Feb 2021 17:54:44 +0100

Prevent error in helpful-variable if sexp at point can't be read

How to reproduce from emacs -Q in the *scratch* buffer:

0. If needed, do `(package-initialize)` and `(require 'helpful)`.
1. Type `(something some-undefined-variable|` where | represents
   point.  (Note that there is no closing parenthesis!)
2. Call helpful-variable.

This will give you an `End of file during parsing` from
`helpful--variable-defined-at-point` because the sexp at point can't
be read due to the missing parenthesis.  This commit suppresses the
error

Fix #251
Close #254

Diffstat:
MCHANGELOG.md | 3+++
Mhelpful.el | 4+++-
Mtest/helpful-unit-test.el | 12++++++++++++
3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -5,6 +5,9 @@ been loaded by the autoloader (#179, #191). Fixed issue with displaying circular data structures. +Fixed a crash in `helpful-variable` in files that weren't +syntactically valid lisp. + # v0.18 Show the original value for custom variables whose value has changed. diff --git a/helpful.el b/helpful.el @@ -2738,7 +2738,9 @@ See also `helpful-callable' and `helpful-variable'." sexp) (when sexp-start (goto-char sexp-start) - (setq sexp (read (current-buffer))) + (setq sexp (condition-case nil + (read (current-buffer)) + (error nil))) (when (memq (car-safe sexp) (list 'defvar 'defvar-local 'defcustom 'defconst)) (nth 1 sexp))))))) diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el @@ -133,6 +133,18 @@ bar"))) (helpful-function #'test-foo-defined-interactively) (should (equal (buffer-name) "*helpful function: test-foo-defined-interactively*")))) +(ert-deftest helpful--variable-defined-at-point () + ;; The happy case with valid code. + (with-temp-buffer + (insert "(defvar foo nil)") + (goto-char (1+ (point-min))) + (should (eq (helpful--variable-defined-at-point) 'foo))) + ;; Ensure we don't crash if the source code isn't valid. + (with-temp-buffer + (insert "(defvar foo nil") + (goto-char (1+ (point-min))) + (helpful--variable-defined-at-point))) + (ert-deftest helpful--edebug-fn () "We should not crash on a function with edebug enabled." (let ((edebug-all-forms t)