From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.help Subject: Re: `save-excursion' defeated by `set-buffer' Date: Sat, 12 Mar 2011 10:59:15 +0200 Message-ID: <83y64ksoik.fsf@gnu.org> References: <4D792D16.1080900@easy-emacs.de> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1299920384 16740 80.91.229.12 (12 Mar 2011 08:59:44 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 12 Mar 2011 08:59:44 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Mar 12 09:59:40 2011 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.69) (envelope-from ) id 1PyKfj-0006FX-UY for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Mar 2011 09:59:40 +0100 Original-Received: from localhost ([127.0.0.1]:45318 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PyKfj-00016K-9V for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Mar 2011 03:59:39 -0500 Original-Received: from [140.186.70.92] (port=33554 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PyKfK-000163-GT for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 03:59:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PyKfJ-0000pa-Fv for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 03:59:14 -0500 Original-Received: from mtaout22.012.net.il ([80.179.55.172]:51617) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PyKfJ-0000p7-8T for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 03:59:13 -0500 Original-Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0LHX00000S79OX00@a-mtaout22.012.net.il> for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 10:59:11 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([77.124.58.59]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0LHX00031SYMSN00@a-mtaout22.012.net.il> for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 10:59:11 +0200 (IST) In-reply-to: X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 80.179.55.172 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:80018 Archived-At: > From: Stefan Monnier > Date: Fri, 11 Mar 2011 10:52:14 -0500 > > So (save-excursion (goto-char BAR)) is pretty much a no-op. > > But (save-excursion (set-buffer FOO) (goto-char BAR)) is either: > - the same as (save-excursion (goto-char BAR)), in case FOO is already current. > - an inefficient form of (with-current-buffer FOO (goto-char BAR)). > I still haven't found any code out there where this behavior is what > is actually wanted and expected by the programmer. > > In more than 90% of the cases, the intended meaning is > (with-current-buffer FOO (goto-char BAR)) and the behavior if FOO is > current (to additionally preserve point) is harmless, so the warning > simply points out an inefficiency. > > In the remaining cases, FOO is almost always current, but when it's not > the resulting behavior is a bug. I.e. the intended code is > (with-current-buffer FOO (save-excursion (goto-char BAR))). Then how about changing the text of the warning to something like Warning: `save-excursion' will not preserve point in the other buffer set by `set-buffer' ?