summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Lindgren <andlind@gmail.com>2015-11-20 21:07:29 +0100
committerAnders Lindgren <andlind@gmail.com>2015-11-20 21:07:29 +0100
commit75a1d009f747a220c7b9b1cfdbe7077082fe02d6 (patch)
treeb2085b2ace71972d21c755fe17372b3a7fcdb855
parenteb3f6754b446a9da59b51a0bef365e5076a7cf8c (diff)
downloademacs-75a1d009f747a220c7b9b1cfdbe7077082fe02d6.tar.gz
Fixed bug#19576: `write-file' saves wrong buffer.
If a function on the hook `window-size-change-functions' doesn't restore the current buffer, functions that save and restore the current window configuration (like `y-or-no-p') could silently change the current buffer. When `write-file' asked the user confirmation to overwrite a file, `y-or-no-p' changed the current buffer, and the wrong buffer was saved to the file. * lisp/follow.el (follow-windows-start-end): Call `select-frame' using the `norecord' parameter. (follow-window-size-change): Restore current buffer. Call `select-frame' using the `norecord' parameter. Cleanup.
-rw-r--r--lisp/follow.el55
1 files changed, 26 insertions, 29 deletions
diff --git a/lisp/follow.el b/lisp/follow.el
index 57ba2f6ca0a..37de923e6a5 100644
--- a/lisp/follow.el
+++ b/lisp/follow.el
@@ -865,10 +865,10 @@ Note that this handles the case when the cache has been set to nil."
(let ((orig-win (selected-window))
win-start-end)
(dolist (w windows)
- (select-window w)
+ (select-window w 'norecord)
(push (cons w (cons (window-start) (follow-calc-win-end)))
win-start-end))
- (select-window orig-win)
+ (select-window orig-win 'norecord)
(setq follow-windows-start-end-cache (nreverse win-start-end)))))
(defsubst follow-pos-visible (pos win win-start-end)
@@ -1416,33 +1416,30 @@ non-first windows in Follow mode."
"Redraw all windows in FRAME, when in Follow mode."
;; Below, we call `post-command-hook'. Avoid an infloop.
(unless follow-inside-post-command-hook
- (let ((buffers '())
- (orig-window (selected-window))
- (orig-buffer (current-buffer))
- (orig-frame (selected-frame))
- windows
- buf)
- (select-frame frame)
- (unwind-protect
- (walk-windows
- (lambda (win)
- (setq buf (window-buffer win))
- (unless (memq buf buffers)
- (set-buffer buf)
- (when follow-mode
- (setq windows (follow-all-followers win))
- (if (not (memq orig-window windows))
- (follow-redisplay windows win)
- ;; Make sure we're redrawing around the selected
- ;; window.
- (select-window orig-window)
- (follow-post-command-hook)
- (setq orig-window (selected-window)))
- (setq buffers (cons buf buffers)))))
- 'no-minibuf)
- (select-frame orig-frame)
- (set-buffer orig-buffer)
- (select-window orig-window)))))
+ (save-current-buffer
+ (let ((orig-frame (selected-frame)))
+ (select-frame frame)
+ (let ((picked-window (selected-window)) ; Note: May change below.
+ (seen-buffers '()))
+ (unwind-protect
+ (walk-windows
+ (lambda (win)
+ (let ((buf (window-buffer win)))
+ (unless (memq buf seen-buffers)
+ (set-buffer buf)
+ (when follow-mode
+ (let ((windows (follow-all-followers win)))
+ (if (not (memq picked-window windows))
+ (follow-redisplay windows win)
+ ;; Make sure we're redrawing around the selected
+ ;; window.
+ (select-window picked-window 'norecord)
+ (follow-post-command-hook)
+ (setq picked-window (selected-window))))
+ (push buf seen-buffers)))))
+ 'no-minibuf)
+ (select-window picked-window 'norecord)))
+ (select-frame orig-frame)))))
(add-hook 'window-scroll-functions 'follow-avoid-tail-recenter t)