瀏覽代碼

Repair radio target search

* lisp/org.el (org-open-at-point): Find radio targets again.
(org-search-radio-target): New function.

* testing/lisp/test-org.el (test-org/open-at-point/radio-target): New
  test.
Nicolas Goaziou 9 年之前
父節點
當前提交
a3b2b7473e
共有 2 個文件被更改,包括 43 次插入11 次删除
  1. 35 11
      lisp/org.el
  2. 8 0
      testing/lisp/test-org.el

+ 35 - 11
lisp/org.el

@@ -10827,17 +10827,21 @@ link in a property drawer line."
 		  (if (not arg) (org-mark-ring-push)
 		    (switch-to-buffer-other-window
 		     (org-get-buffer-for-internal-link (current-buffer))))
-		  (let ((cmd `(org-link-search
-			       ,(if (member type '("custom-id" "coderef"))
-				    (org-element-property :raw-link link)
-				  path)
-			       ,(cond ((equal arg '(4)) 'occur)
-				      ((equal arg '(16)) 'org-occur))
-			       ;; Prevent fuzzy links from matching
-			       ;; themselves.
-			       ,(and (equal type "fuzzy")
-				     (+ 2
-					(org-element-property :begin link))))))
+		  (let ((cmd
+			 (if (equal type "radio")
+			     `(org-search-radio-target
+			       ,(org-element-property :path link))
+			   `(org-link-search
+			     ,(if (member type '("custom-id" "coderef"))
+				  (org-element-property :raw-link link)
+				path)
+			     ,(cond ((equal arg '(4)) 'occur)
+				    ((equal arg '(16)) 'org-occur))
+			     ;; Prevent fuzzy links from matching
+			     ;; themselves.
+			     ,(and (equal type "fuzzy")
+				   (+ 2
+				      (org-element-property :begin link)))))))
 		    (condition-case nil
 			(let ((org-link-search-inhibit-query t)) (eval cmd))
 		      (error (progn (widen) (eval cmd)))))))
@@ -10974,6 +10978,26 @@ the window configuration before `org-open-at-point' was called using:
 
     (set-window-configuration org-window-config-before-follow-link)")
 
+(defun org-search-radio-target (target)
+  "Search a radio target matching TARGET in current buffer.
+White spaces are not significant."
+  (let ((re (format "<<<%s>>>"
+		    (mapconcat #'regexp-quote
+			       (org-split-string target "[ \t\n]+")
+			       "[ \t]+\\(?:\n[ \t]*\\)?")))
+	(origin (point)))
+    (goto-char (point-min))
+    (catch :radio-match
+      (while (re-search-forward re nil t)
+	(backward-char)
+	(let ((object (org-element-context)))
+	  (when (eq (org-element-type object) 'radio-target)
+	    (goto-char (org-element-property :begin object))
+	    (org-show-context 'link-search)
+	    (throw :radio-match nil))))
+      (goto-char origin)
+      (user-error "No match for radio target: %s" target))))
+
 (defun org-link-search (s &optional type avoid-pos stealth)
   "Search for a search string S.
 

+ 8 - 0
testing/lisp/test-org.el

@@ -1660,6 +1660,14 @@ drops support for Emacs 24.1 and 24.2."
      (prog1 (with-current-buffer "*info*" (looking-at "\nOrg Mode Manual"))
        (kill-buffer "*info*")))))
 
+(ert-deftest test-org/open-at-point/radio-target ()
+  "Test `org-open-at-point' on radio targets."
+  (should
+   (org-test-with-temp-text "<<<target>>> <point>target"
+     (org-update-radio-target-regexp)
+     (org-open-at-point)
+     (eq (org-element-type (org-element-context)) 'radio-target))))
+
 
 ;;; Node Properties