emacs-devel
[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: Mon, 04 Jan 2010 18:34:50 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux)

"Davis Herring" <address@hidden> writes:

>> save-excursion only saves point in the current buffer, so
>>
>>    (save-excursion (set-buffer foo) (goto-char (point-min)))
>>
>> will move point in foo and the point-saving done by save-excursion is
>> useless.  So either you want to use
>
> If we know that (eq foo (current-buffer)), we should drop the
> `set-buffer'.  If we know that not to be the case, we should use
> `with-current-buffer' (or perhaps `save-current-buffer').  But what if it
> could but needn't be?

And what if we don't have just (goto-char (point-min)), but some code
that might _revisit_ the original buffer (with set-buffer or otherwise)
and _move_ its point?  Then save-excursion _will_ restore the original
point in the buffer at its end which otherwise would remain moved.

-- 
David Kastrup





reply via email to

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