From 24510c22a36564fe6c4b6f79a30fc41fee89b45b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 28 Nov 2011 14:43:52 -0500 Subject: * lisp/files.el (find-file): Don't use force-same-window. * lisp/window.el (switch-to-buffer): Better match Emacs-23 behavior and only use pop-to-buffer if the selected window can't be used. (pop-to-buffer-same-window): Use display-buffer--same-window-action. Fixes: debbugs:10144 --- lisp/ChangeLog | 7 +++++++ lisp/files.el | 2 +- lisp/window.el | 43 ++++++++++++++++++++++++------------------- 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7dabb7db106..2aded765af5 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2011-11-28 Stefan Monnier + + * files.el (find-file): Don't use force-same-window (bug#10144). + * window.el (switch-to-buffer): Better match Emacs-23 behavior and only + use pop-to-buffer if the selected window can't be used. + (pop-to-buffer-same-window): Use display-buffer--same-window-action. + 2011-11-28 Eli Zaretskii * vc/diff-mode.el (diff-mode-map): Don't inherit 'z' => 'M-z' from diff --git a/lisp/files.el b/lisp/files.el index 0f167ce3ffa..f903d2919a6 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1343,7 +1343,7 @@ automatically choosing a major mode, use \\[find-file-literally]." (let ((value (find-file-noselect filename nil nil wildcards))) (if (listp value) (mapcar 'switch-to-buffer (nreverse value)) - (switch-to-buffer value nil 'force-same-window)))) + (switch-to-buffer value)))) (defun find-file-other-window (filename &optional wildcards) "Edit file FILENAME, in another window. diff --git a/lisp/window.el b/lisp/window.el index 35d80e30ee3..69276a839bd 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -4515,6 +4515,12 @@ Return WINDOW." (set-window-dedicated-p window dedicated)) (window--display-buffer-1 window))) +;; FIXME: Not implemented. +;; FIXME: By the way, there could be more levels of dedication: +;; - `barely' dedicated doesn't prevent reuse of the window, only records that +;; the window hasn't been used for something else yet. +;; - `softly' dedicated only allows reuse when asked explicitly. +;; - `strongly' never allows reuse. (defvar display-buffer-mark-dedicated nil "If non-nil, `display-buffer' marks the windows it creates as dedicated. The actual non-nil value of this variable will be copied to the @@ -4945,10 +4951,7 @@ the buffer. NORECORD, if non-nil means do not put this buffer at the front of the list of recently selected ones." - (pop-to-buffer buffer - '(display-buffer-same-window - (inhibit-same-window . nil)) - norecord)) + (pop-to-buffer buffer display-buffer--same-window-action norecord)) (defun read-buffer-to-switch (prompt) "Read the name of a buffer to switch to, prompting with PROMPT. @@ -5013,21 +5016,23 @@ Return the buffer switched to." (interactive (list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window)) (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name))) - (if (null force-same-window) - (pop-to-buffer buffer display-buffer--same-window-action norecord) - (cond - ;; Don't call set-window-buffer if it's not needed since it - ;; might signal an error (e.g. if the window is dedicated). - ((eq buffer (window-buffer))) - ((window-minibuffer-p) - (error "Cannot switch buffers in minibuffer window")) - ((eq (window-dedicated-p) t) - (error "Cannot switch buffers in a dedicated window")) - (t (set-window-buffer nil buffer))) - - (unless norecord - (select-window (selected-window))) - (set-buffer buffer)))) + (cond + ;; Don't call set-window-buffer if it's not needed since it + ;; might signal an error (e.g. if the window is dedicated). + ((eq buffer (window-buffer))) + ((window-minibuffer-p) + (if force-same-window + (error "Cannot switch buffers in minibuffer window") + (pop-to-buffer buffer norecord))) + ((eq (window-dedicated-p) t) + (if force-same-window + (error "Cannot switch buffers in a dedicated window") + (pop-to-buffer buffer norecord))) + (t (set-window-buffer nil buffer))) + + (unless norecord + (select-window (selected-window))) + (set-buffer buffer))) (defun switch-to-buffer-other-window (buffer-or-name &optional norecord) "Select the buffer specified by BUFFER-OR-NAME in another window. -- cgit v1.2.3