From 10f68bf26f82f4cbc0e097bac9a4d3b997c10bc4 Mon Sep 17 00:00:00 2001 From: Florian Beck Date: Tue, 9 Sep 2014 12:31:35 +0200 Subject: [PATCH 2/4] org-element: Implement `org-element-get' * lisp/org-element.el (org-element-get): New function. --- lisp/org-element.el | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lisp/org-element.el b/lisp/org-element.el index 47fa3f1..f55dd37 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -5873,6 +5873,26 @@ Providing it allows for quicker computation." ;; Store results in cache, if applicable. (org-element--cache-put element cache))))))) +(defun org-element-get (&optional type pom) + "Return the nearest object or element of TYPE at POM." + (let* ((pom (or pom (point))) + (context (with-current-buffer (if (markerp pom) + (marker-buffer pom) + (current-buffer)) + (save-excursion + (goto-char pom) + (org-element-context))))) + (cl-labels ((get-type (type context) + (cond ((not context) nil) + ((not type) context) + ((eql type (car context)) + context) + (t (get-type type + (plist-get + (cadr context) + :parent)))))) + (get-type type context)))) + (defun org-element-nested-p (elem-A elem-B) "Non-nil when elements ELEM-A and ELEM-B are nested." (let ((beg-A (org-element-property :begin elem-A)) -- 1.9.1