From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: Behaviour for save-excursion Date: Tue, 06 Oct 2009 10:48:23 -0400 Message-ID: <87eipg1sug.fsf@stupidchicken.com> References: <5e3a506e0910060644y4ba6c73fv18d63ef8a1393117@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1254841240 16613 80.91.229.12 (6 Oct 2009 15:00:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 6 Oct 2009 15:00:40 +0000 (UTC) Cc: emacs-devel@gnu.org To: Nathaniel Flath Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 06 17:00:30 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 1MvBWU-00007M-5j for ged-emacs-devel@m.gmane.org; Tue, 06 Oct 2009 17:00:18 +0200 Original-Received: from localhost ([127.0.0.1]:60025 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvBWT-0000uf-Bk for ged-emacs-devel@m.gmane.org; Tue, 06 Oct 2009 11:00:17 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvBLD-0004GU-Ju for emacs-devel@gnu.org; Tue, 06 Oct 2009 10:48:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvBL8-0004Ap-QZ for emacs-devel@gnu.org; Tue, 06 Oct 2009 10:48:39 -0400 Original-Received: from [199.232.76.173] (port=47973 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvBL8-0004AZ-Ez for emacs-devel@gnu.org; Tue, 06 Oct 2009 10:48:34 -0400 Original-Received: from pantheon-po32.its.yale.edu ([130.132.50.88]:36403) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MvBL8-0004rC-4N for emacs-devel@gnu.org; Tue, 06 Oct 2009 10:48:34 -0400 Original-Received: from furry (dhcp128036014244.central.yale.edu [128.36.14.244]) (authenticated bits=0) by pantheon-po32.its.yale.edu (8.12.11.20060308/8.12.11) with ESMTP id n96EmPh3017840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 6 Oct 2009 10:48:28 -0400 Original-Received: by furry (Postfix, from userid 1000) id 207EAC070; Tue, 6 Oct 2009 10:48:24 -0400 (EDT) In-Reply-To: <5e3a506e0910060644y4ba6c73fv18d63ef8a1393117@mail.gmail.com> (Nathaniel Flath's message of "Tue, 6 Oct 2009 09:44:38 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) X-YaleITSMailFilter: Version 1.2c (attachment(s) not renamed) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.4-2.6 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:115928 Archived-At: Nathaniel Flath writes: > What is the proper behaviour for save-excursion? The emacs-lisp intro > and the docstring seem to have slightly differing explanations - > namely, the docstring mentions that it saves current-buffer as well as > point and mark, and the emacs-lisp intro does not. The Lisp intro does say that it saves current-buffer: In addition to recording the values of point and mark, `save-excursion' keeps track of the current buffer, and restores it, too. > Based on just what it does, I'm not entirely sure which is correct - > the following code snippet, executed in *scratch*, returns the > "*scratch*" buffer but the buffer displayed is the "bar" buffer, and > evaluating current-bufer afterwards returns the "bar" buffer. You shouldn't use switch-to-buffer in Lisp code unless you know what you're doing. That's why the docstring for switch-to-buffer has this: WARNING: This is NOT the way to work on another buffer temporarily within a Lisp program! Use `set-buffer' instead. That avoids messing with the window-buffer correspondences.