branch: externals/org
commit 62cad0194b2ac91b3de85caab33e40bef9eeb2a4
Author: Christian Barthel <[email protected]>
Commit: Ihor Radchenko <[email protected]>
ol: Allow targets as search option in id: links
* lisp/ol.el (org-link-precise-link-target): Store context when
storing a link on a target.
This makes it possible to restore a link using ID and anchor when
`org-id-link-to-org-use-id' is non-nil.
Link: https://list.orgmode.org/[email protected]/
TINYCHANGE
---
etc/ORG-NEWS | 20 ++++++++++++++++++++
lisp/ol.el | 21 ++++++---------------
testing/lisp/test-ol.el | 20 ++++++++++++++++++++
3 files changed, 46 insertions(+), 15 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 3b9155090e..2712d7589b 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -47,6 +47,26 @@ the correct ~(FILE . ...)~ cons.
# We list the most important features, and the features that may
# require user action to be used.
+*** Link targets can be used as search option in =id:= links
+
+When storing an =id:= link to target, the target will now be used as a
+search option. This mirrors what happens with =file:= links.
+You need to set ~org-id-link-to-org-use-id~ to make Org store =id:=
+link by default.
+
+See also ~org-id-link-use-context~ and ~org-link-context-for-files~.
+
+For example, link to =<<target>>=
+
+: * Heading
+: :PROPERTIES:
+: :ID: foo
+: :END:
+: Some text with <<target>>.
+
+will be stored as
+: [[id:foo::target][target]]
+
*** New actions in the ~org-mouse~ priority menus
Priorities can now be increased, decreased, set to the default, and
diff --git a/lisp/ol.el b/lisp/ol.el
index f08433dfef..db4772d6a2 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1961,9 +1961,14 @@ matches."
((derived-mode-p 'org-mode)
(let* ((element (org-element-at-point))
(name (org-element-property :name element))
+ (context (org-element-context element))
(heading (org-element-lineage element '(headline
inlinetask) t))
(custom-id (org-entry-get heading "CUSTOM_ID")))
(cond
+ ((org-element-type-p context 'target)
+ (list (org-element-property :value context)
+ (org-element-property :value context)
+ (org-element-begin context)))
(name
(list name
name
@@ -2657,24 +2662,10 @@ NAME."
;; buffers
((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
- ((org-in-regexp "[^<]<<\\([^<>]+\\)>>[^>]" 1)
- (setq link
- (concat "file:"
- (abbreviate-file-name
- (buffer-file-name (buffer-base-buffer)))
- "::" (match-string 1))
- ;; 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))
- (t
;; Just link to current headline.
(let ((here (org-link--file-link-to-here)))
(setq link (car here))
- (setq desc (cdr here)))))))
+ (setq desc (cdr here)))))
;; Buffer linked to file, but not an org-mode buffer.
((buffer-file-name (buffer-base-buffer))
diff --git a/testing/lisp/test-ol.el b/testing/lisp/test-ol.el
index 2403b154ca..371bf1e0f5 100644
--- a/testing/lisp/test-ol.el
+++ b/testing/lisp/test-ol.el
@@ -417,6 +417,26 @@ See https://github.com/yantar92/org/issues/4."
(ert-deftest test-org-link/id-store-link ()
"Test `org-id-store-link' specifications."
+ (let ((org-id-link-to-org-use-id t))
+ (should
+ (equal '("id:abc::myanchor" "myanchor")
+ (test-ol-stored-link-with-text "* H1\n:PROPERTIES:\n:ID:
abc\n:END:\n<point><<myanchor>>\n"
+ (org-id-store-link)))))
+ (let ((org-id-link-to-org-use-id t))
+ (should
+ (equal '("id:abc" "H1")
+ (test-ol-stored-link-with-text "<point>* H1\n:PROPERTIES:\n:ID:
abc\n:END:\n<<myanchor>>\n"
+ (org-id-store-link)))))
+ (let ((org-id-link-to-org-use-id t))
+ (should
+ (equal '("id:abc" "H1")
+ (test-ol-stored-link-with-text "* H1\n:PROPERTIES:\n:ID:
abc\n:END:\n<<myanchor>>\n<point>"
+ (org-id-store-link)))))
+ (let ((org-id-link-to-org-use-id nil))
+ (should
+ (equal '("id:abc::myanchor" "myanchor")
+ (test-ol-stored-link-with-text "* H1\n:PROPERTIES:\n:ID:
abc\n:END:\n<point><<myanchor>>\n"
+ (org-id-store-link)))))
(let ((org-id-link-to-org-use-id nil))
(should
(equal '(nil nil)