emacs-devel
[Top][All Lists]
Advanced

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

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


From: Stefan Monnier
Subject: Re: `save-excursion' defeated by `set-buffer'
Date: Tue, 05 Jan 2010 23:20:59 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.91 (gnu/linux)

> Certainly, `set-buffer' does not undo or inhibit or interfere with the
> normal behavior of `save-excursion'; it cannot be said to "defeat"
> `save-excursion' in any way.

The experience so far is that when replacing

  (save-excursion (set-buffer FOO) ...)
with
  (with-current-buffer FOO ...)

either the behavior is unchanged (i.e. the set-buffer makes the
point-saving part of save-excursion useless), or a bug shows up which
can be fixed with the use of

  (with-current-buffer FOO (save-excursion ...))

I.e. the original code only worked right when the set-buffer was a noop
(which for such code is typically the most common case, obviously,
otherwise the bug would have surfaced earlier).

> IMO the warning should simply be removed.

Show me a single case (in existing code) where
(save-excursion (set-buffer FOO) ...) wouldn't better be written some
other way.


        Stefan





reply via email to

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