org-element: Find objects in document and parsed affiliated keywords

* lisp/org-element.el (org-element-context): Find objects in document
  and parsable affiliated keywords.
* testing/lisp/test-org-element.el: Add tests.
This commit is contained in:
Nicolas Goaziou 2012-10-29 10:53:32 +01:00
parent 89ec3f1abf
commit 99110c60a6
2 changed files with 33 additions and 2 deletions

View File

@ -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)

View File

@ -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