From 6e57a371ff92b47bb0876db853158c1e73d4d586 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Sat, 16 Jan 2016 14:50:25 +0100 Subject: [PATCH] Fix tags looking like plain links * lisp/org-element.el (org-element-context): Do not look for objects within TODO keyword, priority cookie, comment keyword or tags. * lisp/org.el (org-activate-tags): Fix regexp. * testing/lisp/test-org-element.el (test-org-element/context): Add test. Reported-by: John Kitchin --- lisp/org-element.el | 12 ++++++++---- lisp/org.el | 16 ++++++++-------- testing/lisp/test-org-element.el | 9 +++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 33514ce68..b22c5ad1e 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -5773,10 +5773,14 @@ Providing it allows for quicker computation." ;; At an headline or inlinetask, objects are in title. ((memq type '(headline inlinetask)) (goto-char (org-element-property :begin element)) - (skip-chars-forward "*") - (if (and (> pos (point)) (< pos (line-end-position))) - (narrow-to-region (point) (line-end-position)) - (throw 'objects-forbidden element))) + (looking-at org-complex-heading-regexp) + (let ((end (match-end 4))) + (if (not end) (throw 'objects-forbidden element) + (goto-char (match-beginning 4)) + (when (let (case-fold-search) (looking-at org-comment-string)) + (goto-char (match-end 0))) + (if (>= (point) end) (throw 'objects-forbidden element) + (narrow-to-region (point) end))))) ;; At a paragraph, a table-row or a verse block, objects are ;; located within their contents. ((memq type '(paragraph table-row verse-block)) diff --git a/lisp/org.el b/lisp/org.el index 9a1e46cae..f741d5ee9 100755 --- a/lisp/org.el +++ b/lisp/org.el @@ -6240,14 +6240,14 @@ done, nil otherwise." (font-lock-mode 1))) (defun org-activate-tags (limit) - (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \r\n]") limit t) - (progn - (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1)) - (add-text-properties (match-beginning 1) (match-end 1) - (list 'mouse-face 'highlight - 'keymap org-mouse-map)) - (org-rear-nonsticky-at (match-end 1)) - t))) + (when (re-search-forward + (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \t]*$") limit t) + (org-remove-flyspell-overlays-in (match-beginning 1) (match-end 1)) + (add-text-properties (match-beginning 1) (match-end 1) + (list 'mouse-face 'highlight + 'keymap org-mouse-map)) + (org-rear-nonsticky-at (match-end 1)) + t)) (defun org-outline-level () "Compute the outline level of the heading at point. diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 6347e876d..4d4adec58 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -3422,6 +3422,15 @@ Text (should (eq 'link (org-test-with-temp-text "[fn::[[http://orgmode.org]]]" + (org-element-type (org-element-context))))) + ;; Special case: tags looking like a link. + (should-not + (eq 'link + (org-test-with-temp-text "* Headline :file:tags:" + (org-element-type (org-element-context))))) + (should + (eq 'link + (org-test-with-temp-text "* Headline :file:tags: :real:tag:" (org-element-type (org-element-context))))))