From 6ef0154576158d080518c8ac556798eed71030d8 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Thu, 29 Feb 2024 14:36:26 +0300 Subject: [PATCH] org-up-heading-safe: Return true level, ignoring org-odd-levels-only * lisp/org.el (org-up-heading-safe): Fix return value, making sure that the returned level is not reduced. This is what other code expects and what used to be the case before refactoring, in previous version of the function. * testing/lisp/test-org.el (test-org/up-heading-safe): Add test. Reported-by: E.L.K. Link: https://orgmode.org/list/CAF+cOoPuh8rzVRoV9-pGSP3SVRm-M8ZQrM=xGB+o4TqJat_O-A@mail.gmail.com --- lisp/org.el | 9 +++++---- testing/lisp/test-org.el | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) 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.