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: Mon, 04 Jan 2010 13:30:04 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

> 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.  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).

> But that's not a general problem of using the two together; that's just
> misunderstanding what they do. If that's the only "problem" we are warning
> programmers about, then I think the warning is misguided.

The precise behavior of (save-excusrion (set-buffer foo) ...) is
sufficiently odd that I still haven't come upon a single real case where
it was the right thing to do.  Yet, this precise form is (well, was)
found more than a hundred times in the Emacs source code.



        Stefan




reply via email to

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