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.
Example:
--8<---------------cut here---------------start------------->8---
* something
:PROPERTIES:
:ID: 12345
:END:
... some <<anchor>>
^
--8<---------------cut here---------------end--------------->8---
When cursor is at the above line of "^", it stores a link with
the ID and org-insert-link would be something like that:
[[id:12345::anchor]]
Other ideas/options: a variable to control the behavior?
--
Christian Barthel
diff -u --label \#\<buffer\ ol.el.gz\<org\>\> --label \#\<buffer\ ol.el.gz\</tmp\>\> /tmp/buffer-content-L37yPE /tmp/buffer-content-ybnUhb
--- #<buffer ol.el.gz<org>>
+++ #<buffer ol.el.gz</tmp>>
@@ -1835,16 +1835,19 @@
(cond
;; Store a link using the target at point
((org-in-regexp "[^<]<<\\([^<>]+\\)>>[^>]" 1)
- (setq link
- (concat "file:"
+ (let ((anchor (match-string 1)))
+ (setq link
+ (if (org-id-get)
+ (concat "id:" (org-id-get) "::" anchor)
+ (concat "file:"
(abbreviate-file-name
(buffer-file-name (buffer-base-buffer)))
- "::" (match-string 1))
+ "::" anchor))
;; Target may be shortened when link is inserted.
;; Avoid [[target][file:~/org/test.org::target]]
;; links. Maybe the case of identical target and
;; description should be handled by `org-insert-link'.
- desc nil))
+ desc nil)))
(t
;; Just link to current headline.
(let ((here (org-link--file-link-to-here)))
Diff finished. Mon Oct 6 13:09:39 2025