summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-11-23 22:46:52 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2012-11-23 22:46:52 (GMT)
commit89b8a8ca6daa3ccafa818a7085620eeee1ab9752 (patch)
tree98e1568238e8c7961b05013c2241aafb8b9616ed
parent5dbccdb432a6cae66f0866a30379a352873ed15e (diff)
downloadorg-mode-89b8a8ca6daa3ccafa818a7085620eeee1ab9752.zip
org-mode-89b8a8ca6daa3ccafa818a7085620eeee1ab9752.tar.gz
org-element: Fix `org-element-context'
* lisp/org-element.el (org-element-context): When point is between two objects, be sure to return the second one. * testing/lisp/test-org-element.el: Add test.
-rw-r--r--lisp/org-element.el18
-rw-r--r--testing/lisp/test-org-element.el9
2 files changed, 19 insertions, 8 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index 5da2dec..51b8958 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4316,18 +4316,22 @@ and :post-blank properties."
(funcall (intern (format "org-element-%s-parser"
(car closest-cand))))))
(cbeg (org-element-property :contents-begin object))
- (cend (org-element-property :contents-end object)))
+ (cend (org-element-property :contents-end object))
+ (obj-end (org-element-property :end object)))
(cond
;; ORIGIN is after OBJECT, so skip it.
- ((< (org-element-property :end object) origin)
- (goto-char (org-element-property :end object)))
- ;; ORIGIN is within a non-recursive object or at an
- ;; object boundaries: Return that object.
+ ((<= obj-end origin)
+ (if (/= obj-end end) (goto-char obj-end)
+ (throw 'exit
+ (org-element-put-property
+ object :parent parent))))
+ ;; ORIGIN is within a non-recursive object or at
+ ;; an object boundaries: Return that object.
((or (not cbeg) (> cbeg origin) (< cend origin))
(throw 'exit
(org-element-put-property object :parent parent)))
- ;; Otherwise, move within current object and restrict
- ;; search to the end of its contents.
+ ;; Otherwise, move within current object and
+ ;; restrict search to the end of its contents.
(t (goto-char cbeg)
(org-element-put-property object :parent parent)
(setq parent object
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 55f5eae..38829d5 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -2490,7 +2490,14 @@ Paragraph \\alpha."
(org-test-with-temp-text "Some *bold* text"
(progn (search-forward "bold")
(org-element-type
- (org-element-property :parent (org-element-context))))))))
+ (org-element-property :parent (org-element-context)))))))
+ ;; Between two objects, return the second one.
+ (should
+ (eq 'macro
+ (org-test-with-temp-text "<<target>>{{{test}}}"
+ (progn (search-forward "{")
+ (backward-char)
+ (org-element-type (org-element-context)))))))
(provide 'test-org-element)