From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: `save-excursion' defeated by `set-buffer' Date: Mon, 21 Dec 2009 10:26:47 -0500 Message-ID: References: <87aaxdqwqv.fsf@regnitz.physics.niu.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1261409707 30372 80.91.229.12 (21 Dec 2009 15:35:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 21 Dec 2009 15:35:07 +0000 (UTC) Cc: emacs-devel@gnu.org To: "Roland Winkler" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 21 16:34:59 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NMkHd-0006A6-Ib for ged-emacs-devel@m.gmane.org; Mon, 21 Dec 2009 16:34:57 +0100 Original-Received: from localhost ([127.0.0.1]:38147 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NMkHb-0000ZH-HW for ged-emacs-devel@m.gmane.org; Mon, 21 Dec 2009 10:34:51 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NMkD6-0007Qm-42 for emacs-devel@gnu.org; Mon, 21 Dec 2009 10:30:12 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NMkD1-0007MT-8D for emacs-devel@gnu.org; Mon, 21 Dec 2009 10:30:11 -0500 Original-Received: from [199.232.76.173] (port=34611 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NMkD1-0007MK-2B for emacs-devel@gnu.org; Mon, 21 Dec 2009 10:30:07 -0500 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:39703) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NMkCz-0007mk-Sr for emacs-devel@gnu.org; Mon, 21 Dec 2009 10:30:06 -0500 Original-Received: from alfajor.home (faina.iro.umontreal.ca [132.204.26.177]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id nBLFTvYZ014693; Mon, 21 Dec 2009 10:30:00 -0500 Original-Received: by alfajor.home (Postfix, from userid 20848) id 4048964367; Mon, 21 Dec 2009 10:26:47 -0500 (EST) In-Reply-To: <87aaxdqwqv.fsf@regnitz.physics.niu.edu> (Roland Winkler's message of "Sun, 20 Dec 2009 13:19:20 -0600") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.90 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3431=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:118758 Archived-At: > 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))) aka (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. Stefan