On Saturday, October 11, 2025, Ihor Radchenko wrote:
>> Hello, I usually prefer using org-id’s (stored in the ID
>> Property) for linking and referencing. This patch would
>> use an existing ID value instead of a filename path.
[..]
> The feature you describe generally makes sense, but it should honor
> `org-link-context-for-files' and `org-id-link-use-context'. What you
> need to modify is `org-link-precise-link-target', not `org-store-link'
> itself.
Thanks for your hints and suggestions. Attached is a new patch.
I hope I understood your comments, didn’t mess up anything and
the patch is helpful for the org community.
1. I have extended ‘org-store-link’ so it recognizes when ID is
set (additionally to CUSTOM_ID).
2. I have extended ‘org-link-precise-link-target’ to store an id:
link if the ID is set.
Users have the option with org-insert-link to either insert the
anchor or the ID (when given) - similar how it is done with
CUSTOM_ID.(*)
When CUSTOM_ID and ID are both set, the CUSTOM_ID will be used.
(*) I wasn’t aware that org-store-link is storing 2 links when
CUSTOM_ID is given. Interesting!
--
Christian Barthel
diff -u --label /opt/emacs-30.1.90/share/emacs/30.1.90/lisp/org/ol.el.gz --label \#\<buffer\ ol.el.gz\<org\>\> /tmp/jka-comOnKBrY /tmp/buffer-content-13Tz0O
--- /opt/emacs-30.1.90/share/emacs/30.1.90/lisp/org/ol.el.gz
+++ #<buffer ol.el.gz<org>>
@@ -1482,7 +1482,8 @@
(let* ((element (org-element-at-point))
(name (org-element-property :name element))
(heading (org-element-lineage element '(headline inlinetask) t))
- (custom-id (org-entry-get heading "CUSTOM_ID")))
+ (custom-id (org-entry-get heading "CUSTOM_ID"))
+ (item-id (org-entry-get heading "ID")))
(cond
(name
(list name
@@ -1494,7 +1495,7 @@
(line-beginning-position)))
(heading
(list (if custom-id (concat "#" custom-id)
- (org-link-heading-search-string))
+ (if item-id (concat "id:" item-id) (org-link-heading-search-string)))
(org-link--normalize-string
(org-get-heading t t t t))
(org-element-begin heading))))))
@@ -1876,7 +1877,8 @@
;; using custom id, if available.
(when (and (buffer-file-name (buffer-base-buffer))
(derived-mode-p 'org-mode)
- (org-entry-get nil "CUSTOM_ID"))
+ (or (org-entry-get nil "CUSTOM_ID")
+ (org-entry-get nil "ID")))
(let ((here (org-link--file-link-to-here)))
(setq link (car here))
(setq desc (cdr here)))
Diff finished. Sat Oct 11 19:49:09 2025