all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#73286: [PATCH] Add foldout command for widening to current fold
@ 2024-09-15 23:38 Paul Nelson
  2024-09-28  9:01 ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Paul Nelson @ 2024-09-15 23:38 UTC (permalink / raw)
  To: 73286

[-- Attachment #1: Type: text/plain, Size: 630 bytes --]

The foldout package, which "zooms in" on document sections by
narrowing the buffer, doesn't play well with Emacs's other narrowing
features: after narrowing further within a fold, there's no easy way
to widen back to the fold's boundaries.

This patch introduces foldout-widen-to-current-fold, a command that
widens to the current fold level (or to the whole buffer if not in a
fold).

Example usage:
- Use foldout-zoom-subtree to zoom in on some section.
- Use narrow-to-defun to edit some function.
- Use foldout-widen-to-current-fold to return to the scope of the
zoomed-in section.

Any feedback welcome.

Thanks, best,

Paul

[-- Attachment #2: 0001-Add-foldout-command-for-widening-to-current-fold.patch --]
[-- Type: application/octet-stream, Size: 3659 bytes --]

From 97e97799eb69e7339e24b4e6e2b2911cb32bc910 Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@gmail.com>
Date: Mon, 16 Sep 2024 01:33:53 +0200
Subject: [PATCH] Add foldout command for widening to current fold

* lisp/foldout.el (foldout-widen-to-current-fold): New command.
(foldout-inhibit-key-bindings): Bind it.
* doc/emacs/text.texi (Foldout): Document it.
* etc/NEWS: Announce it.
---
 doc/emacs/text.texi |  9 +++++++++
 etc/NEWS            |  8 ++++++++
 lisp/foldout.el     | 19 ++++++++++++++++++-
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi
index 9bc2a6407d5..6e304f3b8f6 100644
--- a/doc/emacs/text.texi
+++ b/doc/emacs/text.texi
@@ -1396,6 +1396,15 @@ Foldout
 subheadings, specify a negative argument.  For example, @w{@kbd{M--2 C-c
 C-x}} exits two folds and leaves the text and subheadings exposed.
 
+@kindex C-x n w
+@findex foldout-widen-to-current-fold
+  While working within a fold, you may wish to use Emacs's standard
+narrowing commands such as @kbd{C-x n n} (@code{narrow-to-region}) or
+@kbd{C-x n d} (@code{narrow-to-defun}).  After using these commands,
+@kbd{C-c C-w} (@code{foldout-widen-to-current-fold}) allows you to
+widen back to the current fold level, rather than the entire buffer.
+If you're not currently in a fold, it behaves like @code{widen}.
+
   Foldout mode also provides mouse commands for entering and exiting
 folds, and for showing and hiding text:
 
diff --git a/etc/NEWS b/etc/NEWS
index 492159439fc..86a77f0b827 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -359,6 +359,14 @@ functionality of the standard 'xref' commands in TeX buffers.  You can
 restore the standard 'etags' backend with the 'M-x xref-etags-mode'
 toggle.
 
+** Foldout
+
+---
+*** New command 'foldout-widen-to-current-fold'.
+This command widens the view to the current fold level when in a fold,
+or behaves like 'widen' if not in a fold.  It's bound to 'C-w' in
+the Outline minor mode map.
+
 \f
 * New Modes and Packages in Emacs 31.1
 
diff --git a/lisp/foldout.el b/lisp/foldout.el
index 5799318fc6f..3c732e8b67c 100644
--- a/lisp/foldout.el
+++ b/lisp/foldout.el
@@ -490,6 +490,21 @@ foldout-mouse-goto-heading
       (error "Not a heading line")))
 \f
 
+(defun foldout-widen-to-current-fold ()
+  "Widen to the current fold level.
+If in a fold, widen to that fold's boundaries.
+If not in a fold, acts like `widen'."
+  (interactive)
+  (if foldout-fold-list
+      (let* ((last-fold (car foldout-fold-list))
+             (start (car last-fold))
+             (end (cdr last-fold)))
+        (widen)
+        (narrow-to-region start
+                          (if end (1- (marker-position end)) (point-max))))
+    (widen)))
+\f
+
 ;;; Keymaps:
 
 (defvar foldout-inhibit-key-bindings nil
@@ -506,12 +521,14 @@ foldout-mouse-modifiers
 (unless foldout-inhibit-key-bindings
   (define-key outline-mode-map "\C-c\C-z" #'foldout-zoom-subtree)
   (define-key outline-mode-map "\C-c\C-x" #'foldout-exit-fold)
+  (define-key outline-mode-map "\C-c\C-w" #'foldout-widen-to-current-fold)
   (let ((map (lookup-key outline-minor-mode-map outline-minor-mode-prefix)))
     (unless map
       (setq map (make-sparse-keymap))
       (define-key outline-minor-mode-map outline-minor-mode-prefix map))
     (define-key map "\C-z" #'foldout-zoom-subtree)
-    (define-key map "\C-x" #'foldout-exit-fold))
+    (define-key map "\C-x" #'foldout-exit-fold)
+    (define-key map "\C-w" #'foldout-widen-to-current-fold))
   (let* ((modifiers (apply #'concat
                            (mapcar (lambda (modifier)
                                      (vector
-- 
2.39.3 (Apple Git-145)


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

end of thread, other threads:[~2024-10-12 11:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-15 23:38 bug#73286: [PATCH] Add foldout command for widening to current fold Paul Nelson
2024-09-28  9:01 ` Eli Zaretskii
2024-10-01  9:46   ` Paul Nelson
2024-10-01 18:50   ` Andrea Corallo
2024-10-01 19:33     ` Stefan Kangas
2024-10-05 10:20       ` Eli Zaretskii
2024-10-05 11:14         ` Paul Nelson
2024-10-12 11:53           ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.