Browse Source

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.
Nicolas Goaziou 4 năm trước cách đây
mục cha
commit
4f8a2758cb
1 tập tin đã thay đổi với 17 bổ sung14 xóa
  1. 17 14
      lisp/ol.el

+ 17 - 14
lisp/ol.el

@@ -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))))