From 429f1fb5f588cc6124513335e8eca3b4ef15735a Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Thu, 11 Jul 2019 00:14:43 +0100 Subject: Add bookmark support Fixes #203 --- CHANGELOG.md | 2 ++ helpful.el | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) 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 -- cgit v1.0