diff --git a/lisp/org.el b/lisp/org.el index 89cc8bdd9..33d90506b 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -21248,14 +21248,15 @@ With argument, move up ARG levels." (defun org-up-heading-safe () "Move to the heading line of which the present line is a subheading. -Return the heading level, as number or nil when there is no such heading. +Return the true heading level, as number or nil when there is no such +heading. When point is not at heading, go to the parent of the current heading. When point is at or inside an inlinetask, go to the containing heading. -This version will not throw an error. It will return the level of the -headline found, or nil if no higher level is found. +This version will not throw an error. It will return the true level +of the headline found, or nil if no higher level is found. When no higher level is found, the still move point to the containing heading, if there is any in the accessible portion of the buffer. @@ -21271,7 +21272,7 @@ available portion of the buffer." (<= (point-min) (org-element-begin parent))) (progn (goto-char (org-element-begin parent)) - (org-element-property :level parent)) + (org-element-property :true-level parent)) (when (and current-heading (<= (point-min) (org-element-begin current-heading))) (goto-char (org-element-begin current-heading)) diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 830d0aaa3..cecf9b412 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -2458,6 +2458,13 @@ Test ** H2" (should (= 1 (org-up-heading-safe))) (should (looking-at-p "^\\* H1"))) + ;; Return true level. Ignore `org-odd-levels-only'. + (let ((org-odd-levels-only t)) + (org-test-with-temp-text " +*** H1 +***** H2" + (should (= 3 (org-up-heading-safe))) + (should (looking-at-p "^\\*\\{3\\} H1")))) ;; Do not jump beyond the level 1 heading. (org-test-with-temp-text " Text.