aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilfred Hughes <me@wilfred.me.uk>2019-07-11 00:14:43 +0100
committerWilfred Hughes <me@wilfred.me.uk>2019-07-11 00:15:12 +0100
commit429f1fb5f588cc6124513335e8eca3b4ef15735a (patch)
tree662cb37f3b44ced5fa1cb18a1342696d29798064
parent0aa289e7a954df456793e7bc1f4bdc3d072e783f (diff)
Add bookmark support0.17
Fixes #203
-rw-r--r--CHANGELOG.md2
-rw-r--r--helpful.el33
2 files changed, 34 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cf35f3c..54815a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ String values are now shown as literals by default.
Fixed an issue with modes that override after-change-major-mode-hook,
such as `global-hi-lock-mode`.
+Added bookmark support.
+
# v0.16
Improved wording when looking at aliases.
diff --git a/helpful.el b/helpful.el
index 9dfd4be..49ad48d 100644
--- a/helpful.el
+++ b/helpful.el
@@ -2482,6 +2482,25 @@ or :foo."
(or (fboundp symbol)
(helpful--variable-p symbol)))
+(defun helpful--bookmark-jump (bookmark)
+ "Create and switch to helpful bookmark BOOKMARK."
+ (let ((callable-p (bookmark-prop-get bookmark 'callable-p))
+ (sym (bookmark-prop-get bookmark 'sym))
+ (position (bookmark-prop-get bookmark 'position)))
+ (if callable-p
+ (helpful-callable sym)
+ (helpful-variable sym))
+ (goto-char position)))
+
+(defun helpful--bookmark-make-record ()
+ "Create a bookmark record for helpful buffers.
+
+See docs of `bookmark-make-record-function'."
+ `((sym . ,helpful--sym)
+ (callable-p . ,helpful--callable-p)
+ (position . ,(point))
+ (handler . helpful--bookmark-jump)))
+
(defun helpful--convert-c-name (symbol var)
"Convert SYMBOL from a C name to an Elisp name.
E.g. convert `Fmake_string' to `make-string' or
@@ -2620,13 +2639,25 @@ See also `helpful-max-buffers'."
map)
"Keymap for `helpful-mode'.")
+(declare-function bookmark-prop-get "bookmark" (bookmark prop))
+(declare-function bookmark-make-record-default "bookmark"
+ (&optional no-file no-context posn))
+;; Ensure this variable is defined even if bookmark.el isn't loaded
+;; yet. This follows the pattern in help-mode.el.gz.
+;; TODO: find a cleaner solution.
+(defvar bookmark-make-record-function)
+
(define-derived-mode helpful-mode special-mode "Helpful"
"Major mode for *Helpful* buffers."
(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 " "))
+ (setq-local imenu-space-replacement " ")
+
+ ;; Enable users to bookmark helpful buffers.
+ (set (make-local-variable 'bookmark-make-record-function)
+ #'helpful--bookmark-make-record))
(provide 'helpful)
;;; helpful.el ends here