From dad436c60bb9fe92382cf43921fada4bd75d5414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20Wikstr=C3=B6m?= Date: Thu, 5 Nov 2020 00:42:01 +0100 Subject: [PATCH] Make `org-goto-first-child' behave intuitively before first heading * lisp/org.el (org-goto-first-child): Make it understand outline level 0 as well. The function now behaves intuitively also before first heading. --- etc/ORG-NEWS | 12 ++++++++++++ lisp/org.el | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 7f935bf52..60bff5268 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -88,6 +88,18 @@ package, to convert pandas Dataframes into orgmode tables: | 2 | 3 | 6 | #+end_src +** Miscellaneous +*** =org-goto-first-child= now works before first heading + +When point is before first heading =org-goto-first-child= will move +point to the first child heading, or return nil if no heading exist +in buffer. This is in line with the fact that everything before first +heading is regarded as outline level 0, i.e. the parent level of all +headings in the buffer. + +Previously =org-goto-first-child= would do nothing before first +heading, except return nil. + * Version 9.4 ** Incompatible changes *** Possibly broken internal file links: please check and fix diff --git a/lisp/org.el b/lisp/org.el index 875044a3e..9a13f03d6 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20427,10 +20427,10 @@ move point." Return t when a child was found. Otherwise don't move point and return nil." (let (level (pos (point)) (re org-outline-regexp-bol)) - (when (ignore-errors (org-back-to-heading t)) - (setq level (outline-level)) + (when (org-back-to-heading-or-point-min t) + (setq level (org-outline-level)) (forward-char 1) - (if (and (re-search-forward re nil t) (> (outline-level) level)) + (if (and (re-search-forward re nil t) (> (org-outline-level) level)) (progn (goto-char (match-beginning 0)) t) (goto-char pos) nil))))