The recursive-narrow package
https://github.com/nflath/recursive-narrow/tree/master
Thanks to @maxfriis for bringing it to my attention
What is it?
The recursive-narrow package is an enhancement of the native Emacs narrowing functionality, which allows users to focus on a specific part of a document or buffer, hiding the rest.
What does it do?
It extends the built-in narrowing capabilities by allowing for recursive narrowing. This means you can narrow down to a specific part of a document, and then within that narrowed view, you can narrow down further to an even more specific part. This recursive approach enables a more focused and granular level of working with documents or code.
Why would you want it?
recursive-narrow
helps reduce clutter and distractions, making it easier to read or edit specific parts of your files.
How does it work?
(require 'recursive-narrow)
What are the Main Commands?
recursive-widen (C-x n w)
recursive-narrow-to-defun
recursive-narrow-to-region
recursive-narrow-or-widen-dwim (C-x n n)
Example
(defun recursive-narrow-or-widen-dwim () "If the region is active, narrow to that region. Otherwise, narrow to the current function. If this has no effect, widen the buffer. You can add more functions to `recursive-narrow-dwim-functions'." (interactive) (recursive-narrow-save-position (cond ((region-active-p) (narrow-to-region (region-beginning) (region-end))) ((run-hook-with-args-until-success 'recursive-narrow-dwim-functions)) ((derived-mode-p 'prog-mode) (narrow-to-defun)) ((derived-mode-p 'org-mode) (org-narrow-to-subtree))) ;; If we don't narrow (progn (message "Recursive settings: %d" (length recursive-narrow-settings)) (recursive-widen))))