[Top][All Lists]

[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, 21 Dec 2009 10:26:47 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux)

> Me too I've seen these messages with some code I've been using. Yet
> I wasn't sure how to interpret them / what to do with them. I looked
> into the elisp manual, but I didn't find anything. It would be great
> if someone could add a remark to the elisp manual and / or
> docstrings about the relation between save-excursion, set-buffer and
> with-current-buffer.

save-excursion only saves point in the current buffer, so

   (save-excursion (set-buffer foo) (goto-char (point-min)))

will move point in foo and the point-saving done by save-excursion is
useless.  So either you want to use

   (save-current-buffer (set-buffer foo) (goto-char (point-min)))
   (with-current-buffer foo (goto-char (point-min)))

if moving point in foo is what you wanted, or

   (with-current-buffer foo (save-excursion (goto-char (point-min))))

if you didn't want to move point in foo.


reply via email to

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