aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMartin Rudalics2015-05-20 08:49:23 +0200
committerMartin Rudalics2015-05-20 08:49:23 +0200
commit31d58d45249b3fb13a0a9a2c921f04cd9b42ff3f (patch)
treea5c2f1b4826b1e7f972c88d6b992ba3dfc9ef05b /lisp
parentf743819b57ef519109c1b9d520d358d19a197086 (diff)
downloademacs-31d58d45249b3fb13a0a9a2c921f04cd9b42ff3f.tar.gz
emacs-31d58d45249b3fb13a0a9a2c921f04cd9b42ff3f.zip
Improve `switch-to-buffer' in strongly dedicated windows (Bug#20472)
* lisp/window.el (switch-to-buffer-in-dedicated-window): New option. (switch-to-buffer): If the selected window is strongly dedicated to its buffer, signal error before prompting for buffer name. Handle `switch-to-buffer-in-dedicated-window'. (Bug#20472) * doc/lispref/windows.texi (Switching Buffers): Document `switch-to-buffer-in-dedicated-window'.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/window.el62
1 files changed, 55 insertions, 7 deletions
diff --git a/lisp/window.el b/lisp/window.el
index 49b7e2cc55d..c13499f542b 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -6884,6 +6884,33 @@ the selected window or never appeared in it before, or if
6884 :group 'windows 6884 :group 'windows
6885 :version "24.3") 6885 :version "24.3")
6886 6886
6887(defcustom switch-to-buffer-in-dedicated-window nil
6888 "Allow switching to buffer in strongly dedicated windows.
6889If non-nil, allow `switch-to-buffer' to proceed when called
6890interactively and the selected window is strongly dedicated to
6891its buffer.
6892
6893The following values are recognized:
6894
6895nil - disallow switching; signal an error
6896
6897prompt - prompt user whether to allow switching
6898
6899pop - perform `pop-to-buffer' instead
6900
6901t - undedicate selected window and switch
6902
6903When called non-interactively, `switch-to-buffer' always signals
6904an error when the selected window is dedicated to its buffer and
6905FORCE-SAME-WINDOW is non-nil."
6906 :type '(choice
6907 (const :tag "Disallow" nil)
6908 (const :tag "Prompt" prompt)
6909 (const :tag "Pop" pop)
6910 (const :tag "Allow" t))
6911 :group 'windows
6912 :version "25.1")
6913
6887(defun switch-to-buffer (buffer-or-name &optional norecord force-same-window) 6914(defun switch-to-buffer (buffer-or-name &optional norecord force-same-window)
6888 "Display buffer BUFFER-OR-NAME in the selected window. 6915 "Display buffer BUFFER-OR-NAME in the selected window.
6889 6916
@@ -6891,10 +6918,12 @@ WARNING: This is NOT the way to work on another buffer temporarily
6891within a Lisp program! Use `set-buffer' instead. That avoids 6918within a Lisp program! Use `set-buffer' instead. That avoids
6892messing with the window-buffer correspondences. 6919messing with the window-buffer correspondences.
6893 6920
6894If the selected window cannot display the specified 6921If the selected window cannot display the specified buffer
6895buffer (e.g. if it is a minibuffer window or strongly dedicated 6922because it is a minibuffer window or strongly dedicated to
6896to another buffer), call `pop-to-buffer' to select the buffer in 6923another buffer, call `pop-to-buffer' to select the buffer in
6897another window. 6924another window. In interactive use, if the selected window is
6925strongly dedicated to its buffer, the value of the option
6926`switch-to-buffer-in-dedicated-window' specifies how to proceed.
6898 6927
6899If called interactively, read the buffer name using the 6928If called interactively, read the buffer name using the
6900minibuffer. The variable `confirm-nonexistent-file-or-buffer' 6929minibuffer. The variable `confirm-nonexistent-file-or-buffer'
@@ -6911,8 +6940,9 @@ at the front of the buffer list, and do not make the window
6911displaying it the most recently selected one. 6940displaying it the most recently selected one.
6912 6941
6913If optional argument FORCE-SAME-WINDOW is non-nil, the buffer 6942If optional argument FORCE-SAME-WINDOW is non-nil, the buffer
6914must be displayed in the selected window; if that is impossible, 6943must be displayed in the selected window when called
6915signal an error rather than calling `pop-to-buffer'. 6944non-interactively; if that is impossible, signal an error rather
6945than calling `pop-to-buffer'.
6916 6946
6917The option `switch-to-buffer-preserve-window-point' can be used 6947The option `switch-to-buffer-preserve-window-point' can be used
6918to make the buffer appear at its last position in the selected 6948to make the buffer appear at its last position in the selected
@@ -6920,7 +6950,25 @@ window.
6920 6950
6921Return the buffer switched to." 6951Return the buffer switched to."
6922 (interactive 6952 (interactive
6923 (list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window)) 6953 (let ((force-same-window
6954 (cond
6955 ((window-minibuffer-p) nil)
6956 ((not (eq (window-dedicated-p) t)) 'force-same-window)
6957 ((pcase switch-to-buffer-in-dedicated-window
6958 (`nil (user-error
6959 "Cannot switch buffers in a dedicated window"))
6960 (`prompt
6961 (if (y-or-n-p
6962 (format "Window is dedicated to %s; undedicate it"
6963 (window-buffer)))
6964 (progn
6965 (set-window-dedicated-p nil nil)
6966 'force-same-window)
6967 (user-error
6968 "Cannot switch buffers in a dedicated window")))
6969 (`pop nil)
6970 (_ (set-window-dedicated-p nil nil) 'force-same-window))))))
6971 (list (read-buffer-to-switch "Switch to buffer: ") nil force-same-window)))
6924 (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name))) 6972 (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)))
6925 (cond 6973 (cond
6926 ;; Don't call set-window-buffer if it's not needed since it 6974 ;; Don't call set-window-buffer if it's not needed since it