[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: save-restriction, save-excursion
From: |
pokerface |
Subject: |
Re: save-restriction, save-excursion |
Date: |
18 Sep 2002 22:17:52 GMT |
User-agent: |
Xnews/5.04.25 |
Thank you gentlemen for the helpful replies!
Ryan Yeske <rcyeske@vcn.bc.ca> wrote in
87fzw9ceye.fsf@cut.hotdog.tmp:">news:87fzw9ceye.fsf@cut.hotdog.tmp:
> David Kastrup <David.Kastrup@t-online.de> writes:
>
>> Ryan Yeske <rcyeske+spam@vcn.bc.ca> 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.
>
> Ryan
>