Commit 75a1d009 authored by Anders Lindgren's avatar Anders Lindgren
Browse files

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.
parent eb3f6754
......@@ -865,10 +865,10 @@ Note that this handles the case when the cache has been set to nil."
(let ((orig-win (selected-window))
(dolist (w windows)
(select-window w)
(select-window w 'norecord)
(push (cons w (cons (window-start) (follow-calc-win-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))
(select-frame frame)
(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)
(setq orig-window (selected-window)))
(setq buffers (cons buf buffers)))))
(select-frame orig-frame)
(set-buffer orig-buffer)
(select-window orig-window)))))
(let ((orig-frame (selected-frame)))
(select-frame frame)
(let ((picked-window (selected-window)) ; Note: May change below.
(seen-buffers '()))
(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)
(setq picked-window (selected-window))))
(push buf seen-buffers)))))
(select-window picked-window 'norecord)))
(select-frame orig-frame)))))
(add-hook 'window-scroll-functions 'follow-avoid-tail-recenter t)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment