On 2024-05-05, 18:01 +0700, Max Nikulin <maniku...@gmail.com> wrote:

> I would consider explicit mention that it is related to Emacs Lisp and 
> perhaps that the origin of its name is the ~shortdoc-display-group~ user 
> command. <info:elisp#Documentation Groups> might be a better link.
>
> This line is rather long though I do not have a link where formatting 
> conventions are documented.

I expanded the description on `org-manual.org' and 'ORG-NEWS'.

>> +;;;; "shortdoc" link type
>> +(when (version< "27" emacs-version)
>
> Is it correct?
>
> 2a7488d42d8 2020-10-11 05:51:16 +0200 Lars Ingebrigtsen: Add support for 
> displaying short documentation for function groups
>
> git tag --contains 2a7488d42d8
> emacs-28.0.90

Fixed.

> I think, it is enough to use [^:] since next group is started from "::". 
> You may use use non-capturing group \\(?:::# ...\\) (requires update of 
> next index below) unless you are going add search code back. I am unsure 
> concerning your intentions. You dropped search code, but "#" after "::" 
> is still optional.

Thanks. I updated the regexp.

I had dropped the search code because I wasn't considering the search option 
properly. If I understand correctly, both "::" and "::#" should match a 
function OR a search string? (e.g.: `shortdoc:text-properties::#pos-property' 
will also search for "pos-property" in the shortdoc buffer). This is the 
current behavior in the attached patch.

> I do not have strong opinion what is better here: `user-error' (used in 
> earlier revisions) or `error'. However I do not see the point of 
> capturing original error and signalling another one if it is not 
> `user-error'.

Agreed. I replaced it with `user-error'.

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 1feb5ed60..dd4cb6cd0 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -3382,6 +3382,13 @@ Here is the full set of built-in link types:
 
   Execute a shell command upon activation.
 
+- =shortdoc= ::
+
+  Link to short documentation summary for an Emacs Lisp function group.
+  Since Emacs 28, user command ~shortdoc-display-group~ lists all known
+  documentation groups. For more information, see [[info:emacs#Name Help]]
+  and [[info:elisp#Documentation Groups]].
+
 
 For =file:= and =id:= links, you can additionally specify a line
 number, or a text search string, separated by =::=.  In Org files, you
@@ -3423,6 +3430,8 @@ options:
 | irc        | =irc:/irc.com/#emacs/bob=                                          |
 | help       | =help:org-store-link=                                              |
 | info       | =info:org#External links=                                          |
+| shortdoc   | =shortdoc:text-properties=                                         |
+|            | =shortdoc:text-properties::#get-pos-property=                      |
 | shell      | =shell:ls *.org=                                                   |
 | elisp      | =elisp:(find-file "Elisp.org")= (Elisp form to evaluate)           |
 |            | =elisp:org-agenda= (interactive Elisp command)                     |
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 99dd8839c..1623873c0 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -1405,6 +1405,11 @@ place the entry in the ~Misc~ category if ~TEXINFO_DIR_CATEGORY~ is missing.
 =TEXINFO_DIR_TITLE= is renamed to =TEXINFO_DIR_NAME=.
 The old name is obsolete.
 
+*** =ol.el=: Support for =shortdoc= link type
+
+Add support for storing and inserting links to =shortdoc= documentation
+groups for Emacs Lisp functions.
+
 ** New functions and changes in function arguments
 *** New optional argument =UPDATE-HEADING= for ~org-bibtex-yank~
 
diff --git a/lisp/ol.el b/lisp/ol.el
index bc9682e4a..ff0b56378 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1582,6 +1582,44 @@ PATH is a symbol name, as a string."
                          :follow #'org-link--open-help
                          :store #'org-link--store-help)
 
+;;;; "shortdoc" link type
+(when (version<= "28.0.90" emacs-version)
+  (defun org-link--open-shortdoc (path _)
+    "Open a \"shortdoc\" type link.
+PATH is a group name, \"group::#function\" or \"group::search_string\"."
+    (string-match "\\`\\([^:]*\\)\\(?:::#?\\(.*\\)\\)?\\'" path)
+    (let ((group (match-string 1 path))
+          (fn (match-string 2 path)))
+      (condition-case nil
+          (progn
+              (shortdoc-display-group group (intern-soft fn))
+              (unless (intern-soft fn)
+                (re-search-forward fn nil t)))
+        (user-error "Unknown shortdoc group: %s" group))))
+
+  (defun org-link--store-shortdoc (&optional _interactive?)
+    "Store \"shortdoc\" type link."
+    (when (eq major-mode 'shortdoc-mode)
+      (let* ((buffer (buffer-name))
+             (group (when (string-match "*Shortdoc \\(.*\\)\\*" buffer)
+                      (match-string 1 buffer))))
+        (if (and group (assoc (intern-soft group) shortdoc--groups))
+            (org-link-store-props :type "shortdoc"
+                                  :link (format "shortdoc:%s" group)
+                                  :description nil)
+          (user-error "Unknown shortdoc group: %s" group)))))
+
+  (defun org-link--complete-shortdoc ()
+    "Create a \"shortdoc\" link using completion."
+    (concat "shortdoc:"
+            (completing-read "Shortdoc summary for functions in: "
+                             (mapcar #'car shortdoc--groups))))
+
+  (org-link-set-parameters "shortdoc"
+                           :follow #'org-link--open-shortdoc
+                           :store #'org-link--store-shortdoc
+                           :complete #'org-link--complete-shortdoc))
+
 ;;;; "http", "https", "mailto", "ftp", and "news" link types
 (dolist (scheme '("ftp" "http" "https" "mailto" "news"))
   (org-link-set-parameters scheme

Reply via email to