emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] ol.el: add description format parameter to org-link-parameter


From: Hugo Heagren
Subject: [PATCH v2] ol.el: add description format parameter to org-link-parameters
Date: Tue, 5 Apr 2022 20:29:31 +0100

* ol.el (org-link-parameters): add parameter `:default-description', a
string or a function.
* (org-insert-link): if no description is provided (pre-existing or as
an argument), next option is to use the `:default-description' (if
non-nil) parameter to generate one.

Default descriptions are predictable within a link type, but because
link types are quite diverse, are NOT predictable across many types. A
type-parameter is thus a good place to store information on the
default description.
---

I've added the condition-case back to the check on
`org-link-make-description', and added a new one to the check for the
`:default-description' parameter, as Ihor suggested. I've also
modified the handling of that parameter, to reflect
`org-link-make-description', and updated the docstring accordingly.

Apologies if the subject formatting is not correct, I'm still getting
the hang of git-send-email.

Hugo

 lisp/ol.el | 43 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index 1b2bb9a9a..e74ef8dda 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -140,6 +140,15 @@ link.
   Function that inserts a link with completion.  The function
   takes one optional prefix argument.
 
+`:default-description'
+
+  String or function used as a default when prompting users for a
+  link's description. A string is used as-is, a function is
+  called with two arguments: the full link text, and the
+  description generated by `org-insert-linke'. It should return
+  the description to use (this reflects the behaviour of
+  `org-link-make-description-function').
+
 `:display'
 
   Value for `invisible' text property on the hidden parts of the
@@ -1761,11 +1770,14 @@ prefix negates `org-link-keep-stored-after-insertion'.
 If the LINK-LOCATION parameter is non-nil, this value will be used as
 the link location instead of reading one interactively.
 
-If the DESCRIPTION parameter is non-nil, this value will be used as the
-default description.  Otherwise, if `org-link-make-description-function'
-is non-nil, this function will be called with the link target, and the
-result will be the default link description.  When called non-interactively,
-don't allow to edit the default description."
+If the DESCRIPTION parameter is non-nil, this value will be used
+as the default description.  If not, and the chosen link type has
+a non-nil `:default-description' parameter, that is used to
+generate a description as described in `org-link-parameters'
+docstring. Otherwise, if `org-link-make-description-function' is
+non-nil, this function will be called with the link target, and
+the result will be the default link description.  When called
+non-interactively, don't allow to edit the default description."
   (interactive "P")
   (let* ((wcf (current-window-configuration))
         (origbuf (current-buffer))
@@ -1775,7 +1787,7 @@ don't allow to edit the default description."
         (desc region)
         (link link-location)
         (abbrevs org-link-abbrev-alist-local)
-        entry all-prefixes auto-desc)
+        entry all-prefixes auto-desc type)
     (cond
      (link-location)                 ; specified by arg, just use it.
      ((org-in-regexp org-link-bracket-re 1)
@@ -1842,6 +1854,7 @@ Use TAB to complete link prefixes, then RET for 
type-specific completion support
                      (and (equal ":" (substring link -1))
                           (member (substring link 0 -1) all-prefixes)
                           (setq link (substring link 0 -1))))
+              (setq type link)
              (setq link (with-current-buffer origbuf
                           (org-link--try-special-completion link)))))
        (set-window-configuration wcf)
@@ -1918,7 +1931,23 @@ Use TAB to complete link prefixes, then RET for 
type-specific completion support
       (let ((initial-input
             (cond
              (description)
-             ((not org-link-make-description-function) desc)
+              (desc)
+              ((org-link-get-parameter
+                type
+                :default-description)
+               (condition-case nil
+                   (let ((def (org-link-get-parameter
+                               type
+                               :default-description)))
+                     (cond
+                      ((stringp def) def)
+                      ((functionp def)
+                       (funcall def link desc))))
+                 (error
+                  (message "Can't get link description from %S"
+                          (symbol-name def))
+                 (sit-for 2)
+                  nil)))
              (t (condition-case nil
                     (funcall org-link-make-description-function link desc)
                   (error
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]