aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2017-12-31 01:09:18 +0000
committerWilfred Hughes <me@wilfred.me.uk>2017-12-31 01:20:06 +0000
commitf4301765a9b4a44ce732e3118036acb48c51f94a (patch)
treef5ffa0fe6bb9a9891dd42ae602d5a1bb847bdde6
parentc1fa68fa092201353d3666040c1e89bd31720227 (diff)
Add imenu support
Fixes #24. This is much inspired by the sample code given by @xenodium in issue #36. Thanks! :)
-rw-r--r--CHANGELOG.md2
-rw-r--r--helpful.el23
2 files changed, 24 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4537037..86d0ca1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
# v0.6
+Added imenu support! You can now navigate between headings with imenu.
+
Helpful now correctly handles \= escapes in docstrings.
Added disassemble buttons to byte-code functions in symbol properties.
diff --git a/helpful.el b/helpful.el
index c3f46a9..4eed109 100644
--- a/helpful.el
+++ b/helpful.el
@@ -1389,9 +1389,30 @@ See also `helpful-callable' and `helpful-variable'."
(helpful-symbol symbol)
(user-error "There is no symbol at point.")))
+(defun helpful--imenu-index ()
+ "Return a list of headings in the current buffer, suitable for
+imenu."
+ (let (headings)
+ (goto-char (point-min))
+ (while (not (eobp))
+ (when (eq (get-text-property (point) 'face)
+ 'helpful-heading)
+ (push
+ (cons
+ (buffer-substring-no-properties
+ (line-beginning-position) (line-end-position))
+ (line-beginning-position))
+ headings))
+ (forward-line))
+ (nreverse headings)))
+
(define-derived-mode helpful-mode special-mode "Helpful"
"Major mode for *Helpful* buffers."
- (add-hook 'xref-backend-functions #'elisp--xref-backend nil t))
+ (add-hook 'xref-backend-functions #'elisp--xref-backend nil t)
+
+ (setq imenu-create-index-function #'helpful--imenu-index)
+ ;; Prevent imenu converting "Source Code" to "Source.Code".
+ (setq-local imenu-space-replacement " "))
(defun helpful-visit-reference ()
"Go to the reference at point."