From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Steve Hafner Newsgroups: gmane.emacs.bugs Subject: bug#12208: yes-or-no-p escapes with-current-buffer Date: Thu, 16 Aug 2012 14:36:25 -0600 Message-ID: References: <502CBF82.3080601@gmx.at> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1345149446 23574 80.91.229.3 (16 Aug 2012 20:37:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Aug 2012 20:37:26 +0000 (UTC) To: 12208@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 16 22:37:22 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T26of-0004Yp-Jq for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Aug 2012 22:37:17 +0200 Original-Received: from localhost ([::1]:32877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T26oe-0006Y0-K8 for geb-bug-gnu-emacs@m.gmane.org; Thu, 16 Aug 2012 16:37:16 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:42821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T26ob-0006Xj-14 for bug-gnu-emacs@gnu.org; Thu, 16 Aug 2012 16:37:13 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T26oZ-0004m9-UJ for bug-gnu-emacs@gnu.org; Thu, 16 Aug 2012 16:37:12 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:52822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T26oZ-0004m5-QU for bug-gnu-emacs@gnu.org; Thu, 16 Aug 2012 16:37:11 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1T26x8-0001L6-AX for bug-gnu-emacs@gnu.org; Thu, 16 Aug 2012 16:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Steve Hafner Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Aug 2012 20:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12208 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13451499265009 (code B ref -1); Thu, 16 Aug 2012 20:46:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Aug 2012 20:45:26 +0000 Original-Received: from localhost ([127.0.0.1]:34135 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T26wX-0001Ik-B5 for submit@debbugs.gnu.org; Thu, 16 Aug 2012 16:45:25 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48738) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T26wU-0001Ib-D6 for submit@debbugs.gnu.org; Thu, 16 Aug 2012 16:45:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T26nu-0004f1-4v for submit@debbugs.gnu.org; Thu, 16 Aug 2012 16:36:31 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:42428) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T26nu-0004ex-1d for submit@debbugs.gnu.org; Thu, 16 Aug 2012 16:36:30 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:42639) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T26ns-0006UV-MX for bug-gnu-emacs@gnu.org; Thu, 16 Aug 2012 16:36:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T26nq-0004eS-W2 for bug-gnu-emacs@gnu.org; Thu, 16 Aug 2012 16:36:28 -0400 Original-Received: from mail-gg0-f169.google.com ([209.85.161.169]:39154) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T26nq-0004eI-Rj for bug-gnu-emacs@gnu.org; Thu, 16 Aug 2012 16:36:26 -0400 Original-Received: by ggnf4 with SMTP id f4so3746804ggn.0 for ; Thu, 16 Aug 2012 13:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=qo/iRfSYtTQk0qF6S2jBjhn23xqV09sSnF2uDl27oqU=; b=Rmpr5looUgWmV8O9lRMoVDtAxBM8Y5HYIfzj1fU9XzX61Tcm+YqWkrDGa/2IQTCip8 9uepM8jfNWKdOIFTDD2eKn/BrW2wUwaIxZfCalLJ4b135cjy5Uy1JfcZ54d+8+sZOwn2 XaPo65V4zCRifodWPqv/u8NigVN9j+rnIbxsMCyqdBcVbkzc5REkep2rF2a47fsN/pYt C69YhuPwU6f7r7j2i5kia2zYOnrOUC25e/dqA9+rR0rMc/hyZwd5mff3AchsXo5Y8Upz xwcZurxJkxrH9BiPUDsKxzLwzNljX6b0YRnuErAH7lCTt19i69TcpJMVcnP/PBskBCHO zicw== Original-Received: by 10.50.15.202 with SMTP id z10mr3155044igc.50.1345149386089; Thu, 16 Aug 2012 13:36:26 -0700 (PDT) Original-Received: by 10.64.0.6 with HTTP; Thu, 16 Aug 2012 13:36:25 -0700 (PDT) In-Reply-To: <502CBF82.3080601@gmx.at> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:63233 On Thu, Aug 16, 2012 at 3:38 AM, martin rudalics wrote: >> Open two buffers "buffer1" and "buffer2" so that both are visible. >> >> Place the following in each buffer >> >> (with-current-buffer "buffer1" >> (goto-char (point-min)) >> (yes-or-no-p "") >> (insert "X")) >> >> C-xC-e from buffer1 places "X" at the beginning of the file, while >> C-xC-e from buffer2 places an "X" wherever the point was before moving >> from buffer1. This doesn't happen if only one buffer is visible; Nor >> does it happen if we replace "yes-or-no-p" with "y-or-n-p". >> This happens on both 23.3.1 and 24.1. > > Indeed. What you see is `save-window-excursion' at work. Let's remove > `yes-or-no-p' from the example. With emacs -Q in *scratch* evaluate the > following form: > > (let ((form > "(with-current-buffer \"*buffer1*\" > (goto-char (point-min)) > (save-window-excursion > nil) > (setq x (1+ x)) > (insert (format \"%s\" x)))")) > (setq x 0) > (switch-to-buffer (get-buffer-create "*buffer1*")) > (insert form) > (split-window) > (other-window 1) > (switch-to-buffer (get-buffer-create "*buffer2*")) > (insert form) > (other-window 1)) > > Now in any of the two windows go to the end of the buffer and evaluate > the preceding form. From the *buffer1* window the number is inserted at > position 1, from the *buffer2* window at the position of *buffer1* > before evaluating the form. If, instead, you used the slightly > different form > > (let ((form > "(with-selected-window (get-buffer-window \"*buffer1*\") > (goto-char (point-min)) > (save-window-excursion > nil) > (setq x (1+ x)) > (insert (format \"%s\" x)))")) > (setq x 0) > (switch-to-buffer (get-buffer-create "*buffer1*")) > (insert form) > (split-window) > (other-window 1) > (switch-to-buffer (get-buffer-create "*buffer2*")) > (insert form) > (other-window 1)) > > both insertions happen at position 1. > > martin Thanks for the examples. If I understand correctly, save-window-excursion ends with among other things restoring the window points; and each time a window point is set, the buffer point is set as well. And while the current buffer is restored, save-window-excursion does not restore the point in the current buffer, leaving it at the position set by the window point restore, if there was one. What I don't understand is the rationale for not restoring the current buffer point. Perhaps it's just windows have precedence in a restore. Steve