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: Sat, 12 Mar 2011 16:25:24 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Uday Reddy <uDOTsDOTreddy@cs.bham.ac.uk> writes:

> On 3/12/2011 10:42 AM, David Kastrup wrote:
>
>> No, it isn't.  The likelilood that somebody uses `set-buffer' when he
>> expects it not to change the current buffer is not exactly large.
>
> Agreed.  But that is not the only case where the problems occur.  As
> explained in my message yesterday, there could be unprotected point
> movements deep inside function calls, which are unintentionally caught
> by the save-excursion at the outer level.  Ideally, those point
> movements should be protected where they occur, not by an unrelated an
> save-excursion sitting somewhere else.
>
> Frankly, I think the warning message is quite fine.  save-excursion is
> trying to preserve the point (and mark), but only for the
> current-buffer.  set-buffer is changing the current-buffer and, so,
> the preservation of the point in the current-buffer is useless.

There is little reason to warn about "useless" code.

> If one wants a completely plain warning message, it could be:
>
>   "save-excursion has the effect of save-current-buffer"
>
> It doesn't say very much, but nobody will presumably argue about it.

The most plausible theory I have for this thread is that you are
collectively trying to pull my leg.

If you give the user that warning, he'll say "great, just like I wanted
it to do".

Why warn the user that "save-excursion" is doing what he wants it to do,
when the actual problem is that it may do more, namely reverting an
excursion happening unintendedly in the original buffer?

-- 
David Kastrup


reply via email to

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