[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: Tue, 05 Jan 2010 21:17:12 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> I would like to see a clear, logical presentation of what your position is,
>> Stefan.  It's not obvious to me what this is all about.
> It's really not about much.  Feel free to completely ignore it.
> I've updated the manual (except for the lisp-intro) to eliminate the
> more obvious problems.
>> The explanation in that node is just what I've always understood wrt
>> `save-excursion'.  It makes it clear that only point and mark of the
>> current buffer are saved and restored, along with the identity of the
>> current buffer.  So I really don't see what the problem is.
> The propblem is that even tho it's clear, people tend to forget about
> it.  Proof is the dired-mouse-find-file-other-window example code in the
> manual which did
>    (save-excursion
>      ...
>      (set-buffer ...)
>      (goto-char ...)
>      ...)
> The problem with that code is that point in current buffer will be moved
> depending on whether the buffer we switch to is the same as the
> current buffer.

And it will get restored in the current (original) buffer at the end of
the save-excursion.

So it is not the save-excursion that is defeated by set-buffer, but
rather the goto-char which may be defeated by save-excursion.

> That's unlikely to be what the author intended.  She probably either
> didn't want to save point (and juse use save-current-buffer instead),
> or did want to save point (in which case she needed
> save-current-buffer around and an additional save-excursion inside).

Or she wanted to have point and buffer restored at the end of the

David Kastrup

reply via email to

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