]> code.delx.au - gnu-emacs/commitdiff
Fixed bug#19576: `write-file' saves wrong buffer.
authorAnders Lindgren <andlind@gmail.com>
Fri, 20 Nov 2015 20:07:29 +0000 (21:07 +0100)
committerAnders Lindgren <andlind@gmail.com>
Fri, 20 Nov 2015 20:07:29 +0000 (21:07 +0100)
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.

lisp/follow.el

index 57ba2f6ca0a934a7c0d8bcfa2c2a92cc98242419..37de923e6a5d2c73dd0bd94d87778a395d838c8c 100644 (file)
@@ -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)