summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-10-29 10:53:32 +0100
committerNicolas Goaziou <n.goaziou@gmail.com>2012-10-29 11:09:41 +0100
commit99110c60a6c732f6e9131de7ac6090e19e1d01eb (patch)
tree9e8a2c8c7e9a07c5b6f657b1847727eed31e353a
parent89ec3f1abfcbedaf5cd75c9b0916f653ad0bf2f6 (diff)
downloadorg-mode-99110c60a6c732f6e9131de7ac6090e19e1d01eb.tar.gz
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.
-rw-r--r--lisp/org-element.el23
-rw-r--r--testing/lisp/test-org-element.el12
2 files changed, 33 insertions, 2 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 7828554..c69f518 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 20fa76b..8462f76 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