lisp/ol.el: Fix shadowed radio targets

* lisp/ol.el (org-update-radio-target-regexp): Sort radio targets
before building the regexp that matches them.
* testing/lisp/test-org.el: Test shadowed radio targets.  The bug
occurs when two targets share the same prefix and when and the longer
target appears first.
This commit is contained in:
Rudolf Adamkovič 2022-04-23 11:39:33 +02:00 committed by Ihor Radchenko
parent 0e7033e0ca
commit d9963c58dc
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 16 additions and 0 deletions

View File

@ -2040,6 +2040,10 @@ Also refresh fontification if needed."
(cl-pushnew (org-element-property :value obj) rtn
:test #'equal))))
rtn))))
(setq targets
(sort targets
(lambda (a b)
(> (length a) (length b)))))
(setq org-target-link-regexp
(and targets
(concat before-re

View File

@ -2915,6 +2915,18 @@ Foo Bar
(org-open-at-point)
(eq (org-element-type (org-element-context)) 'radio-target))))
(ert-deftest test-org/open-at-point/radio-target-shadowed ()
"Test `org-open-at-point' on shadowed radio targets."
(should
(org-test-with-temp-text
"<<<target shadowed>>> <<<target>>> <point>target shadowed"
(org-update-radio-target-regexp)
(org-open-at-point)
(string=
(org-element-property :value
(org-element-radio-target-parser))
"target shadowed"))))
(ert-deftest test-org/open-at-point/tag ()
"Test `org-open-at-point' on tags."
(should