unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#57672: [PATCH] Add prefix argument to outline-cycle-buffer
@ 2022-09-08  9:15 Augusto Stoffel
  2022-09-08 12:40 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Augusto Stoffel @ 2022-09-08  9:15 UTC (permalink / raw)
  To: 57672

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#57672: [PATCH] Add prefix argument to outline-cycle-buffer
  2022-09-08  9:15 bug#57672: [PATCH] Add prefix argument to outline-cycle-buffer Augusto Stoffel
@ 2022-09-08 12:40 ` Lars Ingebrigtsen
  2022-09-08 17:34   ` Juri Linkov
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-08 12:40 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: 57672

Augusto Stoffel <arstoffel@gmail.com> writes:

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

Thanks; pushed to Emacs 29.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#57672: [PATCH] Add prefix argument to outline-cycle-buffer
  2022-09-08 12:40 ` Lars Ingebrigtsen
@ 2022-09-08 17:34   ` Juri Linkov
  2022-09-08 17:54     ` Augusto Stoffel
  0 siblings, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2022-09-08 17:34 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 57672, Augusto Stoffel

>> 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.
>
> Thanks; pushed to Emacs 29.

Nice feature, but doesn't work in emacs-lisp-mode with outline-minor-mode.
OTOH, 'C-5 C-c @ C-q' neither, so perhaps a bug is in outline-hide-sublevels.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#57672: [PATCH] Add prefix argument to outline-cycle-buffer
  2022-09-08 17:34   ` Juri Linkov
@ 2022-09-08 17:54     ` Augusto Stoffel
  2022-09-08 19:36       ` Juri Linkov
  0 siblings, 1 reply; 5+ messages in thread
From: Augusto Stoffel @ 2022-09-08 17:54 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Lars Ingebrigtsen, 57672

On Thu,  8 Sep 2022 at 20:34, Juri Linkov <juri@linkov.net> wrote:

> Nice feature, but doesn't work in emacs-lisp-mode with outline-minor-mode.
> OTOH, 'C-5 C-c @ C-q' neither, so perhaps a bug is in outline-hide-sublevels.

Hum, it works for me.  Since your elisp file probably doesn't have that
many levels, and toplevel forms have level 1000, 'C-5 C-c @ C-q' or 'C-5
M-x outline-cycle-buffer RET' will display the full comment outline but
hide the toplevel forms --- which is something I want to do from time to
time.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#57672: [PATCH] Add prefix argument to outline-cycle-buffer
  2022-09-08 17:54     ` Augusto Stoffel
@ 2022-09-08 19:36       ` Juri Linkov
  0 siblings, 0 replies; 5+ messages in thread
From: Juri Linkov @ 2022-09-08 19:36 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: Lars Ingebrigtsen, 57672

>> Nice feature, but doesn't work in emacs-lisp-mode with outline-minor-mode.
>> OTOH, 'C-5 C-c @ C-q' neither, so perhaps a bug is in outline-hide-sublevels.
>
> Hum, it works for me.  Since your elisp file probably doesn't have that
> many levels, and toplevel forms have level 1000, 'C-5 C-c @ C-q' or 'C-5
> M-x outline-cycle-buffer RET' will display the full comment outline but
> hide the toplevel forms --- which is something I want to do from time to
> time.

Thanks, 'C-999 S-TAB' doesn't show toplevel forms, but 'C-1000 S-TAB' does.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-08 19:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-08  9:15 bug#57672: [PATCH] Add prefix argument to outline-cycle-buffer Augusto Stoffel
2022-09-08 12:40 ` Lars Ingebrigtsen
2022-09-08 17:34   ` Juri Linkov
2022-09-08 17:54     ` Augusto Stoffel
2022-09-08 19:36       ` Juri Linkov

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