helpful

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

commit 656ff91eb6094bbd5a78dcd6ef1e9ccb4d257a4d
parent 4abe04870467beb8a5a798773e1f145f65298e59
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Fri,  2 Mar 2018 22:22:06 +0000

Fix references to top-level forms

Previoiusly helpful--outer-sexp assumed point was inside a form, so
returned the wrong sexp for top-level forms.

Diffstat:
MCHANGELOG.md | 3+++
Mhelpful.el | 8++++++--
Mtest/unit-test.el | 28++++++++++++++++++++++++++++
3 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -13,6 +13,9 @@ Improved wording for functions with no source at all. Fixed an issue with obsolete aliases without version information. +Fixed an issue with top-level references where we would show the +previous form rather than the relevant one. + # v0.7 Helpful buffers now start with a summary of what you're looking at, diff --git a/helpful.el b/helpful.el @@ -1098,10 +1098,14 @@ from parent keymaps." (defun helpful--outer-sexp (buf pos) "Find position POS in BUF, and return the name of the outer sexp, -along with its position." +along with its position. + +Moves point in BUF." (with-current-buffer buf (goto-char pos) - (beginning-of-defun) + (let* ((ppss (syntax-ppss))) + (unless (zerop (syntax-ppss-depth ppss)) + (beginning-of-defun))) (list (point) (-take 2 (read buf))))) (defun helpful--count-values (items) diff --git a/test/unit-test.el b/test/unit-test.el @@ -366,3 +366,31 @@ associated a lambda with a keybinding." (let* ((source (helpful--source #'helpful--source t))) (should (s-starts-with-p "(defun " source)))) + +(ert-deftest helpful--outer-sexp () + ;; If point is in the middle of a form, we should return its position. + (with-temp-buffer + (insert "(foo bar baz)") + (goto-char (point-min)) + (search-forward "b") + + (-let [(pos subforms) + (helpful--outer-sexp (current-buffer) (point))] + (should + (equal pos (point-min))) + (should + (equal subforms '(foo bar))))) + ;; If point is at the beginning of a form, we should still return its position. + (with-temp-buffer + (insert "(foo) (bar)") + (goto-char (point-min)) + (search-forward "b") + (backward-char 2) + + (-let [(pos subforms) + (save-excursion + (helpful--outer-sexp (current-buffer) (point)))] + (should + (equal pos (point))) + (should + (equal subforms '(bar))))))