help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: `save-excursion' defeated by `set-buffer'


From: David Kastrup
Subject: Re: `save-excursion' defeated by `set-buffer'
Date: Thu, 10 Mar 2011 23:40:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> `save-excursion' defeated by `set-buffer'
> [...]
>>  (save-excursion
>>    (set-buffer blub)
>>    ...
>>    )
>
>> Save point, mark, and current buffer; execute BODY; restore those things
>
>> would expect previous buffer restored, don't understand
>> that warning.
>
> The difference between save-excursion and save-current-buffer is that
> the first doesn't just save&restore the current buffer but also "point &
> mark".  But if you do `set-buffer' right after save-excursion then most
> likely you will change neither point nor mark in the original buffer,

"most likely".  So `save-excursion' is most likely defeated by
`set-buffer'.

> so the extra work performed by save-excursion compared to
> save-current-buffer will be useless.  Now that's just a waste of
> resources but is otherwise harmless.
>
> Unless of course `blub' is already the current buffer to start with.
>
> I.e. whether point movement in "..." is undone by save-excursion will
> depend dynamically upon whether the current buffer happens to be `blub',
> which leads to subtle bugs.  Hence the warning.

So the warning tells us "`save-excursion' defeated by `set-buffer'" in
order to warn us against the possibility that `save-excursion' may
actually _not_ defeated by `set-buffer'.

Small wonder nobody understands what the warning is supposed to be for.

-- 
David Kastrup


reply via email to

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