diff options
author | Gustav Wikström <gustav@whil.se> | 2021-02-06 20:27:01 +0100 |
---|---|---|
committer | Gustav Wikström <gustav@whil.se> | 2021-02-06 20:46:05 +0100 |
commit | be2966abb5a97f3503cf7c26a83d9e111fc0b8aa (patch) | |
tree | 325bbd0f29f9ffb9a13c64e473003570128ec67b | |
parent | 2512fd702fca4d17f6042f9bfa252a9367fb9f74 (diff) | |
download | org-mode-be2966abb5a97f3503cf7c26a83d9e111fc0b8aa.tar.gz |
org-id: Add title to description when storing id links
* lisp/org-id.el (org-id-store-link): Store title as link description
if it is available.
-rw-r--r-- | etc/ORG-NEWS | 7 | ||||
-rw-r--r-- | lisp/org-id.el | 24 |
2 files changed, 22 insertions, 9 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index ba76922..ef100ed 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -197,6 +197,13 @@ changed to :height 0.75))) #+end_src +*** Storing ID-links before first heading uses title as description + +Storing links to files using ~org-store-link~ (=<C-c l>=) when +~org-id-link-to-org-use-id~ is not nil will now store the title as +description of the link, if available. If no title exists it falls +back to the filename as before. + * Version 9.4 ** Incompatible changes *** Possibly broken internal file links: please check and fix diff --git a/lisp/org-id.el b/lisp/org-id.el index d1e9aa9..76077b7 100644 --- a/lisp/org-id.el +++ b/lisp/org-id.el @@ -693,21 +693,27 @@ optional argument MARKERP, return the position as a new marker." ;;;###autoload (defun org-id-store-link () - "Store a link to the current entry, using its ID." + "Store a link to the current entry, using its ID. + +If before first heading store first title-keyword as description +or filename if no title." (interactive) (when (and (buffer-file-name (buffer-base-buffer)) (derived-mode-p 'org-mode)) (let* ((link (concat "id:" (org-id-get-create))) (case-fold-search nil) (desc (save-excursion (org-back-to-heading-or-point-min t) - (or (and (org-before-first-heading-p) - (file-name-nondirectory - (buffer-file-name (buffer-base-buffer)))) - (and (looking-at org-complex-heading-regexp) - (if (match-end 4) - (match-string 4) - (match-string 0))) - link)))) + (cond ((org-before-first-heading-p) + (let ((keywords (org-collect-keywords '("TITLE")))) + (if keywords + (car (alist-get "TITLE" keywords nil nil 'equal)) + (file-name-nondirectory + (buffer-file-name (buffer-base-buffer)))))) + ((looking-at org-complex-heading-regexp) + (if (match-end 4) + (match-string 4) + (match-string 0))) + (t link))))) (org-link-store-props :link link :description desc :type "id") link))) |