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
This commit is contained in:
Nicolas Goaziou 2014-04-02 14:16:52 +02:00
parent 8a43270e8e
commit 23e62f7527
2 changed files with 18 additions and 3 deletions

View File

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

View File

@ -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 "<<<radio >>>"
(org-element-type (org-element-context))))))