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))