diff --git a/lisp/org-element.el b/lisp/org-element.el index 7828554b0..c69f518ab 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -4622,7 +4622,19 @@ and :post-blank properties." ;; Check if point is inside an element containing objects or at ;; a secondary string. In that case, move to beginning of the ;; element or secondary string and set END to the other side. - (if (not (or (and (eq type 'item) + (if (not (or (let ((post (org-element-property :post-affiliated element))) + (and post (> post origin) + (< (org-element-property :begin element) origin) + (progn (beginning-of-line) + (looking-at org-element--affiliated-re) + (member (upcase (match-string 1)) + org-element-parsed-keywords)) + (if (and (match-end 2) (<= origin (match-end 2))) + (progn (goto-char (match-beginning 2)) + (setq end (match-end 2))) + (goto-char (match-end 0)) + (setq end (line-end-position))))) + (and (eq type 'item) (let ((tag (org-element-property :tag element))) (and tag (progn @@ -4646,7 +4658,14 @@ and :post-blank properties." :contents-end element))) (and (>= origin cbeg) (<= origin cend) - (progn (goto-char cbeg) (setq end cend))))))) + (progn (goto-char cbeg) (setq end cend))))) + (and (eq type 'keyword) + (let ((key (org-element-property :key element))) + (and (member key org-element-document-properties) + (progn (beginning-of-line) + (search-forward key (line-end-position) t) + (forward-char) + (setq end (line-end-position)))))))) element (let ((restriction (org-element-restriction element)) (parent element) diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el index 20fa76b59..8462f766a 100644 --- a/testing/lisp/test-org-element.el +++ b/testing/lisp/test-org-element.el @@ -2645,6 +2645,18 @@ Paragraph \\alpha." (org-test-with-temp-text "| a | b {{{macro}}} |" (progn (search-forward "b") (org-element-type (org-element-context)))))) + ;; Find objects in document keywords. + (should + (eq 'macro + (org-test-with-temp-text "#+DATE: {{{macro}}}" + (progn (search-forward "{") + (org-element-type (org-element-context)))))) + ;; Find objects in parsed affiliated keywords. + (should + (eq 'macro + (org-test-with-temp-text "#+CAPTION: {{{macro}}}\nParagraph." + (progn (search-forward "{") + (org-element-type (org-element-context)))))) ;; Correctly set `:parent' property. (should (eq 'paragraph