From 5d0796faa829aebe7b5f73054e0cfab16b4b0860 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Tue, 22 May 2018 20:23:32 +0100 Subject: Show preceding comments and autoload cookies in source --- CHANGELOG.md | 3 +++ helpful.el | 7 ++++++- test/unit-test.el | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43ca377..def91be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ Fixed an issue with very large code snippets making helpful hang due to slow syntax highlighting. This was particularly problematic for C functions and variables. +When extracting the source for an item, include preceding comments and +autoload cookies. + # v0.9 Much better handling of aliases: show aliases differently to their diff --git a/helpful.el b/helpful.el index feb4bce..aaa7ed4 100644 --- a/helpful.el +++ b/helpful.el @@ -950,7 +950,12 @@ If the source code cannot be found, return the sexp used." (save-excursion (save-restriction (goto-char start-pos) - (narrow-to-defun) + (narrow-to-defun t) + + ;; If there was a preceding comment, START-POS will be + ;; after that comment. Move the position to include that comment. + (setq start-pos (point-min)) + (setq source (buffer-substring-no-properties (point-min) (point-max)))))) (setq source (s-trim-right source)) (when (and source (buffer-file-name buf)) diff --git a/test/unit-test.el b/test/unit-test.el index 910819d..9ccbdfd 100644 --- a/test/unit-test.el +++ b/test/unit-test.el @@ -473,6 +473,12 @@ associated a lambda with a keybinding." (should (s-starts-with-p "(defun " source)))) +(ert-deftest helpful--source-autoloaded () + "We should include the autoload cookie." + (let* ((source (helpful--source #'helpful-at-point t))) + (should + (s-starts-with-p ";;;###autoload" source)))) + (ert-deftest helpful--source--interactively-defined-fn () "We should return the raw sexp for functions where we can't find the source code." -- cgit v1.0