diff --git a/lisp/org-element.el b/lisp/org-element.el index ea42a739c..9d146e631 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -5698,7 +5698,7 @@ Providing it allows for quicker computation." (if (not (member (org-element-property :key element) org-element-document-properties)) (throw 'objects-forbidden element) - (beginning-of-line) + (goto-char (org-element-property :begin element)) (search-forward ":") (if (and (>= pos (point)) (< pos (line-end-position))) (narrow-to-region (point) (line-end-position)) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index bf031ac7b..73b428ae8 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -3187,9 +3187,16 @@ Text ;; Find objects in document keywords. (should (eq 'macro - (org-test-with-temp-text "#+DATE: {{{macro}}}" - (progn (search-forward "{") - (org-element-type (org-element-context)))))) + (org-test-with-temp-text "#+DATE: {{{macro}}}" + (org-element-type (org-element-context))))) + (should-not + (eq 'macro + (org-test-with-temp-text "#+DATE: {{{macro}}}\n" + (org-element-type (org-element-context))))) + (should-not + (eq 'macro + (org-test-with-temp-text "#+RANDOM_KEYWORD: {{{macro}}}" + (org-element-type (org-element-context))))) ;; Do not find objects in table rules. (should (eq 'table-row