[Top][All Lists]

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

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

From: Andreas Röhler
Subject: Re: `save-excursion' defeated by `set-buffer'
Date: Fri, 11 Mar 2011 09:52:26 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; de; rv: Gecko/20100711 Thunderbird/3.0.6

Am 11.03.2011 02:28, schrieb Stefan Monnier:
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.

Thanks, this warning goes away if body is wrapped with a let:

   (let ()
     (set-buffer blub)

I see you apparently didn't understand much of what I wrote :-(


Maybe let's put the question another way:

is there an example, where save-excursion will fail, ie not restore the buffer due to a set-buffer afterwards?



reply via email to

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