From f0077a592fbf4ddfde02f5899dc428db4f7ecbf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= Date: Sat, 23 Apr 2022 11:39:33 +0200 Subject: [PATCH] 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. --- lisp/ol.el | 3 +++ testing/lisp/test-org.el | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lisp/ol.el b/lisp/ol.el index d4bd0e40c..189e31b1e 100644 --- a/lisp/ol.el +++ b/lisp/ol.el @@ -2040,6 +2040,9 @@ Also refresh fontification if needed." (cl-pushnew (org-element-property :value obj) rtn :test #'equal)))) rtn)))) + (sort targets + (lambda (a b) + (> (length a) (length b)))) (setq org-target-link-regexp (and targets (concat before-re diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 5f13e89a4..121f9efd5 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -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" + (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 -- 2.36.1