Subject: bug#20353: M-. sometimes jumps in another window

From: martin rudalics <[email-masked]>
Date: Tue, 21 Apr 2015 12:34:13 +0200

> Right, the remembering might be part of pop-to-buffer and quit-window
> rather than part of xref.  Either way is fine by me.

Would the attached patch fix it?

martin

--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5474,10 +5474,15 @@ element is BUFFER."
   (cond
    ((eq type 'reuse)
     (if (eq (window-buffer window) buffer)
-	;; WINDOW shows BUFFER already.
-	(when (consp (window-parameter window 'quit-restore))
-	  ;; If WINDOW has a quit-restore parameter, reset its car.
-	  (setcar (window-parameter window 'quit-restore) 'same))
+	;; WINDOW shows BUFFER already.  Update WINDOW's quit-restore
+	;; parameter, if any.
+	(let ((old (window-parameter window 'quit-restore)))
+	  (when (consp old)
+	    (set-window-parameter
+	     window 'quit-restore
+	     ;; The selected-window might have changed in between
+	     ;; (Bug#20353).
+	     (list 'same (nth 1 old) (selected-window) (nth 3 old)))))
       ;; WINDOW shows another buffer.
       (with-current-buffer (window-buffer window)
 	(set-window-parameter