]> git.eshelyaron.com Git - emacs.git/commitdiff
Add foldout command for widening to current fold
authorPaul Nelson <ultrono@gmail.com>
Sun, 15 Sep 2024 23:33:53 +0000 (01:33 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 14 Oct 2024 17:39:36 +0000 (19:39 +0200)
* lisp/foldout.el (foldout-widen-to-current-fold): New command.
* doc/emacs/text.texi (Foldout): Document it.
* etc/NEWS: Announce it.  (Bug#73286)

(cherry picked from commit ebfd5874f0b74cec06572ffc3e9bf7288bd5e77b)

doc/emacs/text.texi
etc/NEWS
lisp/foldout.el

index 9bc2a6407d55a3df8eb732f3a78061299239c717..a6d19a32bc5e0b4ea0619b9201a7854dbd48b7fc 100644 (file)
@@ -1396,6 +1396,14 @@ exits all folds.
 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.
 
+@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,
+@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:
 
index 6646d253c949344368e0964a73599e226910b92d..392eb5cc5a3c4993f833968464f26506f29429e2 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -470,6 +470,13 @@ exist.  If "python" points to Python 2 on your system, you now have to
 customize these variables to "python3" if you want to use Python 3
 instead.
 
+** 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.
+
 \f
 * New Modes and Packages in Emacs 31.1
 
index 5799318fc6fb910791b2ef0256ccde129eba0cf9..a4b6a402c5c80b18678522bdadd2bda46226f6fc 100644 (file)
@@ -490,6 +490,21 @@ Signal an error if the event didn't occur on a 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