Laurenz Wiskott <laurenz.wisk...@rub.de> writes: > There is one feature however that I really miss: It used to be that I could > add an entry > with a certain number of stars in the first line, and then 'org-global-cycle' > using S-TAB > would allow to make all the headlines visible only up to that many stars. > For instance, > a file with > > > *** - > * 1 > ... > after one or two S-TAB (depending on the initial folding state) would look > like > > *** - > * 1 > ** 2 > *** 3 > > without the 4-star headline visible. If I remove one star in the first line > and type > S-TAB once or twice, then it looks like > > ** - > * 1 > ** 2 > > I found that a convenient way of controlling the depth of the CONTENT view (I > believe it > is called). That does not work any more. Typing S-TAB once or twice leads > to the > CONTENTS view that shows all headlines, no matter how many stars and > independently of the > first line.
This was not documented and caused by implementation detail. > Here is an example for 'org-cycle' > > * 1 > *** - > ** A > *** Aa > ... > Typing TAB once or twice (depending on the initial folding state) on the main > headline (* > 1) yields the view: > > * 1 > *** - > ** A > *** Aa > ** B > *** Ba It is a bug in `org-fold-show-children'. The reason your example works has nothing to do with what the function intends to do. Fix is attached.
>From a5e8062b258fc7c4e4d4129278101a8d20bb43c4 Mon Sep 17 00:00:00 2001 Message-Id: <a5e8062b258fc7c4e4d4129278101a8d20bb43c4.1675855848.git.yanta...@posteo.net> From: Ihor Radchenko <yanta...@posteo.net> Date: Wed, 8 Feb 2023 14:29:30 +0300 Subject: [PATCH] org-fold-show-children: Only display direct children by default * lisp/org-fold.el (org-fold-show-children): Clarify the docstring emphasizing that direct children are always displayed. Fix grandchildren being displayed when the first child has deeper level than the next children. --- lisp/org-fold.el | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lisp/org-fold.el b/lisp/org-fold.el index 1b7ca22b0..f9c604155 100644 --- a/lisp/org-fold.el +++ b/lisp/org-fold.el @@ -419,20 +419,21 @@ (defun org-fold-show-siblings () (defun org-fold-show-children (&optional level) "Show all direct subheadings of this heading. -Prefix arg LEVEL is how many levels below the current level -should be shown. Default is enough to cause the following -heading to appear." +Prefix arg LEVEL is how many levels below the current level should be +shown. If direct subheadings are deeper than LEVEL, they are still +displayed." (interactive "p") (unless (org-before-first-heading-p) (save-excursion (org-with-limited-levels (org-back-to-heading t)) (let* ((current-level (funcall outline-level)) + (parent-level current-level) (max-level (org-get-valid-level - current-level + parent-level (if level (prefix-numeric-value level) 1))) + (min-level-direct-child most-positive-fixnum) (end (save-excursion (org-end-of-subtree t t))) (regexp-fmt "^\\*\\{%d,%s\\}\\(?: \\|$\\)") - (past-first-child nil) ;; Make sure to skip inlinetasks. (re (format regexp-fmt current-level @@ -448,11 +449,12 @@ (defun org-fold-show-children (&optional level) ;; MAX-LEVEL. Since we want to display it anyway, adjust ;; MAX-LEVEL accordingly. (while (re-search-forward re end t) - (unless past-first-child - (setq re (format regexp-fmt - current-level - (max (funcall outline-level) max-level))) - (setq past-first-child t)) + (setq current-level (funcall outline-level)) + (when (< current-level min-level-direct-child) + (setq min-level-direct-child current-level + re (format regexp-fmt + parent-level + (max min-level-direct-child max-level)))) (org-fold-heading nil)))))) (defun org-fold-show-subtree () -- 2.39.1
-- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at <https://orgmode.org/>. Support Org development at <https://liberapay.com/org-mode>, or support my work at <https://liberapay.com/yantar92>