From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: save-current-buffer Date: Sun, 19 Oct 2008 17:44:01 +0200 Message-ID: References: <1224362986.875430@arno.fh-trier.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1224435967 19716 80.91.229.12 (19 Oct 2008 17:06:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 19 Oct 2008 17:06:07 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Andreas Politz Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Oct 19 19:03:42 2008 connect(): Connection refused Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KraTD-0000Px-1X for geh-help-gnu-emacs@m.gmane.org; Sun, 19 Oct 2008 17:45:31 +0200 Original-Received: from localhost ([127.0.0.1]:41525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KraS7-0004RA-S0 for geh-help-gnu-emacs@m.gmane.org; Sun, 19 Oct 2008 11:44:23 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KraRo-0004R5-IH for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 11:44:04 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KraRn-0004Qs-S2 for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 11:44:04 -0400 Original-Received: from [199.232.76.173] (port=34554 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KraRn-0004Qp-No for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 11:44:03 -0400 Original-Received: from dd18200.kasserver.com ([85.13.138.168]:51509) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KraRn-0008Dz-Ce for help-gnu-emacs@gnu.org; Sun, 19 Oct 2008 11:44:03 -0400 Original-Received: from thursday (BAH0e26.bah.pppool.de [77.135.14.38]) by dd18200.kasserver.com (Postfix) with ESMTP id B8E0A18465A33; Sun, 19 Oct 2008 17:44:06 +0200 (CEST) In-Reply-To: <1224362986.875430@arno.fh-trier.de> (Andreas Politz's message of "Sat\, 18 Oct 2008 22\:43\:58 +0200") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:58925 Archived-At: Andreas Politz wrote: > Is this a bug, or am I missing something ? > Eval this in *scratch* buffer and you end up in the *Help* one. > > (save-current-buffer > (switch-to-buffer "*Help*")) There is a subtle difference between the current-buffer and the window's buffer. Any buffer can be current without being displayed. The function for that is `set-buffer'. `switch-to-buffer' changes both the current-buffer and the selected window's buffer. (progn (message "%s/%s" (current-buffer) (window-buffer (selected-window))) (save-current-buffer (switch-to-buffer "*Help*") (message "%s/%s" (current-buffer) (window-buffer (selected-window)))) (message "%s/%s" (current-buffer) (window-buffer (selected-window)))) will output: *scratch*/*scratch* *Help*/*Help* *scratch*/*Help* As you can see, current-buffer is restored, but the window's buffer is not. Replacing `save-current-buffer' with `save-window-excursion' gets you: *scratch*/*scratch* *Help*/*Help* *scratch*/*scratch* But generally, `switch-to-buffer' should only be used when the user wants to see the new buffer. Otherwise `set-buffer' is the better choice. regards, Nikolaj Schumacher