From 23e62f7527e7106abd12f35fc919f44dfe22f097 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Wed, 2 Apr 2014 14:16:52 +0200 Subject: [PATCH] Radio targets cannot beging or end with whitespace * lisp/org.el (org-radio-target-regexp): Radio targets cannot begin or end with whitespace. (org-target-regexp): Update syntax according to previous rule. (org-any-target-regexp): Fix fontification bug. * testing/lisp/test-org-element.el (test-org-element/radio-target-parser): Add test. Variables are turned into defconst to emphasize the fact that they are not subject to change. Thanks to Daniel Clemente for reporting it. http://permalink.gmane.org/gmane.emacs.orgmode/84461 --- lisp/org.el | 12 +++++++++--- testing/lisp/test-org-element.el | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lisp/org.el b/lisp/org.el index bb83eb7c6..9283d3644 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -6065,11 +6065,17 @@ by a #." (defvar org-target-link-regexp nil "Regular expression matching radio targets in plain text.") (make-variable-buffer-local 'org-target-link-regexp) -(defvar org-target-regexp "<<\\([^<>\n\r]+\\)>>" + +(defconst org-target-regexp (let ((border "[^<>\n\r \t]")) + (format "<<\\(%s\\|%s[^<>\n\r]*%s\\)>>" + border border border)) "Regular expression matching a link target.") -(defvar org-radio-target-regexp "<<<\\([^<>\n\r]+\\)>>>" + +(defconst org-radio-target-regexp (format "<%s>" org-target-regexp) "Regular expression matching a radio target.") -(defvar org-any-target-regexp "<<\n\r]+\\)>>>?" ; FIXME, not exact, would match <<> as a radio target. + +(defconst org-any-target-regexp + (format "%s\\|%s" org-radio-target-regexp org-target-regexp) "Regular expression matching any target.") (defun org-activate-target-links (limit) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index def1659cc..d6e38ff85 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1699,6 +1699,15 @@ Outside list" (should (eq 'radio-target (org-test-with-temp-text "<<<\\alpha radio>>>" + (org-element-type (org-element-context))))) + ;; Radio targets cannot begin or end with white space. + (should-not + (eq 'radio-target + (org-test-with-temp-text "<<< radio>>>" + (org-element-type (org-element-context))))) + (should-not + (eq 'radio-target + (org-test-with-temp-text "<<>>" (org-element-type (org-element-context))))))