helpful

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

commit a983eb66fd143510107b39d70d280d947e8f7f53
parent ffc16a64b2d594b713580194558cf997c3e5ebad
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sat, 20 Jan 2018 11:49:26 +0000

Ensure we handle edebug info correctly

edebug info may be a marker or a list, ensure we handle both.

Diffstat:
MCHANGELOG.md | 2++
Mhelpful.el | 9++++++---
Mtest/unit-test.el | 16++++++++++++++++
3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -5,6 +5,8 @@ available. Fixed some crashes on primitive functions. +Improved finding source code when edebug info is available. + Better handling of docstrings: * All strings in quotes are highlighted. For example, previously diff --git a/helpful.el b/helpful.el @@ -841,9 +841,12 @@ buffer." (callable-p ;; Functions defined interactively may have an edebug property ;; that contains the location of the definition. - (-when-let (marker (car-safe (get sym 'edebug))) - (setq buf (marker-buffer marker)) - (setq pos (marker-position marker)))) + (-when-let (edebug-info (get sym 'edebug)) + (-let [marker (if (consp edebug-info) + (car edebug-info) + edebug-info)] + (setq buf (marker-buffer marker)) + (setq pos (marker-position marker))))) ((not callable-p) (condition-case _err (-let [(sym-buf . sym-pos) (find-definition-noselect sym 'defvar)] diff --git a/test/unit-test.el b/test/unit-test.el @@ -204,6 +204,22 @@ (message "No Emacs source code found at %S, skipping test. Run ./download_emacs_src.sh" emacs-src-path)))) +(ert-deftest helpful--definition-edebug-fn () + "Ensure we use the position information set by edebug, if present." + ;; Test with both edebug enabled and disabled. The edebug property + ;; on the symbol varies based on this. + (dolist (edebug-on (list nil t)) + (let ((edebug-all-forms edebug-on) + (edebug-all-defs edebug-on)) + (with-temp-buffer + (insert "(defun test-foo-edebug-defn () 44)") + (goto-char (point-min)) + (shut-up + (eval (eval-sexp-add-defvars (edebug-read-top-level-form)) t)) + + (-let [(buf pos opened) (helpful--definition 'test-foo-edebug-defn t)] + (should buf)))))) + (ert-deftest helpful-variable () "Smoke test for `helpful-variable'." (helpful-variable 'tab-width))