From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: `save-excursion' defeated by `set-buffer' Date: Mon, 04 Jan 2010 13:30:04 -0500 Message-ID: References: <87aaxdqwqv.fsf@regnitz.physics.niu.edu> <876380nvnt.fsf@lola.goethe.zz> <87hbrijbyg.fsf@lola.goethe.zz> <87skb0iw04.fsf@lola.goethe.zz> <1DA372296B5F41A1A3317F557D27355D@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1262629939 17983 80.91.229.12 (4 Jan 2010 18:32:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 4 Jan 2010 18:32:19 +0000 (UTC) Cc: 'David Kastrup' , emacs-devel@gnu.org To: "Drew Adams" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jan 04 19:32:11 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NRris-0003sv-MY for ged-emacs-devel@m.gmane.org; Mon, 04 Jan 2010 19:32:10 +0100 Original-Received: from localhost ([127.0.0.1]:43710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NRrit-0000jq-04 for ged-emacs-devel@m.gmane.org; Mon, 04 Jan 2010 13:32:11 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NRrgz-0006Kd-J6 for emacs-devel@gnu.org; Mon, 04 Jan 2010 13:30:13 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NRrgu-0006Bi-KB for emacs-devel@gnu.org; Mon, 04 Jan 2010 13:30:13 -0500 Original-Received: from [199.232.76.173] (port=58803 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NRrgu-0006BT-Cb for emacs-devel@gnu.org; Mon, 04 Jan 2010 13:30:08 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.183]:65486 helo=ironport2-out.pppoe.ca) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NRrgr-0004t6-Sn; Mon, 04 Jan 2010 13:30:06 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArMEAO/CQUvO+KPG/2dsb2JhbACBRdQugiyCBASKKQ X-IronPort-AV: E=Sophos;i="4.47,499,1257138000"; d="scan'208";a="52912017" Original-Received: from 206-248-163-198.dsl.teksavvy.com (HELO pastel.home) ([206.248.163.198]) by ironport2-out.pppoe.ca with ESMTP; 04 Jan 2010 13:30:04 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 7A0C88FD6; Mon, 4 Jan 2010 13:30:04 -0500 (EST) In-Reply-To: <1DA372296B5F41A1A3317F557D27355D@us.oracle.com> (Drew Adams's message of "Mon, 4 Jan 2010 01:09:53 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:119387 Archived-At: > I would like to see a clear, logical presentation of what your position is, > Stefan. It's not obvious to me what this is all about. It's really not about much. Feel free to completely ignore it. I've updated the manual (except for the lisp-intro) to eliminate the more obvious problems. > The explanation in that node is just what I've always understood wrt > `save-excursion'. It makes it clear that only point and mark of the > current buffer are saved and restored, along with the identity of the > current buffer. So I really don't see what the problem is. The propblem is that even tho it's clear, people tend to forget about it. Proof is the dired-mouse-find-file-other-window example code in the manual which did (save-excursion ... (set-buffer ...) (goto-char ...) ...) The problem with that code is that point in current buffer will be moved depending on whether the buffer we switch to is the same as the current buffer. That's unlikely to be what the author intended. She probably either didn't want to save point (and juse use save-current-buffer instead), or did want to save point (in which case she needed save-current-buffer around and an additional save-excursion inside). > But that's not a general problem of using the two together; that's just > misunderstanding what they do. If that's the only "problem" we are warning > programmers about, then I think the warning is misguided. The precise behavior of (save-excusrion (set-buffer foo) ...) is sufficiently odd that I still haven't come upon a single real case where it was the right thing to do. Yet, this precise form is (well, was) found more than a hundred times in the Emacs source code. Stefan