[Top][All Lists]

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

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

From: Stefan Monnier
Subject: Re: `save-excursion' defeated by `set-buffer'
Date: Fri, 04 Mar 2011 23:28:40 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

> `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, 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.


reply via email to

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