From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.help Subject: Re: `save-excursion' defeated by `set-buffer' Date: Thu, 10 Mar 2011 23:40:47 +0100 Organization: Organization?!? Message-ID: <87sjuulhu8.fsf@fencepost.gnu.org> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1299800463 2789 80.91.229.12 (10 Mar 2011 23:41:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 10 Mar 2011 23:41:03 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 11 00:41:00 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 1PxpTW-0001Ve-UG for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Mar 2011 00:40:59 +0100 Original-Received: from localhost ([127.0.0.1]:54340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PxpTV-0008W1-IK for geh-help-gnu-emacs@m.gmane.org; Thu, 10 Mar 2011 18:40:57 -0500 Original-Path: usenet.stanford.edu!newsserver.news.garr.it!kanaga.switch.ch!news-zh.switch.ch!switch.ch!news.belwue.de!news.n-ix.net!noris.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:r7awmPxHcJqxXEhKd5WGeMgGxtA= Original-Lines: 40 Original-NNTP-Posting-Date: 10 Mar 2011 23:40:48 CET Original-NNTP-Posting-Host: 1c64d6ea.newsspool3.arcor-online.net Original-X-Trace: DXC=lRcJcHIRYW9]E=H1Q9`787McF=Q^Z^V384Fo<]lROoR18kF 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:79950 Archived-At: Stefan Monnier writes: >> `save-excursion' defeated by `set-buffer' > [...] >> (save-excursion >> (set-buffer blub) >> ... >> ) > >> Save point, mark, and current buffer; execute BODY; restore those things > >> would expect previous buffer restored, don't understand >> that warning. > > The difference between save-excursion and save-current-buffer is that > the first doesn't just save&restore the current buffer but also "point & > mark". But if you do `set-buffer' right after save-excursion then most > likely you will change neither point nor mark in the original buffer, "most likely". So `save-excursion' is most likely defeated by `set-buffer'. > so the extra work performed by save-excursion compared to > save-current-buffer will be useless. Now that's just a waste of > resources but is otherwise harmless. > > Unless of course `blub' is already the current buffer to start with. > > I.e. whether point movement in "..." is undone by save-excursion will > depend dynamically upon whether the current buffer happens to be `blub', > which leads to subtle bugs. Hence the warning. So the warning tells us "`save-excursion' defeated by `set-buffer'" in order to warn us against the possibility that `save-excursion' may actually _not_ defeated by `set-buffer'. Small wonder nobody understands what the warning is supposed to be for. -- David Kastrup