diff --git a/lisp/org.el b/lisp/org.el index 27b7fbf79..1ac912e61 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20717,12 +20717,16 @@ When TO-HEADING is non-nil, go to the next heading or `point-max'." (when element (setq element (org-element-lineage element - '(headline inlinetask) + '(headline) 'include-self)) (goto-char (org-element-begin element))) (unless (and invisible-ok element) (org-back-to-heading-or-point-min invisible-ok) - (setq element (org-element-at-point))) + (setq element + (org-element-lineage + (org-element-at-point) + '(headline) + 'include-self))) (if (org-element-type-p element 'headline) (goto-char (org-element-end element)) (goto-char (point-max))) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 3a6c12025..890ea6a8c 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -4107,6 +4107,167 @@ text" (org-end-of-meta-data t) (looking-at "Contents")))) +(ert-deftest test-org/end-of-subtree () + "Test `org-end-of-subtree' specifictions." + ;; Simple call with no arguments. + (org-test-with-temp-text + " +* Heading +** Sub1 +** Sub 2 +asd +* Heading 2" + (org-end-of-subtree) + ;; Move one point before next level 1 heading. + (forward-char) + (should (looking-at-p "^\\* Heading 2")) + (forward-line -1) + (should (looking-at-p "^asd"))) + ;; TO-HEADING + (org-test-with-temp-text + " +* Heading +** Sub1 +** Sub 2 +asd +* Heading 2" + (org-end-of-subtree nil t) + (should (looking-at-p "^\\* Heading 2"))) + ;; Ignore trailing blank lines. + (org-test-with-temp-text + " +* Heading +** Sub1 +** Sub 2 +asd + + + +* Heading 2" + (org-end-of-subtree) + (forward-line 0) + (should (looking-at-p "^asd"))) + ;; Ignore inlinetasks + (let ((org-inlinetask-min-level 3)) + (org-test-with-temp-text + " +* Heading +some text +*** Inlinetask +t +*** END +** Sub1 +** Sub 2 +asd +* Heading 2" + (org-end-of-subtree) + (forward-line 0) + (should (looking-at-p "^asd")))) + (let ((org-inlinetask-min-level 3)) + (org-test-with-temp-text + " +* Heading +some text +*** Inlinetask +t +*** END +*** Inlinetask2 +** Sub1 +** Sub 2 +asd +* Heading 2" + (org-end-of-subtree nil nil (org-element-at-point)) + (forward-line 0) + (should (looking-at-p "^asd")))) + ;; Before first heading. + (org-test-with-temp-text + " +Some text. +* Heading +** Sub1 +** Sub 2 +asd +* Heading 2 +text" + (org-end-of-subtree) + (should (eobp))) + (org-test-with-temp-text + " +Some text. +* Heading +** Sub1 +** Sub 2 +asd +* Heading 2" + (org-end-of-subtree) + (should (eobp))) + (org-test-with-temp-text + " +Some text. +* Heading +** Sub1 +** Sub 2 +asd +* Heading 2 +" + (org-end-of-subtree) + ;; This is tricky. Users may or may not want moving to a heading + ;; May need to be re-considered. + (should (equal (point) (1- (point-max))))) + (org-test-with-temp-text + " +Some text. +* Heading +** Sub1 +** Sub 2 +asd +* Heading 2 + + +" + (org-end-of-subtree) + (forward-line 0) + (should (looking-at-p "^\\* Heading 2"))) + ;; TO-HEADING before first heading. + (org-test-with-temp-text + " +Some text. +* Heading +** Sub1 +** Sub 2 +asd +* Heading 2 + + +" + (org-end-of-subtree nil t) + (should (eobp))) + (org-test-with-temp-text + " +Some text. +* Heading +** Sub1 +** Sub 2 +asd +* Heading 2" + (org-end-of-subtree nil t) + (should (eobp))) + ;; Honor visibility. + (org-test-with-temp-text + " +* Heading +** Sub1 +*** Subsub +text +** Sub 2 +asd +* Heading 2" + (org-overview) + (org-end-of-subtree nil t) + ;; Current subtree is fully hidden. Jump to the end of the first + ;; visible subtree. + (should (looking-at-p "^\\* Heading 2")))) + (ert-deftest test-org/shiftright-heading () "Test `org-shiftright' on headings." (let ((org-todo-keywords '((sequence "TODO" "DONE"))))