From 8a2ffac88ae697ddd835da1db1de03bb0162c4c0 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 15 Apr 2017 17:27:01 +0200 Subject: [PATCH] org-element: Fix radio link parser * lisp/org-element.el (org-element--object-lex): Fix parsing of radio links within emphasis. * testing/lisp/test-org-element.el (test-org-element/link-parser): Add test. Reported-by: R C --- lisp/org-element.el | 11 ++++++++--- testing/lisp/test-org-element.el | 11 +++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index f12061995..deeb51b01 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -4366,6 +4366,10 @@ to an appropriate container (e.g., a paragraph)." (if (memq 'table-cell restriction) (org-element-table-cell-parser) (let* ((start (point)) (limit + ;; Object regexp sometimes needs to have a peek at + ;; a character ahead. Therefore, when there is a hard + ;; limit, make it one more than the true beginning of the + ;; radio target. (save-excursion (cond ((not org-target-link-regexp) nil) ((not (memq 'link restriction)) nil) @@ -4381,8 +4385,8 @@ to an appropriate container (e.g., a paragraph)." ((and (= start (1+ (line-beginning-position))) (= start (match-end 1))) (and (re-search-forward org-target-link-regexp nil t) - (match-beginning 1))) - (t (match-beginning 1))))) + (1+ (match-beginning 1)))) + (t (1+ (match-beginning 1)))))) found) (save-excursion (while (and (not found) @@ -4456,7 +4460,8 @@ to an appropriate container (e.g., a paragraph)." (org-element-link-parser))))))) (or (eobp) (forward-char)))) (cond (found) - (limit (org-element-link-parser)) ;radio link + (limit (forward-char -1) + (org-element-link-parser)) ;radio link (t nil)))))) (defun org-element--parse-objects (beg end acc restriction &optional parent) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index c8c35284f..afda308a6 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -1618,6 +1618,17 @@ e^{i\\pi}+1=0 (org-test-with-temp-text "* <<>>\na-bug" (org-update-radio-target-regexp) (org-element-parse-buffer))) + ;; Pathological case: radio target in an emphasis environment. + (should + (eq 'bold + (org-test-with-temp-text "* <<>>\n*radio*" + (org-update-radio-target-regexp) + (org-element-type (org-element-context))))) + (should + (eq 'link + (org-test-with-temp-text "* <<>>\n*radio*" + (org-update-radio-target-regexp) + (org-element-type (org-element-context))))) ;; Standard link. ;; ;; ... with description.