From: Paul Nelson <ultrono@gmail.com>
To: 73286@debbugs.gnu.org
Subject: bug#73286: [PATCH] Add foldout command for widening to current fold
Date: Mon, 16 Sep 2024 01:38:35 +0200 [thread overview]
Message-ID: <CAOA-32N5qEVkJh9vuZO=WvPHX_M0h+_gBKG92hbaC1HpDDRTHw@mail.gmail.com> (raw)
[-- 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)
next reply other threads:[~2024-09-15 23:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-15 23:38 Paul Nelson [this message]
2024-09-28 9:01 ` bug#73286: [PATCH] Add foldout command for widening to current fold 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
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='CAOA-32N5qEVkJh9vuZO=WvPHX_M0h+_gBKG92hbaC1HpDDRTHw@mail.gmail.com' \
--to=ultrono@gmail.com \
--cc=73286@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).