From a3b2b7473ecfe019134bb68759fa726040197ed1 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 3 Aug 2015 02:45:25 +0200 Subject: [PATCH] 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. --- lisp/org.el | 46 +++++++++++++++++++++++++++++++++++----------- testing/lisp/test-org.el | 8 ++++++++ 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index 1b69421f5..240542eeb 100755 --- a/lisp/org.el +++ b/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. diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index c8052f760..8282bbe4a 100644 --- a/testing/lisp/test-org.el +++ b/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" + (org-update-radio-target-regexp) + (org-open-at-point) + (eq (org-element-type (org-element-context)) 'radio-target)))) + ;;; Node Properties -- 2.11.4.GIT