diff options
| author | Martin Rudalics | 2015-05-20 08:49:23 +0200 |
|---|---|---|
| committer | Martin Rudalics | 2015-05-20 08:49:23 +0200 |
| commit | 31d58d45249b3fb13a0a9a2c921f04cd9b42ff3f (patch) | |
| tree | a5c2f1b4826b1e7f972c88d6b992ba3dfc9ef05b /lisp | |
| parent | f743819b57ef519109c1b9d520d358d19a197086 (diff) | |
| download | emacs-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.el | 62 |
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. | ||
| 6889 | If non-nil, allow `switch-to-buffer' to proceed when called | ||
| 6890 | interactively and the selected window is strongly dedicated to | ||
| 6891 | its buffer. | ||
| 6892 | |||
| 6893 | The following values are recognized: | ||
| 6894 | |||
| 6895 | nil - disallow switching; signal an error | ||
| 6896 | |||
| 6897 | prompt - prompt user whether to allow switching | ||
| 6898 | |||
| 6899 | pop - perform `pop-to-buffer' instead | ||
| 6900 | |||
| 6901 | t - undedicate selected window and switch | ||
| 6902 | |||
| 6903 | When called non-interactively, `switch-to-buffer' always signals | ||
| 6904 | an error when the selected window is dedicated to its buffer and | ||
| 6905 | FORCE-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 | |||
| 6891 | within a Lisp program! Use `set-buffer' instead. That avoids | 6918 | within a Lisp program! Use `set-buffer' instead. That avoids |
| 6892 | messing with the window-buffer correspondences. | 6919 | messing with the window-buffer correspondences. |
| 6893 | 6920 | ||
| 6894 | If the selected window cannot display the specified | 6921 | If the selected window cannot display the specified buffer |
| 6895 | buffer (e.g. if it is a minibuffer window or strongly dedicated | 6922 | because it is a minibuffer window or strongly dedicated to |
| 6896 | to another buffer), call `pop-to-buffer' to select the buffer in | 6923 | another buffer, call `pop-to-buffer' to select the buffer in |
| 6897 | another window. | 6924 | another window. In interactive use, if the selected window is |
| 6925 | strongly dedicated to its buffer, the value of the option | ||
| 6926 | `switch-to-buffer-in-dedicated-window' specifies how to proceed. | ||
| 6898 | 6927 | ||
| 6899 | If called interactively, read the buffer name using the | 6928 | If called interactively, read the buffer name using the |
| 6900 | minibuffer. The variable `confirm-nonexistent-file-or-buffer' | 6929 | minibuffer. The variable `confirm-nonexistent-file-or-buffer' |
| @@ -6911,8 +6940,9 @@ at the front of the buffer list, and do not make the window | |||
| 6911 | displaying it the most recently selected one. | 6940 | displaying it the most recently selected one. |
| 6912 | 6941 | ||
| 6913 | If optional argument FORCE-SAME-WINDOW is non-nil, the buffer | 6942 | If optional argument FORCE-SAME-WINDOW is non-nil, the buffer |
| 6914 | must be displayed in the selected window; if that is impossible, | 6943 | must be displayed in the selected window when called |
| 6915 | signal an error rather than calling `pop-to-buffer'. | 6944 | non-interactively; if that is impossible, signal an error rather |
| 6945 | than calling `pop-to-buffer'. | ||
| 6916 | 6946 | ||
| 6917 | The option `switch-to-buffer-preserve-window-point' can be used | 6947 | The option `switch-to-buffer-preserve-window-point' can be used |
| 6918 | to make the buffer appear at its last position in the selected | 6948 | to make the buffer appear at its last position in the selected |
| @@ -6920,7 +6950,25 @@ window. | |||
| 6920 | 6950 | ||
| 6921 | Return the buffer switched to." | 6951 | Return 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 |