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 14:28:17 +0200 Message-ID: <83pqpwseu6.fsf@gnu.org> References: <4D792D16.1080900@easy-emacs.de> <87pqpwr8ay.fsf@fencepost.gnu.org> <87d3lwr56j.fsf@fencepost.gnu.org> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1299932926 5598 80.91.229.12 (12 Mar 2011 12:28:46 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 12 Mar 2011 12:28:46 +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 13:28:42 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 1PyNw2-0006CS-6S for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Mar 2011 13:28:42 +0100 Original-Received: from localhost ([127.0.0.1]:49858 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PyNw1-0002rc-HQ for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Mar 2011 07:28:41 -0500 Original-Received: from [140.186.70.92] (port=49181 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PyNve-0002rP-Cn for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 07:28:19 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PyNvb-0008Kn-EH for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 07:28:18 -0500 Original-Received: from mtaout21.012.net.il ([80.179.55.169]:45434) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PyNvb-0008KK-7t for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 07:28:15 -0500 Original-Received: from conversion-daemon.a-mtaout21.012.net.il by a-mtaout21.012.net.il (HyperSendmail v2007.08) id <0LHY00A002FHT800@a-mtaout21.012.net.il> for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 14:28:13 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([77.124.58.59]) by a-mtaout21.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0LHY00ADR2N0C8C0@a-mtaout21.012.net.il> for help-gnu-emacs@gnu.org; Sat, 12 Mar 2011 14:28:13 +0200 (IST) In-reply-to: <87d3lwr56j.fsf@fencepost.gnu.org> X-012-Sender: halo1@inter.net.il X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-Received-From: 80.179.55.169 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:80025 Archived-At: > From: David Kastrup > Date: Sat, 12 Mar 2011 11:42:12 +0100 > > Eli Zaretskii writes: > > >> From: David Kastrup > >> Date: Sat, 12 Mar 2011 10:34:45 +0100 > >> > >> > Warning: `save-excursion' will not preserve point in the other buffer > >> > set by `set-buffer' > >> > >> Is there a particular reason that nobody is interested in letting the > >> warning be about the case that is supposed to be problematic > > > > Huh? That's what I tried to express in the above text. Isn't that > > _precisely_ the problematic case, when the other buffer is not the > > current and the body of save-excursion moves point and/or mark there? > > No, it isn't. The likelilood that somebody uses `set-buffer' when he > expects it not to change the current buffer is not exactly large. And that is exactly the situation that my suggested warning is about. > >> Warning: `save-excursion' will preserve point and mark in the current > >> buffer even if set-buffer does not actually change buffers. > > > > Your "warning" describes what `save-excursion' is supposed to do, at > > least according to the ELisp manual: > > > > The `save-excursion' special form saves the identity of the current > > buffer and the values of point and the mark in it, evaluates BODY, > > and finally restores the buffer and its saved values of point and > > the mark. > > > > So how could warning about the normal operation be TRT? > > Very funny. Of course the warning will be about a situation where every > function works according to its specifications. Very funny. The warning should be about a situation where what the function is supposed to do does not match what the programmer might expect from the function, judging by the code the programmer actually wrote. Perhaps you could explain how saying that `save-excursion' _will_ preserve point and mark is supposed to help the programmer understand her possible mistake, which is that `save-excursion' might _not_ preserve them. Let's see: J. R. Hacker: Let's use `save-excursion' to preserve point and mark in both this and the other buffer. [Hacks away.] Emacs: Warning: `save-excursion' will preserve point and mark in the current buffer even if set-buffer does not actually change buffers. J. R. Hacker: ?? Isn't that what I wanted, to preserve point and mark? Why the warning??? Stupid Emacs! [Leaves the code as is.] > Anyway, I suggest you get yourself up to speed by reading a few messages > from Stefan Monnier about his rationale for introducing this warning. Actually, I did. Perhaps so should you. Or, if you see some flaw in my suggested text, how about pointing out when and how it could lead J. R. Hacker to the wrong conclusion?