From 18a146a9d588ce31b1081371d0a1ed9d8c57cce1 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Fri, 17 Feb 2023 14:58:32 +0300 Subject: [PATCH] org-fold-core-previous-visibility-change: Fix edge case * lisp/org-fold-core.el (org-fold-core-next-visibility-change): Take into account that `previous-single-char-property-change' move the point to the first position where the property is still unchanged. * lisp/org-cycle.el (org-cycle-set-visibility-according-to-property): Ignore invisibility when skipping subtree. Reported-by: Philipp Kiefer Link: https://orgmode.org/list/96becf12-9a5a-2fc2-0105-a41528be1f66@gmail.com --- lisp/org-cycle.el | 2 +- lisp/org-fold-core.el | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lisp/org-cycle.el b/lisp/org-cycle.el index 90fc95f41..fafcfd797 100644 --- a/lisp/org-cycle.el +++ b/lisp/org-cycle.el @@ -658,7 +658,7 @@ With a numeric prefix, show all headlines up to that level." ((or "all" "showall") (org-fold-show-subtree)) (_ nil))) - (org-end-of-subtree))))))) + (org-end-of-subtree t))))))) (defun org-cycle-overview () "Switch to overview mode, showing only top-level headlines." diff --git a/lisp/org-fold-core.el b/lisp/org-fold-core.el index 027ff9215..43c6b2b74 100644 --- a/lisp/org-fold-core.el +++ b/lisp/org-fold-core.el @@ -835,13 +835,20 @@ If PREVIOUS-P is non-nil, search backwards." (next-change (if previous-p (if ignore-hidden-p (lambda (p) (org-fold-core-previous-folding-state-change (org-fold-core-get-folding-spec nil p) p limit)) - (lambda (p) (max limit (1- (previous-single-char-property-change p 'invisible nil limit))))) + (lambda (p) (max limit (previous-single-char-property-change p 'invisible nil limit)))) (if ignore-hidden-p (lambda (p) (org-fold-core-next-folding-state-change (org-fold-core-get-folding-spec nil p) p limit)) (lambda (p) (next-single-char-property-change p 'invisible nil limit))))) (next pos)) (while (and (funcall cmp next limit) - (not (org-xor invisible-initially? (funcall invisible-p next)))) + (not (org-xor + invisible-initially? + (funcall invisible-p + (if previous-p + ;; NEXT-1 -> NEXT is the change. + (max limit (1- next)) + ;; NEXT -> NEXT+1 is the change. + next))))) (setq next (funcall next-change next))) next))