From 680210c64545389502e7a2d05ec0c98e7b25c24b Mon Sep 17 00:00:00 2001 From: "Paul W. Rankin" Date: Tue, 17 Nov 2020 12:44:44 +1000 Subject: [PATCH 2/2] * lisp/outline.el: avoid hiding all buffer content (outline-cycle-buffer): check that buffer has top-level headings before calling outline-hide-sublevels 1 thus preventing disconcerting buffer state of content reduced to single "..." --- lisp/outline.el | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/lisp/outline.el b/lisp/outline.el index 8cc8a3cd89..9b11b86b9d 100644 --- a/lisp/outline.el +++ b/lisp/outline.el @@ -1173,20 +1173,30 @@ outline--cycle-buffer-state (defun outline-cycle-buffer () "Cycle the whole buffer like in `outline-cycle'." (interactive) - (pcase outline--cycle-buffer-state - ('show-all - (outline-hide-sublevels 1) - (setq outline--cycle-buffer-state 'top-level) - (message "Top level headings")) - ('top-level - (outline-show-all) - (outline-hide-region-body (point-min) (point-max)) - (setq outline--cycle-buffer-state 'all-heading) - (message "All headings")) - ('all-heading - (outline-show-all) - (setq outline--cycle-buffer-state 'show-all) - (message "Show all")))) + (let (has-top-level) + (save-excursion + (goto-char (point-min)) + (while (not (or has-top-level (eobp))) + (when (outline-on-heading-p t) + (when (= (funcall outline-level) 1) + (setq has-top-level t))) + (outline-next-heading))) + (cond + ((and (eq outline--cycle-buffer-state 'show-all) + has-top-level) + (outline-hide-sublevels 1) + (setq outline--cycle-buffer-state 'top-level) + (message "Top level headings")) + ((or (eq outline--cycle-buffer-state 'show-all) + (eq outline--cycle-buffer-state 'top-level)) + (outline-show-all) + (outline-hide-region-body (point-min) (point-max)) + (setq outline--cycle-buffer-state 'all-heading) + (message "All headings")) + (t + (outline-show-all) + (setq outline--cycle-buffer-state 'show-all) + (message "Show all"))))) (provide 'outline) (provide 'noutline) -- 2.29.2