org-goto-sibling: Fix when called from inlinetask

* lisp/org.el (org-goto-sibling): Do not try to find inlinetask
siblings.  Clarify the docstring.
* testing/lisp/test-org.el (test-org/goto-sibling): New test.
This commit is contained in:
Ihor Radchenko 2023-08-02 16:06:02 +03:00
parent 345d4e09b5
commit 63e8cac2ca
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 62 additions and 1 deletions

View File

@ -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))

View File

@ -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 <point>
** 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.<point>
** Heading 3"
(should (org-goto-sibling))
(should (looking-at-p "^\\*\\* Heading 3")))
(org-test-with-temp-text
"* Parent
** Heading 1
** Heading 2
Some text.<point>
** Heading 3"
(should (org-goto-sibling 'previous))
(should (looking-at-p "^\\*\\* Heading 1")))
(org-test-with-temp-text
"* Parent
** Heading 2
Some text.<point>
"
(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 <point>
*** 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.