ol: Factorize "help" link store function

* lisp/ol.el (org-link--store-help): New function.
(org-store-link): Do not hard-code "help" links. Use regular
`org-link-set-parameters' process.
This commit is contained in:
Nicolas Goaziou 2021-04-27 17:26:11 +02:00
parent 17084f6425
commit 4f8a2758cb
1 changed files with 17 additions and 14 deletions

View File

@ -1329,7 +1329,23 @@ PATH is a symbol name, as a string."
((and (pred boundp) function) (describe-variable function))
(name (user-error "Unknown function or variable: %s" name))))
(org-link-set-parameters "help" :follow #'org-link--open-help)
(defun org-link--store-help ()
(when (eq major-mode 'help-mode)
(let ((symbol
(replace-regexp-in-string
;; Help mode escapes backquotes and backslashes before
;; displaying them. E.g., "`" appears as "\'" for
;; reasons. Work around this.
(rx "\\" (group (or "`" "\\"))) "\\1"
(save-excursion
(goto-char (point-min))
(re-search-forward "\\S_" (line-end-position) t)
(buffer-substring (point-min) (point))))))
(org-link-store-props :type "help" :link (concat "help:" symbol)))))
(org-link-set-parameters "help"
:follow #'org-link--open-help
:store #'org-link--store-help)
;;;; "http", "https", "mailto", "ftp", and "news" link types
(dolist (scheme '("ftp" "http" "https" "mailto" "news"))
@ -1546,19 +1562,6 @@ non-nil."
nil nil nil))))
(org-link-store-props :type "calendar" :date cd)))
((eq major-mode 'help-mode)
(let ((symbol (replace-regexp-in-string
;; Help mode escapes backquotes and backslashes
;; before displaying them. E.g., "`" appears
;; as "\'" for reasons. Work around this.
(rx "\\" (group (or "`" "\\"))) "\\1"
(save-excursion
(goto-char (point-min))
(looking-at "^[^ ]+")
(match-string 0)))))
(setq link (concat "help:" symbol)))
(org-link-store-props :type "help"))
((eq major-mode 'w3-mode)
(setq cpltxt (if (and (buffer-name)
(not (string-match "Untitled" (buffer-name))))