diff options
| author | Damien Cassou <damien@cassou.me> | 2022-11-01 14:44:01 +0100 |
|---|---|---|
| committer | Wilfred Hughes <me@wilfred.me.uk> | 2022-12-01 09:18:55 -0800 |
| commit | 2f525ca6e49a869cf315ae48851e511bad42a975 (patch) | |
| tree | 800d990b69353eb475ad6376b62378453a38cb31 /helpful.el | |
| parent | 08507233ba5a8335a3646f14eb3f42526b8389d2 (diff) | |
Add support for following and storing org "help" links
Closes #38
Diffstat (limited to 'helpful.el')
| -rw-r--r-- | helpful.el | 41 |
1 files changed, 40 insertions, 1 deletions
@@ -2962,6 +2962,39 @@ See also `helpful-max-buffers'." ;; TODO: find a cleaner solution. (defvar bookmark-make-record-function) +(defun helpful--add-support-for-org-links () + "Improve support for org \"help\" links through helpful." + (helpful--support-storing-org-links) + (helpful--prefer-helpful-when-following-org-link)) + +(defun helpful--support-storing-org-links () + "Make `org-store-link' in a helpful buffer return a \"help\" link." + (when (and (fboundp 'org-link-set-parameters) + (not (-contains-p (org-link-types) "helpful"))) + (org-link-set-parameters "helpful" + :store #'helpful--org-link-store))) + +(defun helpful--org-link-store () + "Store \"help\" type link when in a helpful buffer." + (when (derived-mode-p 'helpful-mode) + ;; Create a "help" link instead of a dedicated "helpful" link: the + ;; author of the Org document uses helful, but this is not + ;; necessarily the case of the reader of the document. + (org-link-store-props :type "help" + :link (format "help:%s" helpful--sym) + :description nil))) + +(defun helpful--prefer-helpful-when-following-org-link () + "Prefer helpful when using `org-open-at-point' on a \"help\" link." + (when (fboundp 'org-link-set-parameters) + (let ((follow-function (org-link-get-parameter "help" :follow))) + (when (not (equal follow-function #'helpful--org-link-follow)) + (org-link-set-parameters "help" + :follow #'helpful--org-link-follow))))) + +(defun helpful--org-link-follow (link _) + (helpful-symbol (intern link))) + (define-derived-mode helpful-mode special-mode "Helpful" "Major mode for *Helpful* buffers." (add-hook 'xref-backend-functions #'elisp--xref-backend nil t) @@ -2972,7 +3005,13 @@ See also `helpful-max-buffers'." ;; Enable users to bookmark helpful buffers. (set (make-local-variable 'bookmark-make-record-function) - #'helpful--bookmark-make-record)) + #'helpful--bookmark-make-record) + + ;; This function should normally only be called once after Org and + ;; helpful are loaded. To avoid using `eval-after-load' (which is + ;; only recommended in user init files), the function is called each + ;; time the major mode is used. + (helpful--add-support-for-org-links)) (provide 'helpful) ;;; helpful.el ends here |
