From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-15?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: `save-excursion' defeated by `set-buffer' Date: Sat, 12 Mar 2011 20:00:40 +0100 Message-ID: <4D7BC2D8.8080909@easy-emacs.de> References: <4D792D16.1080900@easy-emacs.de> <83y64ksoik.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1299956169 17499 80.91.229.12 (12 Mar 2011 18:56:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 12 Mar 2011 18:56:09 +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 19:56:05 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 1PyTyu-0003kM-Ti for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Mar 2011 19:56:05 +0100 Original-Received: from localhost ([127.0.0.1]:54936 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PyTyt-0004oV-SO for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Mar 2011 13:56:03 -0500 Original-Received: from [140.186.70.92] (port=45171 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PyTyV-0004oQ-Hy for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 13:55:40 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PyTyT-0007DK-Sx for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 13:55:39 -0500 Original-Received: from moutng.kundenserver.de ([212.227.17.10]:62814) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PyTyT-0007Cu-Gh for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 13:55:37 -0500 Original-Received: from [192.168.178.29] (brln-4d0c394f.pool.mediaWays.net [77.12.57.79]) by mrelayeu.kundenserver.de (node=mrbap1) with ESMTP (Nemesis) id 0Lv8ja-1Q6YtT14aY-010al2; Sat, 12 Mar 2011 19:55:33 +0100 User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6 In-Reply-To: <83y64ksoik.fsf@gnu.org> X-Provags-ID: V02:K0:gwixHQ5pE6oDIBwfz9BoRDGZYY+tAu45Vz0Yl2cwanp VQVWf63jBs6bcTrEF9oRqQUTD7W4S+gYmrk0S2HExaM6ZTIcnh hpNhaPQ4W/HmcjpotDlIF48B56rJk88VvOICKKUFlnR8PTUsET 7EPN7O3NgAvLThj8vXUzBWtLFw7qp+T8wCMxN2DVX0g9lPIKOV TNrYuP8PWOSl8/8kx/AzOm6Qx5WWAViAub6YGk0Fu0= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 212.227.17.10 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:80033 Archived-At: Am 12.03.2011 09:59, schrieb Eli Zaretskii: >> 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' > > ? > > Seems all what's neccessary to know about save-excursion already is expressed in it's docstring. If people don't want the buffer restored alongside with point and mark, they should not use this form. As I used it, compiler may assume I wanted that. No reason for a warning if used as provided. OTOH we need compiler warnings for serious things. So my suggestion is simply to drop that warning. Thanks all Andreas