aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Rudalics2015-05-20 08:49:23 +0200
committerMartin Rudalics2015-05-20 08:49:23 +0200
commit31d58d45249b3fb13a0a9a2c921f04cd9b42ff3f (patch)
treea5c2f1b4826b1e7f972c88d6b992ba3dfc9ef05b
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'.
-rw-r--r--doc/lispref/windows.texi49
-rw-r--r--etc/NEWS13
-rw-r--r--lisp/window.el62
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
2005list (@pxref{Buffer List}). However, this is not done if the 2005list (@pxref{Buffer List}). However, this is not done if the
2006optional argument @var{norecord} is non-@code{nil}. 2006optional argument @var{norecord} is non-@code{nil}.
2007 2007
2008Sometimes, @code{switch-to-buffer} may be unable to display the buffer 2008Sometimes, the selected window may not be suitable for displaying the
2009in the selected window. This happens if the selected window is a 2009buffer. This happens if the selected window is a minibuffer window, or
2010minibuffer window, or if the selected window is strongly dedicated to 2010if the selected window is strongly dedicated to its buffer
2011its buffer (@pxref{Dedicated Windows}). In that case, the command 2011(@pxref{Dedicated Windows}). In such cases, the command normally tries
2012normally tries to display the buffer in some other window, by invoking 2012to 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
2015instead. 2015If the optional argument @var{force-same-window} is non-@code{nil} and
2016the selected window is not suitable for displaying the buffer, this
2017function always signals an error when called non-interactively. In
2018interactive use, if the selected window is a minibuffer window, this
2019function will try to use some other window instead. If the selected
2020window is strongly dedicated to its buffer, the option
2021@code{switch-to-buffer-in-dedicated-window} described next can be used
2022to proceed.
2016@end deffn 2023@end deffn
2017 2024
2025@defopt switch-to-buffer-in-dedicated-window
2026This option, if non-@code{nil}, allows @code{switch-to-buffer} to
2027proceed when called interactively and the selected window is strongly
2028dedicated to its buffer.
2029
2030The following values are respected:
2031
2032@table @code
2033@item nil
2034Disallows switching and signals an error as in non-interactive use.
2035
2036@item prompt
2037Prompts the user whether to allow switching.
2038
2039@item pop
2040Invokes @code{pop-to-buffer} to proceed.
2041
2042@item t
2043Marks the selected window as non-dedicated and proceeds.
2044@end table
2045
2046When called non-interactively, @code{switch-to-buffer} always signals an
2047error when the selected window is dedicated to its buffer and
2048@var{force-same-window} is non-@code{nil}.
2049@end defopt
2050
2018By default, @code{switch-to-buffer} shows the buffer at its position of 2051By 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
diff --git a/etc/NEWS b/etc/NEWS
index c4c9d774b5f..2540756b9be 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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
166files (recursively) under a directory. 166files (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
169name (as returned from, for instance, `file-name-all-completions' is 169name (as returned from, for instance, `file-name-all-completions' is
170a directory file name. It returns non-nil if the last character in 170a directory file name. It returns non-nil if the last character in
171the name is a forward slash. 171the name is a forward slash.
@@ -585,8 +585,8 @@ nil to disable this.
585fitting for use in money calculations; factorial works with 585fitting for use in money calculations; factorial works with
586non-integer inputs. 586non-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. 589interactive 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
592name patterns. Default case-insensitive .h, .hh, .hpp and .hxx. 592name 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
755from which the minibuffer was entered, call it with the new argument 755from 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
761active region handling. 761active region handling.
@@ -960,6 +960,11 @@ fullwidth frames, the behavior may depend on the toolkit used.
960windows without "fixing" it. It's supported by `fit-window-to-buffer', 960windows 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
965how `switch-to-buffer' proceeds interactively when the selected window
966is 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.
964Those features have been deprecated in Gtk+ for a long time. 969Those 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.
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