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: Tue, 22 Dec 2009 19:45:25 -0500 Message-ID: References: <87aaxdqwqv.fsf@regnitz.physics.niu.edu> <876380nvnt.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1261529360 359 80.91.229.12 (23 Dec 2009 00:49:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 23 Dec 2009 00:49:20 +0000 (UTC) Cc: emacs-devel@gnu.org To: David Kastrup Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Dec 23 01:49:12 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 1NNFPX-00005K-80 for ged-emacs-devel@m.gmane.org; Wed, 23 Dec 2009 01:49:07 +0100 Original-Received: from localhost ([127.0.0.1]:45124 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NNFPX-0005LX-DL for ged-emacs-devel@m.gmane.org; Tue, 22 Dec 2009 19:49:07 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NNFPS-0005LJ-8Y for emacs-devel@gnu.org; Tue, 22 Dec 2009 19:49:02 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NNFPN-0005Jh-Me for emacs-devel@gnu.org; Tue, 22 Dec 2009 19:49:01 -0500 Original-Received: from [199.232.76.173] (port=44314 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NNFPN-0005Jc-JH for emacs-devel@gnu.org; Tue, 22 Dec 2009 19:48:57 -0500 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:48122) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NNFPE-0007HV-94; Tue, 22 Dec 2009 19:48:48 -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 nBN0mcTo014977; Tue, 22 Dec 2009 19:48:40 -0500 Original-Received: by alfajor.home (Postfix, from userid 20848) id 5D9EE64365; Tue, 22 Dec 2009 19:45:25 -0500 (EST) In-Reply-To: <876380nvnt.fsf@lola.goethe.zz> (David Kastrup's message of "Mon, 21 Dec 2009 17:23:18 +0100") 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 RV3433=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:118781 Archived-At: >> 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))) > Says who? I, based on my experience. > You mean "so either you _could_ use". But save-excursion > does save the mark in the current buffer, and it does save point and > mark of the current buffer. > Please check the difference of > (with-temp-buffer > (let ((buf1 (current-buffer))) > (insert "xxxx") > (prin1 (point)) > (save-excursion > (with-temp-buffer > (with-current-buffer buf1 > (goto-char (point-min))))) > (prin1 (point)))) > and > (with-temp-buffer > (let ((buf1 (current-buffer))) > (insert "xxxx") > (prin1 (point)) > (with-temp-buffer > (with-current-buffer buf1 > (goto-char (point-min)))) > (prin1 (point)))) > You'll see that save-excursion restores point (and mark) even when > temporarily moving into some other buffer. Irrelevant: neither example uses (save-excursion (set-buffer ..) ...). >> 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. > And what if I wanted to have mark, point, and buffer restored, as the Obviously "if you didn't want to move point in foo" implies that you did not want "to have mark, point, and buffer restored". Stefan