[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master f10645d260: Add prefix argument to outline-cycle-buffer
From: |
Lars Ingebrigtsen |
Subject: |
master f10645d260: Add prefix argument to outline-cycle-buffer |
Date: |
Thu, 8 Sep 2022 08:40:38 -0400 (EDT) |
branch: master
commit f10645d26029523e8d7520b266ac7e04d8794e50
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Add prefix argument to outline-cycle-buffer
* lisp/outline.el (outline-cycle-buffer): Add prefix argument to show
headings up to a given level. Handle the case where the top
heading level is not 1.
---
lisp/outline.el | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/lisp/outline.el b/lisp/outline.el
index 9a94cad638..6579e12bfe 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1582,7 +1582,7 @@ and body between `hide all', `headings only' and `show
all'.
(defvar-local outline--cycle-buffer-state 'show-all
"Internal variable used for tracking buffer cycle state.")
-(defun outline-cycle-buffer ()
+(defun outline-cycle-buffer (&optional level)
"Cycle visibility state of the body lines of the whole buffer.
This cycles the visibility of all the subheadings and bodies of all
@@ -1591,20 +1591,28 @@ the heading lines in the buffer. It cycles them
between `hide all',
`Hide all' means hide all the buffer's subheadings and their bodies.
`Headings only' means show all the subheadings, but not their bodies.
-`Show all' means show all the buffer's subheadings and their bodies."
- (interactive)
- (let (has-top-level)
+`Show all' means show all the buffer's subheadings and their bodies.
+
+With a prefix argument, show headings up to that LEVEL."
+ (interactive (list (when current-prefix-arg
+ (prefix-numeric-value current-prefix-arg))))
+ (let (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)))
+ (while (not (or (eq top-level 1) (eobp)))
+ (when-let ((level (and (outline-on-heading-p t)
+ (funcall outline-level))))
+ (when (< level (or top-level most-positive-fixnum))
+ (setq top-level (max level 1))))
(outline-next-heading)))
(cond
+ (level
+ (outline-hide-sublevels level)
+ (setq outline--cycle-buffer-state 'all-heading)
+ (message "All headings up to level %s" level))
((and (eq outline--cycle-buffer-state 'show-all)
- has-top-level)
- (outline-hide-sublevels 1)
+ top-level)
+ (outline-hide-sublevels top-level)
(setq outline--cycle-buffer-state 'top-level)
(message "Top level headings"))
((or (eq outline--cycle-buffer-state 'show-all)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master f10645d260: Add prefix argument to outline-cycle-buffer,
Lars Ingebrigtsen <=