[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: save-restriction, save-excursion

From: Ryan Yeske
Subject: Re: save-restriction, save-excursion
Date: Tue, 17 Sep 2002 06:24:18 GMT
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

David Kastrup <address@hidden> writes:

> Ryan Yeske <address@hidden> writes:
> > From the node "Narrowing" in the elisp manual:
> > 
> >      `save-restriction' does _not_ restore point and the mark; use
> >      `save-excursion' for that.  If you use both `save-restriction' and
> >      `save-excursion' together, `save-excursion' should come first (on
> >      the outside).  Otherwise, the old point value would be restored
> >      with temporary narrowing still in effect.  If the old point value
> >      were outside the limits of the temporary narrowing, this would
> >      fail to restore it accurately.
> Hmmm.  What if I have a restriction active and write
> (save-excursion
>   (save-restriction
>     (widen)
>     (goto (point-min))))
> When the restriction gets restored, point will lie outside of the
> restored restriction.  Wouldn't that cause trouble?

Try it :)

It helps me to think about it like this:

1) save the point
2) save the restriction
3) frob the restriction (narrow *or* widen)
4) frob the point
5) restore the old restriction
6) restore the old point
It doesn't matter whether you are widening or narrowing.  When the
restriction is restored (step 5), the point is adjusted to be within
the restriction (the point can never be outside the current
restriction).  It doesn't really matter though, since the point is
then immediatly restored to the initial value within the initial
restriction at step 6.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]