소스 검색

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.
Rudolf Adamkovič 2 년 전
부모
커밋
d9963c58dc
2개의 변경된 파일16개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      lisp/ol.el
  2. 12 0
      testing/lisp/test-org.el

+ 4 - 0
lisp/ol.el

@@ -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

+ 12 - 0
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>>> <<<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