From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Uday Reddy Newsgroups: gmane.emacs.help Subject: Re: `save-excursion' defeated by `set-buffer' Date: Sun, 13 Mar 2011 20:48:12 +0000 Organization: SunSITE.dk - Supporting Open source Message-ID: <4d7d2da4$0$23756$14726298@news.sunsite.dk> References: <4D792D16.1080900@easy-emacs.de> <83y64ksoik.fsf@gnu.org> <87aah0j7lf.fsf@rapttech.com.au> <4d7cd1d8$0$23762$14726298@news.sunsite.dk> 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: dough.gmane.org 1300052435 5973 80.91.229.12 (13 Mar 2011 21:40:35 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 13 Mar 2011 21:40:35 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 13 22:40:30 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 1Pyt1Z-0003hS-D6 for geh-help-gnu-emacs@m.gmane.org; Sun, 13 Mar 2011 22:40:29 +0100 Original-Received: from localhost ([127.0.0.1]:35032 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pyt1Y-0003U3-3R for geh-help-gnu-emacs@m.gmane.org; Sun, 13 Mar 2011 17:40:28 -0400 Original-Path: usenet.stanford.edu!news-transit.tcx.org.uk!feeder.erje.net!nuzba.szn.dk!news.szn.dk!pnx.dk!dotsrc.org!filter.dotsrc.org!news.dotsrc.org!not-for-mail User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 Original-Newsgroups: gnu.emacs.help In-Reply-To: Original-Lines: 59 Original-NNTP-Posting-Host: 92.232.137.113 Original-X-Trace: news.sunsite.dk DXC=QC@2V^EDE:Lc8biIGL=c`GYSB=nbEKnkK3LlDMZ4XbVI^H_C>[:W; BFUdS?DZIH?UA6E]45i7E1PAiLQiXd?DWbGG[N=S 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:80066 Archived-At: On 3/13/2011 6:25 PM, Drew Adams wrote: > >> save-excursion should be placed *as close as possible* to the point >> movements that it is trying to revert. > > Agreed. I don't think anyone disputes that. Oh, good. We are getting somewhere. Now, let us take the next step. Every save-excursion/set-buffer combination is a remote save-excursion. It is trying to protect point movements that are far away in code, so far away in fact that it is extremely hard to find them. So, by objecting to the compiler warning, you are indeed disputing the principle. > But you seem to think that `save-excursion' should never have been defined to > remember which buffer is current and restore that. `save-excursion' is _not_ > only about point movement. It is not designed only to save point and mark in > the current buffer. It is _designed_ to also restore that buffer, making it > current again. In retrospect, it seems that that design was a mistake. It would have been far better to have separate primitives for save-current-buffer and save-point-and-mark. Now that we have save-current-buffer available, there is no reason to use save-excursion to restore the current buffer. If you know of such reasons, please tell me. >> Another way to think about the problem is, for every >> save-excursion in the code: >> - are you clear which point movements it is trying to revert, >> - is it placed as close as possible to those point movements? > > Again, no disagreement. > > Though `save-excursion' is not only about point movement. And even wrt point > movement it really doesn't matter which movements a `save-excursion' is "trying > to revert". It is trying to revert them all (in its body) - and it does. > > Your real point here, I think, is again that it helps understanding and > modularity to keep the scope of a `save-excursion' as tight as possible. > Everyone agrees AFAIK. If you are agreeing, then it seems that your disagreement is about whether the compiler should help people in getting their save-excursion's right. You are not disagreeing that the compiler is being helpful. You seem to be saying that the compiler has no business in doing such things. Is that what this dispute really about? And, no, I haven't "missed" that save-excursion restores the current buffer. But save-current-buffer restores it just as well, and so that aspect of save-excursion doesn't seem relevant. If you want to argue that there are cases where save-excursion is a better choice than save-current-buffer, then by all means let us discuss that! Cheers, Uday