diff --git a/lisp/org-element.el b/lisp/org-element.el index d8a78436f..6eabf7661 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -5753,15 +5753,15 @@ Providing it allows for quicker computation." (org-with-wide-buffer (let* ((pos (point)) (element (or element (org-element-at-point))) - (type (org-element-type element))) + (type (org-element-type element)) + (post (org-element-property :post-affiliated element))) ;; If point is inside an element containing objects or ;; a secondary string, narrow buffer to the container and ;; proceed with parsing. Otherwise, return ELEMENT. (cond ;; At a parsed affiliated keyword, check if we're inside main ;; or dual value. - ((let ((post (org-element-property :post-affiliated element))) - (and post (< pos post))) + ((and post (< pos post)) (beginning-of-line) (let ((case-fold-search t)) (looking-at org-element--affiliated-re)) (cond @@ -5780,7 +5780,8 @@ Providing it allows for quicker computation." ;; At an item, objects can only be located within tag, if any. ((eq type 'item) (let ((tag (org-element-property :tag element))) - (if (not tag) (throw 'objects-forbidden element) + (if (or (not tag) (/= (line-beginning-position) post)) + (throw 'objects-forbidden element) (beginning-of-line) (search-forward tag (line-end-position)) (goto-char (match-beginning 0)) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index c3d8d6e5d..ac1f0f598 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -3322,36 +3322,43 @@ Text ;; Return closest object containing point. (should (eq 'underline - (org-test-with-temp-text "Some *text with _underline_ text*" - (progn (search-forward "under") - (org-element-type (org-element-context)))))) + (org-test-with-temp-text "Some *text with _underline_ text*" + (org-element-type (org-element-context))))) ;; Find objects in secondary strings. (should (eq 'underline - (org-test-with-temp-text "* Headline _with_ underlining" - (progn (search-forward "w") - (org-element-type (org-element-context)))))) + (org-test-with-temp-text "* Headline _with_ underlining" + (org-element-type (org-element-context))))) ;; Find objects in objects. (should (eq 'macro - (org-test-with-temp-text "| a | {{{macro}}} |" - (progn (search-forward "{") - (org-element-type (org-element-context)))))) + (org-test-with-temp-text "| a | {{{macro}}} |" + (org-element-type (org-element-context))))) (should (eq 'table-cell - (org-test-with-temp-text "| a | b {{{macro}}} |" - (progn (search-forward "b") - (org-element-type (org-element-context)))))) + (org-test-with-temp-text "| a | b {{{macro}}} |" + (org-element-type (org-element-context))))) ;; Find objects in planning lines. (should (eq 'timestamp - (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>" - (search-forward "2012") + (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>" (org-element-type (org-element-context))))) (should-not (eq 'timestamp - (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>" - (search-forward "SCHEDULED") + (org-test-with-temp-text "* H\n SCHEDULED: <2012-03-29 thu.>" + (org-element-type (org-element-context))))) + ;; Find objects in item tags. + (should + (eq 'bold + (org-test-with-temp-text "- *bold* ::" + (org-element-type (org-element-context))))) + (should-not + (eq 'bold + (org-test-with-temp-text "- *bold* ::" + (org-element-type (org-element-context))))) + (should-not + (eq 'bold + (org-test-with-temp-text "- *bold* ::\n" (org-element-type (org-element-context))))) ;; Do not find objects in table rules. (should @@ -3361,14 +3368,12 @@ Text ;; Find objects in parsed affiliated keywords. (should (eq 'macro - (org-test-with-temp-text "#+CAPTION: {{{macro}}}\n| a | b |." - (progn (search-forward "{") - (org-element-type (org-element-context)))))) + (org-test-with-temp-text "#+CAPTION: {{{macro}}}\n| a | b |" + (org-element-type (org-element-context))))) (should (eq 'bold - (org-test-with-temp-text "#+caption: *bold*\nParagraph" - (progn (search-forward "*") - (org-element-type (org-element-context)))))) + (org-test-with-temp-text "#+caption: *bold*\nParagraph" + (org-element-type (org-element-context))))) ;; Find objects at the end of buffer. (should (eq 'bold @@ -3378,35 +3383,28 @@ Text ;; Correctly set `:parent' property. (should (eq 'paragraph - (org-test-with-temp-text "Some *bold* text" - (progn (search-forward "bold") - (org-element-type - (org-element-property :parent (org-element-context))))))) + (org-test-with-temp-text "Some *bold* text" + (org-element-type + (org-element-property :parent (org-element-context)))))) ;; Between two objects, return the second one. (should (eq 'macro - (org-test-with-temp-text "<>{{{test}}}" - (progn (search-forward "{") - (backward-char) - (org-element-type (org-element-context)))))) + (org-test-with-temp-text "<>{{{test}}}" + (org-element-type (org-element-context))))) ;; Test optional argument. (should (eq 'underline - (org-test-with-temp-text "Some *text with _underline_ text*" - (progn - (search-forward "under") - (org-element-type (org-element-context (org-element-at-point))))))) + (org-test-with-temp-text "Some *text with _underline_ text*" + (org-element-type (org-element-context (org-element-at-point)))))) ;; Special case: bold object at the beginning of a headline. (should (eq 'bold - (org-test-with-temp-text "* *bold*" - (search-forward "bo") + (org-test-with-temp-text "* *bold*" (org-element-type (org-element-context))))) ;; Special case: incomplete cell at the end of a table row. (should (eq 'table-cell - (org-test-with-temp-text "|a|b|c" - (goto-char (point-max)) + (org-test-with-temp-text "|a|b|c" (org-element-type (org-element-context))))) ;; Special case: objects in inline footnotes. (should