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 | |
| 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'.
| -rw-r--r-- | doc/lispref/windows.texi | 49 | ||||
| -rw-r--r-- | etc/NEWS | 13 | ||||
| -rw-r--r-- | lisp/window.el | 62 |
3 files changed, 105 insertions, 19 deletions
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi index 6da3582ddd1..b2bc6378008 100644 --- a/doc/lispref/windows.texi +++ b/doc/lispref/windows.texi | |||
| @@ -2005,16 +2005,49 @@ list---both the global buffer list and the selected frame's buffer | |||
| 2005 | list (@pxref{Buffer List}). However, this is not done if the | 2005 | list (@pxref{Buffer List}). However, this is not done if the |
| 2006 | optional argument @var{norecord} is non-@code{nil}. | 2006 | optional argument @var{norecord} is non-@code{nil}. |
| 2007 | 2007 | ||
| 2008 | Sometimes, @code{switch-to-buffer} may be unable to display the buffer | 2008 | Sometimes, the selected window may not be suitable for displaying the |
| 2009 | in the selected window. This happens if the selected window is a | 2009 | buffer. This happens if the selected window is a minibuffer window, or |
| 2010 | minibuffer window, or if the selected window is strongly dedicated to | 2010 | if the selected window is strongly dedicated to its buffer |
| 2011 | its buffer (@pxref{Dedicated Windows}). In that case, the command | 2011 | (@pxref{Dedicated Windows}). In such cases, the command normally tries |
| 2012 | normally tries to display the buffer in some other window, by invoking | 2012 | to display the buffer in some other window, by invoking |
| 2013 | @code{pop-to-buffer} (see below). However, if the optional argument | 2013 | @code{pop-to-buffer} (see below). |
| 2014 | @var{force-same-window} is non-@code{nil}, it signals an error | 2014 | |
| 2015 | instead. | 2015 | If the optional argument @var{force-same-window} is non-@code{nil} and |
| 2016 | the selected window is not suitable for displaying the buffer, this | ||
| 2017 | function always signals an error when called non-interactively. In | ||
| 2018 | interactive use, if the selected window is a minibuffer window, this | ||
| 2019 | function will try to use some other window instead. If the selected | ||
| 2020 | window is strongly dedicated to its buffer, the option | ||
| 2021 | @code{switch-to-buffer-in-dedicated-window} described next can be used | ||
| 2022 | to proceed. | ||
| 2016 | @end deffn | 2023 | @end deffn |
| 2017 | 2024 | ||
| 2025 | @defopt switch-to-buffer-in-dedicated-window | ||
| 2026 | This option, if non-@code{nil}, allows @code{switch-to-buffer} to | ||
| 2027 | proceed when called interactively and the selected window is strongly | ||
| 2028 | dedicated to its buffer. | ||
| 2029 | |||
| 2030 | The following values are respected: | ||
| 2031 | |||
| 2032 | @table @code | ||
| 2033 | @item nil | ||
| 2034 | Disallows switching and signals an error as in non-interactive use. | ||
| 2035 | |||
| 2036 | @item prompt | ||
| 2037 | Prompts the user whether to allow switching. | ||
| 2038 | |||
| 2039 | @item pop | ||
| 2040 | Invokes @code{pop-to-buffer} to proceed. | ||
| 2041 | |||
| 2042 | @item t | ||
| 2043 | Marks the selected window as non-dedicated and proceeds. | ||
| 2044 | @end table | ||
| 2045 | |||
| 2046 | When called non-interactively, @code{switch-to-buffer} always signals an | ||
| 2047 | error when the selected window is dedicated to its buffer and | ||
| 2048 | @var{force-same-window} is non-@code{nil}. | ||
| 2049 | @end defopt | ||
| 2050 | |||
| 2018 | By default, @code{switch-to-buffer} shows the buffer at its position of | 2051 | By default, @code{switch-to-buffer} shows the buffer at its position of |
| 2019 | @code{point}. This behavior can be tuned using the following option. | 2052 | @code{point}. This behavior can be tuned using the following option. |
| 2020 | 2053 | ||
| @@ -165,7 +165,7 @@ buffers to allow certain parts of the text to be writable. | |||
| 165 | ** A new function `directory-files-recursively' returns all matching | 165 | ** A new function `directory-files-recursively' returns all matching |
| 166 | files (recursively) under a directory. | 166 | files (recursively) under a directory. |
| 167 | 167 | ||
| 168 | ** The new `directory-name-p' can be used to check whether a file | 168 | ** The new function `directory-name-p' can be used to check whether a file |
| 169 | name (as returned from, for instance, `file-name-all-completions' is | 169 | name (as returned from, for instance, `file-name-all-completions' is |
| 170 | a directory file name. It returns non-nil if the last character in | 170 | a directory file name. It returns non-nil if the last character in |
| 171 | the name is a forward slash. | 171 | the name is a forward slash. |
| @@ -585,8 +585,8 @@ nil to disable this. | |||
| 585 | fitting for use in money calculations; factorial works with | 585 | fitting for use in money calculations; factorial works with |
| 586 | non-integer inputs. | 586 | non-integer inputs. |
| 587 | 587 | ||
| 588 | ** HideIfDef mode now support full C/C++ expressions, argumented macro expansions | 588 | ** HideIfDef mode now support full C/C++ expressions, argumented macro expansions, |
| 589 | , interactive macro evaluation and automatic scanning of #defined symbols. | 589 | interactive macro evaluation and automatic scanning of #defined symbols. |
| 590 | 590 | ||
| 591 | *** New custom variable `hide-ifdef-header-regexp' to define C/C++ header file | 591 | *** New custom variable `hide-ifdef-header-regexp' to define C/C++ header file |
| 592 | name patterns. Default case-insensitive .h, .hh, .hpp and .hxx. | 592 | name patterns. Default case-insensitive .h, .hh, .hpp and .hxx. |
| @@ -755,7 +755,7 @@ If you want the old behavior of calling the function in the buffer | |||
| 755 | from which the minibuffer was entered, call it with the new argument | 755 | from which the minibuffer was entered, call it with the new argument |
| 756 | `switch-buffer'. | 756 | `switch-buffer'. |
| 757 | 757 | ||
| 758 | ** window-configurations no longer record the buffers's marks. | 758 | ** window-configurations no longer record the buffers' marks. |
| 759 | 759 | ||
| 760 | ** inhibit-modification-hooks now also inhibits lock-file checks, as well as | 760 | ** inhibit-modification-hooks now also inhibits lock-file checks, as well as |
| 761 | active region handling. | 761 | active region handling. |
| @@ -960,6 +960,11 @@ fullwidth frames, the behavior may depend on the toolkit used. | |||
| 960 | windows without "fixing" it. It's supported by `fit-window-to-buffer', | 960 | windows without "fixing" it. It's supported by `fit-window-to-buffer', |
| 961 | `temp-buffer-resize-mode' and `display-buffer'. | 961 | `temp-buffer-resize-mode' and `display-buffer'. |
| 962 | 962 | ||
| 963 | +++ | ||
| 964 | ** New option `switch-to-buffer-in-dedicated-window' allows to customize | ||
| 965 | how `switch-to-buffer' proceeds interactively when the selected window | ||
| 966 | is strongly dedicated to its buffer. | ||
| 967 | |||
| 963 | ** Tearoff menus and detachable toolbars for Gtk+ has been removed. | 968 | ** Tearoff menus and detachable toolbars for Gtk+ has been removed. |
| 964 | Those features have been deprecated in Gtk+ for a long time. | 969 | Those features have been deprecated in Gtk+ for a long time. |
| 965 | 970 | ||
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 |