org-element: New `org-element-down' function

* contrib/lisp/org-element.el (org-element-down): New function.
* testing/lisp/test-org-element.el: Add test.
This commit is contained in:
Nicolas Goaziou 2012-03-09 19:47:50 +01:00
parent 1a42967061
commit 86131a8b50
2 changed files with 26 additions and 0 deletions

View File

@ -3859,6 +3859,17 @@ modified."
((org-before-first-heading-p) (error "No surrounding element"))
(t (org-back-to-heading))))))))))
(defun org-element-down ()
"Move to inner element."
(interactive)
(let ((element (org-element-at-point)))
(cond
((eq (org-element-type element) 'plain-list)
(forward-char))
((memq (org-element-type element) org-element-greater-elements)
(goto-char (org-element-property :contents-begin element)))
(t (error "No inner element")))))
(provide 'org-element)
;;; org-element.el ends here

View File

@ -312,6 +312,21 @@ Outside."
(org-element-up)
(should (looking-at "\\* Top"))))
(ert-deftest test-org-elemnet/down-element ()
"Test `org-element-down' specifications."
;; 1. Error when the element hasn't got a recursive type.
(org-test-with-temp-text "Paragraph."
(should-error (org-element-down)))
;; 2. When at a plain-list, move to first item.
(org-test-with-temp-text "- Item 1\n - Item 1.1\n - Item 2.2"
(goto-line 2)
(org-element-down)
(should (looking-at " - Item 1.1")))
;; 3. Otherwise, move inside the greater element.
(org-test-with-temp-text "#+BEGIN_CENTER\nParagraph.\n#+END_CENTER"
(org-element-down)
(should (looking-at "Paragraph"))))
(provide 'test-org-element)
;;; test-org-element.el ends here