unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Steve Hafner <steve.b.hafner@gmail.com>
To: 12208@debbugs.gnu.org
Subject: bug#12208: yes-or-no-p escapes with-current-buffer
Date: Thu, 16 Aug 2012 14:36:25 -0600	[thread overview]
Message-ID: <CAOy7MZJFxyF4JrZr9ep7RacZs=-Kayzc_uGUiRhZU=U6LniWeA@mail.gmail.com> (raw)
In-Reply-To: <502CBF82.3080601@gmx.at>

On Thu, Aug 16, 2012 at 3:38 AM, martin rudalics <rudalics@gmx.at> 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





  reply	other threads:[~2012-08-16 20:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-16  4:37 bug#12208: yes-or-no-p escapes with-current-buffer Steve Hafner
2012-08-16  9:38 ` martin rudalics
2012-08-16 20:36   ` Steve Hafner [this message]
2012-08-17 12:09     ` martin rudalics
2012-08-17 15:18       ` martin rudalics
2012-08-17 20:24         ` Steve Hafner
2012-08-18  2:55           ` Steve Hafner
2012-08-18 13:15             ` martin rudalics
2012-08-18 16:39               ` Steve Hafner
2012-08-18 17:38                 ` martin rudalics
2012-08-27  9:15               ` martin rudalics

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOy7MZJFxyF4JrZr9ep7RacZs=-Kayzc_uGUiRhZU=U6LniWeA@mail.gmail.com' \
    --to=steve.b.hafner@gmail.com \
    --cc=12208@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).