From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: Behaviour for save-excursion Date: Tue, 06 Oct 2009 16:44:47 +0200 Message-ID: <4ACB57DF.7040407@gmx.at> References: <5e3a506e0910060644y4ba6c73fv18d63ef8a1393117@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1254841148 16136 80.91.229.12 (6 Oct 2009 14:59:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 6 Oct 2009 14:59:08 +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 16:58:58 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 1MvBV9-0007wH-GX for ged-emacs-devel@m.gmane.org; Tue, 06 Oct 2009 16:58:55 +0200 Original-Received: from localhost ([127.0.0.1]:59280 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvBV9-0007oR-75 for ged-emacs-devel@m.gmane.org; Tue, 06 Oct 2009 10:58:55 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvBHd-0008Le-0x for emacs-devel@gnu.org; Tue, 06 Oct 2009 10:44:57 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvBHY-0008Go-HF for emacs-devel@gnu.org; Tue, 06 Oct 2009 10:44:56 -0400 Original-Received: from [199.232.76.173] (port=58389 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvBHY-0008Ga-37 for emacs-devel@gnu.org; Tue, 06 Oct 2009 10:44:52 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]:56108) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1MvBHX-00040c-CK for emacs-devel@gnu.org; Tue, 06 Oct 2009 10:44:51 -0400 Original-Received: (qmail invoked by alias); 06 Oct 2009 14:44:48 -0000 Original-Received: from 62-47-34-167.adsl.highway.telekom.at (EHLO [62.47.34.167]) [62.47.34.167] by mail.gmx.net (mp064) with SMTP; 06 Oct 2009 16:44:48 +0200 X-Authenticated: #14592706 X-Provags-ID: V01U2FsdGVkX1+xfa9JP8mxxYtMyg5fyDTilZ5ls1qEeu/n2jzZLb T+InAQU6h390JV User-Agent: Thunderbird 2.0.0.21 (Windows/20090302) In-Reply-To: <5e3a506e0910060644y4ba6c73fv18d63ef8a1393117@mail.gmail.com> X-Y-GMX-Trusted: 0 X-FuHaFi: 0.68 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. 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:115927 Archived-At: > 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. 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. > > (progn > (save-excursion > (switch-to-buffer "bar")) > (current-buffer)) > > Either the manual or the docstring should be changed to reflect what it > does, but I'm not entirely sure which based on this. Please read the Elisp manual entry on `save-excursion' which states: Likewise, `save-excursion' does not restore window-buffer correspondences altered by functions such as `switch-to-buffer'. One way to restore these correspondences, and the selected window, is to use `save-window-excursion' inside `save-excursion' (*note Window Configurations::). Also the following entry from section 27.2 The Current Buffer of the Elisp manual might provide further explanation: When an editing command returns to the editor command loop, the command loop designates the buffer displayed in the selected window as current, to prevent confusion: the buffer that the cursor is in when Emacs reads a command is the buffer that the command will apply to. (*Note Command Loop::.) Therefore, `set-buffer' is not the way to switch visibly to a different buffer so that the user can edit it. For that, you must use the functions described in *Note Displaying Buffers::. martin