diff options
authorNicolas Goaziou <>2013-01-09 14:33:29 (GMT)
committer Nicolas Goaziou <>2013-01-09 14:33:29 (GMT)
commit2fd88bfd5675fc78a2297c2a1544a66c1a86af75 (patch)
parent1dd1b10d5a908ef302b76838931aefdab2d05f34 (diff)
org-element: Small optimization to `org-element-context'
* lisp/org-element.el (org-element-context): Add an optional argument so (org-element-context) and (org-element-context (org-element-at-point)) are equivalent. * testing/lisp/test-org-element.el: Add test.
2 files changed, 15 insertions, 4 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 1349e2b..b7bb487 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4614,7 +4614,7 @@ first element of current section."
(goto-char cbeg)))))))))))
-(defun org-element-context ()
+(defun org-element-context (&optional element)
"Return closest element or object around point.
Return value is a list like (TYPE PROPS) where TYPE is the type
@@ -4624,10 +4624,14 @@ associated to it.
Possible types are defined in `org-element-all-elements' and
`org-element-all-objects'. Properties depend on element or
object type, but always include :begin, :end, :parent
-and :post-blank properties."
+and :post-blank properties.
+Optional argument ELEMENT, when non-nil, is the closest element
+containing point, as returned by `org-element-at-point'.
+Providing it allows for quicker computation."
(let* ((origin (point))
- (element (org-element-at-point))
+ (element (or element (org-element-at-point)))
(type (car element))
;; Check if point is inside an element containing objects or at
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 2ce99ea..b8c012c 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -2713,7 +2713,14 @@ Paragraph \\alpha."
(org-test-with-temp-text "<<target>>{{{test}}}"
(progn (search-forward "{")
- (org-element-type (org-element-context)))))))
+ (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))))))))
(provide 'test-org-element)