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: Eli Zaretskii
Subject: Re: `save-excursion' defeated by `set-buffer'
Date: Sat, 12 Mar 2011 10:59:15 +0200

> 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'

?



reply via email to

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