helpful

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

commit f4301765a9b4a44ce732e3118036acb48c51f94a
parent c1fa68fa092201353d3666040c1e89bd31720227
Author: Wilfred Hughes <me@wilfred.me.uk>
Date:   Sun, 31 Dec 2017 01:09:18 +0000

Add imenu support

Fixes #24.

This is much inspired by the sample code given by @xenodium in
issue #36. Thanks! :)

Diffstat:
MCHANGELOG.md | 2++
Mhelpful.el | 23++++++++++++++++++++++-
2 files changed, 24 insertions(+), 1 deletion(-)

diff --git 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 @@ -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."