[comp.emacs] interactive recursive narrowing

MANSFIEL@EMBL.BITNET (Niall Mansfield) (06/30/87)

The standard GNU Emacs "narrow-to-region" and "widen" allow
for only one-or-none narrowing - i.e. you're narrowed or
not.

Often I would have found it helpful to have recursive
narrowing.  Is there any way to do this?

(An example: when I'm already narrowed to a particular
function in a source program, I would like to restrict
further to a particular part of that function for some
operation, and when I am finished I'd like "widen" to undo
just the top level restriction, leaving me still narrowed to
the whole function).

Niall

ardis@wanginst.EDU (Mark A. Ardis) (07/06/87)

In article <8707021017.AA21039@EDDIE.MIT.EDU>, MANSFIEL@EMBL.BITNET (Niall Mansfield) writes:
> 
> The standard GNU Emacs "narrow-to-region" and "widen" allow
> for only one-or-none narrowing - i.e. you're narrowed or
> not.
> 
> Often I would have found it helpful to have recursive
> narrowing.  Is there any way to do this?

Try this:

;;; recursive-narrow.el -- recursive narrowing
;;; Mark A. Ardis, July 6, 1987

(defun recursive-narrow (start stop)
  "Narrow to the region between START and STOP, invoke recursive-edit
   to allow further editing, then widen to the previous restriction."
  (interactive "r")
					; Local Variables
  (let ()
					; Body
    (save-restriction
      (narrow-to-region start stop)
      (recursive-edit)
      (widen)
      ) ; save-restriction
    ) ; let
  ) ; defun recursive-narrow

;;; end of recursive-narrow.el
-- 
Mark A. Ardis                           ardis%wanginst@CSNet-Relay (CSNet)
Wang Institute of Graduate Studies      ...!decvax!wanginst!ardis (UUCP)
72 Tyng Road, Tyngsboro, MA 01879-2099  (617) 649-9731

rbj@ICST-CMR.ARPA (Root Boy Jim) (07/06/87)

? 
? The standard GNU Emacs "narrow-to-region" and "widen" allow
? for only one-or-none narrowing - i.e. you're narrowed or not.
? 
? Often I would have found it helpful to have recursive
? narrowing.  Is there any way to do this?

M-x describe-function <RET> save-restriction <RET>

save-restriction:
Execute the body, undoing at the end any changes to current buffer's restrictions.
Changes to restrictions are made by narrow-to-region or by widen.
Thus, the restrictions are the same after this function as they were before it.
The value returned is that returned by the last form in the body.

This function can be confused if, within the body, you widen
and then make changes outside the area within the saved restrictions.

Note: if you are using both save-excursion and save-restriction,
use save-excursion outermost.

? Niall
? 

	(Root Boy) Jim Cottrell	<rbj@icst-cmr.arpa>
	National Bureau of Standards
	Flamer's Hotline: (301) 975-5688
If I am elected no one will ever have to do their laundry again!