aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/window.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/window.el')
-rw-r--r--lisp/window.el42
1 files changed, 25 insertions, 17 deletions
diff --git a/lisp/window.el b/lisp/window.el
index 999e408bdb1..593fa14d215 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5925,7 +5925,7 @@ buffer with the name BUFFER-OR-NAME and return that buffer."
5925 buffer)) 5925 buffer))
5926 (other-buffer))) 5926 (other-buffer)))
5927 5927
5928(defun switch-to-buffer (buffer-or-name &optional norecord) 5928(defun switch-to-buffer (buffer-or-name &optional norecord force-same-window)
5929 "Switch to buffer BUFFER-OR-NAME in the selected window. 5929 "Switch to buffer BUFFER-OR-NAME in the selected window.
5930If called interactively, prompt for the buffer name using the 5930If called interactively, prompt for the buffer name using the
5931minibuffer. The variable `confirm-nonexistent-file-or-buffer' 5931minibuffer. The variable `confirm-nonexistent-file-or-buffer'
@@ -5941,25 +5941,33 @@ BUFFER-OR-NAME is nil, switch to the buffer returned by
5941Optional argument NORECORD non-nil means do not put the buffer 5941Optional argument NORECORD non-nil means do not put the buffer
5942specified by BUFFER-OR-NAME at the front of the buffer list and 5942specified by BUFFER-OR-NAME at the front of the buffer list and
5943do not make the window displaying it the most recently selected 5943do not make the window displaying it the most recently selected
5944one. Return the buffer switched to. 5944one.
5945 5945
5946This function is intended for interactive use only. Lisp 5946If FORCE-SAME-WINDOW is non-nil, BUFFER-OR-NAME must be displayed
5947functions should call `pop-to-buffer-same-window' instead." 5947in the currently selected window; signal an error if that is
5948impossible (e.g. if the selected window is minibuffer-only).
5949If non-nil, BUFFER-OR-NAME may be displayed in another window.
5950
5951Return the buffer switched to."
5948 (interactive 5952 (interactive
5949 (list (read-buffer-to-switch "Switch to buffer: "))) 5953 (list (read-buffer-to-switch "Switch to buffer: ") nil nil))
5950 (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name))) 5954 (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)))
5951 (cond 5955 (if (null force-same-window)
5952 ;; Don't call set-window-buffer if it's not needed since it 5956 (pop-to-buffer buffer-or-name
5953 ;; might signal an error (e.g. if the window is dedicated). 5957 '(same-window (reuse-window-dedicated . weak))
5954 ((eq buffer (window-buffer)) nil) 5958 norecord nil)
5955 ((window-minibuffer-p) 5959 (cond
5956 (error "Cannot switch buffers in minibuffer window")) 5960 ;; Don't call set-window-buffer if it's not needed since it
5957 ((eq (window-dedicated-p) t) 5961 ;; might signal an error (e.g. if the window is dedicated).
5958 (error "Cannot switch buffers in a dedicated window")) 5962 ((eq buffer (window-buffer)) nil)
5959 (t (set-window-buffer nil buffer))) 5963 ((window-minibuffer-p)
5960 (unless norecord 5964 (error "Cannot switch buffers in minibuffer window"))
5961 (select-window (selected-window))) 5965 ((eq (window-dedicated-p) t)
5962 (set-buffer buffer))) 5966 (error "Cannot switch buffers in a dedicated window"))
5967 (t (set-window-buffer nil buffer)))
5968 (unless norecord
5969 (select-window (selected-window)))
5970 (set-buffer buffer))))
5963 5971
5964(defun switch-to-buffer-same-frame (buffer-or-name &optional norecord) 5972(defun switch-to-buffer-same-frame (buffer-or-name &optional norecord)
5965 "Switch to buffer BUFFER-OR-NAME in a window on the selected frame. 5973 "Switch to buffer BUFFER-OR-NAME in a window on the selected frame.