[Top][All Lists]

[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: Sun, 10 Jan 2010 09:12:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> which to code things, just what is inherently wrong or dangerous (meriting a
>> warning) with code like the following, to do some work in other buffers yet
>> return to the original buffer AND restore its point and mark?
>> (save-excursion
>>   (set-buffer FOO)
>>   ; Pick up some info in FOO, & perhaps assign it to a var
>>   (set-buffer BAR)
>>   ; Calculate something in BAR, & perhaps record it too
>>   ...
>> )
> What is dangerous about it is that dependong on which buffer is current
> before executing this code, the point-saving will either do something
> or nothing.

Wrong.  It will always restore the _original_ buffer and its point on
exit of the save-excursion form.

> That's a very delicate semantics, which (as mentioned) I've never
> found to be correct (i.e. the only times it works reliably is when the
> point-saving part of save-excursion is never useful nor harmful).

As an example, when debugging some operation in buffer FOO, I can use
save-excursion in FOO and then set-buffer to the DEBUG buffer.  If the
user now selects FOO and moves around in it in order to look at its
contents, on exit of save-excursion, FOO's point will get restored.
Which is exactly what is required.

> Anyway, we just disagree,

If no consensus between suitably reasonable and informed persons can be
reached, it is a mistake to emit warnings and penalize a programming
style that can't be shown to be wrong.

David Kastrup

reply via email to

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