[Top][All Lists]

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

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

From: Uday Reddy
Subject: Re: `save-excursion' defeated by `set-buffer'
Date: Sun, 13 Mar 2011 02:40:34 +0000
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20110303 Thunderbird/3.1.9

On 3/12/2011 3:25 PM, David Kastrup wrote:

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.

Why is that?  I am quite happy to receive warnings about bad 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".

Ok, how about

   "save-current-buffer is a better choice than save-excursion"

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?

If an excursion is happening unintentionally that is definitely a bug! You probably mean that reverting it unintentionally is not so bad. But I happen to think that it is. save-excursion's should be as close as possible to the point movements they are protecting. One shouldn't randomly wrap large pieces of bad code in save-excursion and hope that nobody will notice. It is really hard to maintain such code. The compiler warning is really welcome from my point of view. I only wish that the compiler warning was there 20 years ago so that I wouldn't have to deal with that mess now. But better late than never!


reply via email to

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