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: Andreas Röhler
Subject: Re: `save-excursion' defeated by `set-buffer'
Date: Sat, 12 Mar 2011 20:00:40 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6

Am 12.03.2011 09:59, schrieb Eli Zaretskii:
From: Stefan Monnier<monnier@iro.umontreal.ca>
Date: Fri, 11 Mar 2011 10:52:14 -0500

So (save-excursion (goto-char BAR)) is pretty much a no-op.

But (save-excursion (set-buffer FOO) (goto-char BAR)) is either:
- the same as (save-excursion (goto-char BAR)), in case FOO is already current.
- an inefficient form of (with-current-buffer FOO (goto-char BAR)).
I still haven't found any code out there where this behavior is what
is actually wanted and expected by the programmer.

In more than 90% of the cases, the intended meaning is
(with-current-buffer FOO (goto-char BAR)) and the behavior if FOO is
current (to additionally preserve point) is harmless, so the warning
simply points out an inefficiency.

In the remaining cases, FOO is almost always current, but when it's not
the resulting behavior is a bug.  I.e. the intended code is
(with-current-buffer FOO (save-excursion (goto-char BAR))).

Then how about changing the text of the warning to something like

   Warning: `save-excursion' will not preserve point in the other buffer
   set by `set-buffer'

?





Seems all what's neccessary to know about save-excursion already is expressed in it's docstring.

If people don't want the buffer restored alongside with point and mark, they should not use this form.

As I used it, compiler may assume I wanted that. No reason for a warning if used as provided.

OTOH we need compiler warnings for serious things.

So my suggestion is simply to drop that warning.

Thanks all

Andreas







reply via email to

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