From: Augusto Stoffel <arstoffel@gmail.com>
To: 57672@debbugs.gnu.org
Subject: bug#57672: [PATCH] Add prefix argument to outline-cycle-buffer
Date: Thu, 08 Sep 2022 11:15:21 +0200 [thread overview]
Message-ID: <874jxii5w6.fsf@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 198 bytes --]
Tags: patch
Similar org-mode, this allows showing only headings up to a given level.
Also, handle the edge case where the lowest outline level is bigger than
1, where previously we just gave up.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-prefix-argument-to-outline-cycle-buffer.patch --]
[-- Type: text/patch, Size: 2579 bytes --]
From 6ca5337a986fea7252a81887827e6c451fd8a9e9 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@gmail.com>
Date: Thu, 8 Sep 2022 09:56:59 +0200
Subject: [PATCH] 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 178cbe3071..f09481f7ea 100644
--- a/lisp/outline.el
+++ b/lisp/outline.el
@@ -1581,7 +1581,7 @@ outline-cycle
(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
@@ -1590,20 +1590,28 @@ outline-cycle-buffer
`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)
--
2.37.3
next reply other threads:[~2022-09-08 9:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-08 9:15 Augusto Stoffel [this message]
2022-09-08 12:40 ` bug#57672: [PATCH] Add prefix argument to outline-cycle-buffer Lars Ingebrigtsen
2022-09-08 17:34 ` Juri Linkov
2022-09-08 17:54 ` Augusto Stoffel
2022-09-08 19:36 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874jxii5w6.fsf@gmail.com \
--to=arstoffel@gmail.com \
--cc=57672@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).