On 06/05/2021 19:41, Bastien wrote:
Fr Ml writes:
I have a problem with the function org-store-link it doesn't work as
described in the documentation:
https://orgmode.org/manual/Handling-Links.html
"For Org files, if there is a '<<target>>' at point, the link points
to
the target."
Fixed in maint, thanks a lot for reporting this and Ihor for
confirming the bug.
Bastien, unfortunately your fix caused duplication of stored links like
"file:~/org/file.org::#custom_id" when point is outside of <<target>>.
Earlier #CUSTOM_ID link was stored in addition to
"file:~/org/file.org::*Heading" search link. My suggestion is to revert
your patch and to just reset custom-id variable when <<target>> link is
stored. Another effect or your patch, that I consider unintentional, is
storing
[[file:~/org/file.org::#custom_id][file:~/org/file.org::#custom_id]]
instead of [[file:~/org/file.org::#custom_id][Heading]]. I prefer
"original" behavior.
Third patch is intended to avoid links inserted as
[[target][file:~/org/file.org::target]] in the case of same file. I
suppose, just [[target]] is better. Current variant looks unbalanced and
misleading. Of course, you are free to skip last patch.
I am confused by `org-insert-link' behavior. It inserts links like
[[file:~/org/file.org::#custom_id][file:~/org/file.org::#custom_id]]
without user prompt for description but
[[file:~/org/file.org::#custom_id][Heading]] requires to confirm
"Heading" description explicitly. I would expect that "raw" link is
subject to ask user for more friendly option.
>From 28f1d331888ebd22d60343bb06d3b307aff9fc93 Mon Sep 17 00:00:00 2001
From: Max Nikulin <maniku...@gmail.com>
Date: Fri, 5 Nov 2021 19:03:59 +0700
Subject: [PATCH 1/3] Revert "lisp/ol.el: Fix bug when storing links"
This reverts commit b4b35fc92d6ea8eb2ac061b8ccf026e9b4ebfe33.
Avoid duplication of CUSTOM_ID links.
---
lisp/ol.el | 17 +++++------------
1 file changed, 5 insertions(+), 12 deletions(-)
diff --git a/lisp/ol.el b/lisp/ol.el
index aa1849715..6fe50ed60 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1613,8 +1613,9 @@ non-nil."
((and (buffer-file-name (buffer-base-buffer)) (derived-mode-p 'org-mode))
(org-with-limited-levels
- (cond
- ;; Store a link using the target at point.
+ (setq custom-id (org-entry-get nil "CUSTOM_ID"))
+ (cond
+ ;; Store a link using the target at point
((org-in-regexp "[^<]<<\\([^<>]+\\)>>[^>]" 1)
(setq cpltxt
(concat "file:"
@@ -1622,15 +1623,6 @@ non-nil."
(buffer-file-name (buffer-base-buffer)))
"::" (match-string 1))
link cpltxt))
- ;; Store a link using the CUSTOM_ID property.
- ((setq custom-id (org-entry-get nil "CUSTOM_ID"))
- (setq cpltxt
- (concat "file:"
- (abbreviate-file-name
- (buffer-file-name (buffer-base-buffer)))
- "::#" custom-id)
- link cpltxt))
- ;; Store a link using (and perhaps creating) the ID property.
((and (featurep 'org-id)
(or (eq org-id-link-to-org-use-id t)
(and interactive?
@@ -1639,13 +1631,14 @@ non-nil."
'create-if-interactive-and-no-custom-id)
(not custom-id))))
(and org-id-link-to-org-use-id (org-entry-get nil "ID"))))
+ ;; Store a link using the ID at point
(setq link (condition-case nil
(prog1 (org-id-store-link)
(setq desc (or (plist-get org-store-link-plist
:description)
"")))
(error
- ;; Probably before first headline, link only to file.
+ ;; Probably before first headline, link only to file
(concat "file:"
(abbreviate-file-name
(buffer-file-name (buffer-base-buffer))))))))
--
2.25.1
>From 1fb5a5e071141e47d551202eeca5776185ca8461 Mon Sep 17 00:00:00 2001
From: Max Nikulin <maniku...@gmail.com>
Date: Fri, 5 Nov 2021 19:49:23 +0700
Subject: [PATCH 2/3] ol.el: Skip #CUSTOM_ID when <<target>> link is stored
* list/ol.el (org-store-link): Suppress storing of
"file:file.org::#custom_id" link when point is <<target>>.
CUSTOM_ID link is stored as additional option, so new chunk of code
introduced by b4b35fc92 is not necessary. It prevented adding of
"file:file.org::*Heading" link and caused duplication of
"file:file.org::#custom_id" link.
Reported-by: Fr Ml <fr...@t-online.de>
Link: https://orgmode.org/list/aadb23f3-c0fe-19aa-be79-50e51d16c...@t-online.de/
---
lisp/ol.el | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lisp/ol.el b/lisp/ol.el
index 6fe50ed60..5e1f1f2d2 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1622,7 +1622,9 @@ non-nil."
(abbreviate-file-name
(buffer-file-name (buffer-base-buffer)))
"::" (match-string 1))
- link cpltxt))
+ link cpltxt
+ ;; Do not append #CUSTOM_ID link below.
+ custom-id nil))
((and (featurep 'org-id)
(or (eq org-id-link-to-org-use-id t)
(and interactive?
--
2.25.1
>From f307c7059744b28b26f5c3b8dd4a0f563b22e586 Mon Sep 17 00:00:00 2001
From: Max Nikulin <maniku...@gmail.com>
Date: Sat, 6 Nov 2021 18:23:25 +0700
Subject: [PATCH 3/3] ol.el: Avoid links like
"[[target][file:~/org/test.org::target]]"
* lisp/ol.el (org-store-link): Do not set description for "<<target>>"
links to avoid case when it is more detailed than link target.
While inserting to the same file, file part of the link target is
stripped, description is inserted without modification. I do not think,
file path adds real value in comparison to "[[target]]" link to some
point in the same file. A side effect is user prompt for description
since link and description are not identical any more.
---
lisp/ol.el | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/lisp/ol.el b/lisp/ol.el
index 5e1f1f2d2..ec5427e7c 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1617,12 +1617,17 @@ non-nil."
(cond
;; Store a link using the target at point
((org-in-regexp "[^<]<<\\([^<>]+\\)>>[^>]" 1)
- (setq cpltxt
+ (setq link
(concat "file:"
(abbreviate-file-name
(buffer-file-name (buffer-base-buffer)))
"::" (match-string 1))
- link cpltxt
+ ;; 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'.
+ cpltxt nil
+ desc nil
;; Do not append #CUSTOM_ID link below.
custom-id nil))
((and (featurep 'org-id)
--
2.25.1