--- a/lisp/window.el +++ b/lisp/window.el @@ -6887,10 +6887,13 @@ 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. But if the optional argument FORCE-SAME-WINDOW +is non-nil and the selected window is strongly dedicated to its +buffer, prompt the user whether to undedicate the selected window +first. If called interactively, read the buffer name using the minibuffer. The variable `confirm-nonexistent-file-or-buffer' @@ -6906,10 +6909,6 @@ If optional argument NORECORD is non-nil, do not put the buffer at the front of the buffer list, and do not make the window displaying it the most recently selected one. -If optional argument FORCE-SAME-WINDOW is non-nil, the buffer -must be displayed in the selected window; if that is impossible, -signal an error rather than calling `pop-to-buffer'. - The option `switch-to-buffer-preserve-window-point' can be used to make the buffer appear at its last position in the selected window. @@ -6923,13 +6922,14 @@ Return the buffer switched to." ;; might signal an error (e.g. if the window is dedicated). ((eq buffer (window-buffer))) ((window-minibuffer-p) - (if force-same-window - (user-error "Cannot switch buffers in minibuffer window") - (pop-to-buffer buffer norecord))) - ((eq (window-dedicated-p) t) - (if force-same-window - (user-error "Cannot switch buffers in a dedicated window") - (pop-to-buffer buffer norecord))) + (pop-to-buffer buffer norecord)) + ((and (eq (window-dedicated-p) t) + (or (not force-same-window) + (not (y-or-n-p + (format "Window is dedicated to %s; undedicate it" + (window-buffer)))) + (set-window-dedicated-p nil nil))) + (pop-to-buffer buffer norecord)) (t (let* ((entry (assq buffer (window-prev-buffers))) (displayed (and (eq switch-to-buffer-preserve-window-point