From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: `save-exursion' makes a comeback! Date: Tue, 15 Mar 2011 09:02:02 -0700 Message-ID: <12BFB1D857B848BC862DBEAAC016E686@us.oracle.com> References: <87d3lso1a6.fsf@fencepost.gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1300206232 24344 80.91.229.12 (15 Mar 2011 16:23:52 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 15 Mar 2011 16:23:52 +0000 (UTC) To: "'David Kastrup'" , Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 15 17:23:48 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 1PzX2B-0007Db-MJ for geh-help-gnu-emacs@m.gmane.org; Tue, 15 Mar 2011 17:23:48 +0100 Original-Received: from localhost ([127.0.0.1]:35654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzWnh-0007PD-Me for geh-help-gnu-emacs@m.gmane.org; Tue, 15 Mar 2011 12:08:49 -0400 Original-Received: from [140.186.70.92] (port=56861 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PzWhJ-0004cG-06 for help-gnu-emacs@gnu.org; Tue, 15 Mar 2011 12:02:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PzWhH-0003Ax-Gv for help-gnu-emacs@gnu.org; Tue, 15 Mar 2011 12:02:12 -0400 Original-Received: from rcsinet10.oracle.com ([148.87.113.121]:32019) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PzWhG-0003Af-AB; Tue, 15 Mar 2011 12:02:10 -0400 Original-Received: from rcsinet13.oracle.com (rcsinet13.oracle.com [148.87.113.125]) by rcsinet10.oracle.com (Switch-3.4.2/Switch-3.4.2) with ESMTP id p2FG28ii020020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 15 Mar 2011 16:02:09 GMT Original-Received: from acsmt356.oracle.com (acsmt356.oracle.com [141.146.40.156]) by rcsinet13.oracle.com (Switch-3.4.2/Switch-3.4.1) with ESMTP id p2FG27OL022259 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 15 Mar 2011 16:02:07 GMT Original-Received: from abhmt021.oracle.com (abhmt021.oracle.com [141.146.116.30]) by acsmt356.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p2FG27eq024276; Tue, 15 Mar 2011 11:02:07 -0500 Original-Received: from dradamslap1 (/130.35.178.194) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 15 Mar 2011 09:02:04 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <87d3lso1a6.fsf@fencepost.gnu.org> Thread-Index: AcvjJ0kcgtHpnbsCSNGLFHVTPb3NygAAQe4Q X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5994 X-Source-IP: acsmt356.oracle.com [141.146.40.156] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090203.4D7F8D80.007D,ss=1,fgs=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 148.87.113.121 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:80130 Archived-At: > > Forget about `save-excursion' "saving" or "restoring" or > > "hiding" or "protecting" anything. Forget about it "defeating" > > or being "defeated". Forget all of that right now. > > > > The real name of `save-excursion' is `come-back-here'. > > Just remember that and Bob's your uncle. > > M-: (with-temp-buffer (let ((b (current-buffer))) (save-excursion > (set-buffer "*scratch*") (kill-buffer b))) (current-buffer)) RET Yes, David. I explicitly mentioned that case before (though that was no doubt lost in the bit torrent). This makes it even clearer, I think: (defun foo () (interactive) (save-excursion (message "BEFORE KILL, buf: %S, pt: %S, mark: %S" (current-buffer) (point) (mark)) (sit-for 2) (kill-buffer (current-buffer)) (message "BEFORE END, buf: %S, pt: %S, mark: %S" (current-buffer) (point) (mark)) (sit-for 2)) (message "AFTER, buf: %S, pt: %S, mark: %S" (current-buffer) (point) (mark)) (sit-for 2)) M-x foo RET This is no different from your father saying "Come back here!" as you run out the door, and your then burning down the house so there is no place to come back to. Really, this kind of thing just adds confusion to the discussion for most users. There is nothing special here to do with `save-excursion'. `save-excursion' just does an `unwind-protect' to return where you came from. If in the meantime you have nuked the place you came from then there is nothing that `save-excursion', `unwind-protect', or the Emacs god herself can do to bring your home back.