--- a/lisp/window.el +++ b/lisp/window.el @@ -6887,10 +6887,11 @@ WARNING: This is NOT the way to work on another buffer temporarily within a Lisp program! Use `set-buffer' instead. That avoids messing with the window-buffer correspondences. -If the selected window cannot display the specified -buffer (e.g. if it is a minibuffer window or strongly dedicated -to another buffer), call `pop-to-buffer' to select the buffer in -another window. +If the selected window cannot display the specified buffer +because it is a minibuffer window or strongly dedicated to +another buffer, call `pop-to-buffer' to select the buffer in +another window. In interactive use offer to undedicate the +selected window before. If called interactively, read the buffer name using the minibuffer. The variable `confirm-nonexistent-file-or-buffer' @@ -6916,7 +6917,15 @@ window. Return the buffer switched to." (interactive - (list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window)) + (let ((force-same-window + (and (not (window-minibuffer-p)) + (or (not (eq (window-dedicated-p) t)) + (and (y-or-n-p + (format "Window is dedicated to %s; undedicate it" + (window-buffer))) + (or (set-window-dedicated-p nil nil) t))) + 'force-same-window))) + (list (read-buffer-to-switch "Switch to buffer: ") nil force-same-window))) (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name))) (cond ;; Don't call set-window-buffer if it's not needed since it