diff --git a/lisp/org.el b/lisp/org.el index 93101e6b8..27b7fbf79 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20637,7 +20637,7 @@ point before the first headline or at point-min." (< l level))))) (defun org-goto-sibling (&optional previous) - "Goto the next sibling, even if it is invisible. + "Goto the next sibling heading, even if it is invisible. When PREVIOUS is set, go to the previous sibling instead. Returns t when a sibling was found. When none is found, return nil and don't move point." @@ -20646,6 +20646,8 @@ move point." (re org-outline-regexp-bol) level l) (when (ignore-errors (org-back-to-heading t)) + (when (org-element-type-p (org-element-at-point) 'inlinetask) + (org-up-heading-safe)) (setq level (funcall outline-level)) (catch 'exit (or previous (forward-char 1)) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 50c9968a3..3a6c12025 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -2449,6 +2449,65 @@ Text. (should-not (org-up-heading-safe)) (should (looking-at-p "^\\*\\* H2")))) +(ert-deftest test-org/goto-sibling () + "Test `org-goto-sibling' specifications." + (org-test-with-temp-text + "* Parent +** Heading 1 +** Heading 2 +** Heading 3" + (should (org-goto-sibling)) + (should (looking-at-p "^\\*\\* Heading 3")) + (should-not (org-goto-sibling)) + (should (org-goto-sibling 'previous)) + (should (looking-at-p "^\\*\\* Heading 2")) + (should (org-goto-sibling 'previous)) + (should (looking-at-p "^\\*\\* Heading 1")) + (should-not (org-goto-sibling 'previous))) + ;; Inside heading. + (org-test-with-temp-text + "* Parent +** Heading 1 +** Heading 2 +Some text. +** Heading 3" + (should (org-goto-sibling)) + (should (looking-at-p "^\\*\\* Heading 3"))) + (org-test-with-temp-text + "* Parent +** Heading 1 +** Heading 2 +Some text. +** Heading 3" + (should (org-goto-sibling 'previous)) + (should (looking-at-p "^\\*\\* Heading 1"))) + (org-test-with-temp-text + "* Parent +** Heading 2 +Some text. +" + (should-not (org-goto-sibling)) + (should-not (org-goto-sibling 'previous))) + ;; Ignore inlinetasks. + (let ((org-inlinetask-min-level 3)) + (org-test-with-temp-text + "* Parent +** Heading 1 +** Heading 2 +*** Inlinetask 1 +test +*** END +*** Inlinetask 2 +** Heading 3" + (should (org-goto-sibling)) + (should (looking-at-p "^\\*\\* Heading 3")) + (should-not (org-goto-sibling)) + (should (org-goto-sibling 'previous)) + (should (looking-at-p "^\\*\\* Heading 2")) + (should (org-goto-sibling 'previous)) + (should (looking-at-p "^\\*\\* Heading 1")) + (should-not (org-goto-sibling 'previous))))) + (ert-deftest test-org/get-heading () "Test `org-get-heading' specifications." ;; Return current heading, even if point is not on it.