[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#12208: yes-or-no-p escapes with-current-buffer
From: |
martin rudalics |
Subject: |
bug#12208: yes-or-no-p escapes with-current-buffer |
Date: |
Thu, 16 Aug 2012 11:38:10 +0200 |
> 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
- bug#12208: yes-or-no-p escapes with-current-buffer, Steve Hafner, 2012/08/16
- bug#12208: yes-or-no-p escapes with-current-buffer,
martin rudalics <=
- bug#12208: yes-or-no-p escapes with-current-buffer, Steve Hafner, 2012/08/16
- bug#12208: yes-or-no-p escapes with-current-buffer, martin rudalics, 2012/08/17
- bug#12208: yes-or-no-p escapes with-current-buffer, martin rudalics, 2012/08/17
- bug#12208: yes-or-no-p escapes with-current-buffer, Steve Hafner, 2012/08/17
- bug#12208: yes-or-no-p escapes with-current-buffer, Steve Hafner, 2012/08/17
- bug#12208: yes-or-no-p escapes with-current-buffer, martin rudalics, 2012/08/18
- bug#12208: yes-or-no-p escapes with-current-buffer, Steve Hafner, 2012/08/18
- bug#12208: yes-or-no-p escapes with-current-buffer, martin rudalics, 2012/08/18
- bug#12208: yes-or-no-p escapes with-current-buffer, martin rudalics, 2012/08/27