diff --git a/lisp/org.el b/lisp/org.el index 6aa2a1621..ab8b76b92 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20213,7 +20213,10 @@ interactive command with similar behavior." (defun org-back-to-heading (&optional invisible-ok) "Go back to beginning of heading." (beginning-of-line) - (or (org-at-heading-p (not invisible-ok)) + (or (and (org-at-heading-p (not invisible-ok)) + (not (and (featurep 'org-inlinetask) + (fboundp 'org-inlinetask-end-p) + (org-inlinetask-end-p)))) (if (org-element--cache-active-p) (let ((heading (org-element-lineage (org-element-at-point) '(headline inlinetask) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 47cb8d881..f999189aa 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -2281,6 +2281,48 @@ CLOCK: [2022-09-17 sam. 11:00]--[2022-09-17 sam. 11:46] => 0:46" ;;; Headline +(ert-deftest test-org/org-back-to-heading () + "Test `org-back-to-heading' specifications." + ;; On heading already + (org-test-with-temp-text "* Heading" + (org-back-to-heading) + (should (bobp))) + ;; Below heading + (org-test-with-temp-text "* Heading +Text" + (org-back-to-heading) + (should (bobp))) + ;; At inlinetask + (let ((org-inlinetask-min-level 3)) + (org-test-with-temp-text "* Heading +*** Inlinetask " + (org-back-to-heading) + (should (= 11 (point))))) + ;; Below inlinetask + (let ((org-inlinetask-min-level 3)) + (org-test-with-temp-text "* Heading +*** Inlinetask +Test " + (org-back-to-heading) + ;; Not at or inside inlinetask. Move to parent heading. + (should (bobp)))) + ;; Inside inlinetask + (let ((org-inlinetask-min-level 3)) + (org-test-with-temp-text "* Heading +*** Inlinetask +Test +*** END" + (org-back-to-heading) + (should (= 11 (point))))) + ;; At END + (let ((org-inlinetask-min-level 3)) + (org-test-with-temp-text "* Heading +*** Inlinetask +Test +*** END" + (org-back-to-heading) + (should (= 11 (point)))))) + (ert-deftest test-org/get-heading () "Test `org-get-heading' specifications." ;; Return current heading, even if point is not on it.