From: martin rudalics <rudalics@gmx.at>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 20472@debbugs.gnu.org, Ed Avis <eda@waniasset.com>
Subject: bug#20472: 24.4; Cannot switch buffers in a dedicated window - report this error earlier
Date: Tue, 05 May 2015 11:18:52 +0200 [thread overview]
Message-ID: <55488AFC.5040403@gmx.at> (raw)
In-Reply-To: <jwvr3qx5dtc.fsf-monnier+emacsbugs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 147 bytes --]
> (I'm not 100% sure prompting will turn out to be a good
> idea, but we can give it a try)
Then let's make it customizable right away.
martin
[-- Attachment #2: switch-to-buffer-in-dedicated-window.diff --]
[-- Type: text/plain, Size: 3773 bytes --]
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -6880,6 +6880,33 @@ the selected window or never appeared in it before, or if
:group 'windows
:version "24.3")
+(defcustom switch-to-buffer-in-dedicated-window nil
+ "Allow switching to buffer in dedicated window.
+If non-nil, allow `switch-to-buffer' to proceed when called
+interactively and the selected window is strongly dedicated to
+its buffer.
+
+The following values are recognized:
+
+nil - disallow switching; signal an error
+
+prompt - prompt user whether to allow switching
+
+pop - perform `pop-to-buffer' instead
+
+t - undedicate selected window and switch
+
+When called non-interactively, `switch-to-buffer' always signals
+an error when the selected window is dedicated to its buffer and
+FORCE-SAME-WINDOW is non-nil."
+ :type '(choice
+ (const :tag "Disallow" nil)
+ (const :tag "Prompt" prompt)
+ (const :tag "Pop" pop)
+ (const :tag "Allow" t))
+ :group 'windows
+ :version "25.1")
+
(defun switch-to-buffer (buffer-or-name &optional norecord force-same-window)
"Display buffer BUFFER-OR-NAME in the selected window.
@@ -6887,10 +6914,12 @@ WARNING: This is NOT the way to work on another buffer temporarily
within a Lisp program! Use `set-buffer' instead. That avoids
messing with the window-buffer correspondences.
-If the selected window cannot display the specified
-buffer (e.g. if it is a minibuffer window or strongly dedicated
-to another buffer), call `pop-to-buffer' to select the buffer in
-another window.
+If the selected window cannot display the specified buffer
+because it is a minibuffer window or strongly dedicated to
+another buffer, call `pop-to-buffer' to select the buffer in
+another window. In interactive use, if the selected window is
+dedicated to its buffer `switch-to-buffer-in-dedicated-window'
+specifies how to proceed.
If called interactively, read the buffer name using the
minibuffer. The variable `confirm-nonexistent-file-or-buffer'
@@ -6907,8 +6936,9 @@ at the front of the buffer list, and do not make the window
displaying it the most recently selected one.
If optional argument FORCE-SAME-WINDOW is non-nil, the buffer
-must be displayed in the selected window; if that is impossible,
-signal an error rather than calling `pop-to-buffer'.
+must be displayed in the selected window when called
+non-interactively; if that is impossible, signal an error rather
+than calling `pop-to-buffer'.
The option `switch-to-buffer-preserve-window-point' can be used
to make the buffer appear at its last position in the selected
@@ -6916,7 +6946,25 @@ window.
Return the buffer switched to."
(interactive
- (list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window))
+ (let ((force-same-window
+ (cond
+ ((window-minibuffer-p) nil)
+ ((not (eq (window-dedicated-p) t)) 'force-same-window)
+ ((pcase switch-to-buffer-in-dedicated-window
+ (`nil (user-error
+ "Cannot switch buffers in a dedicated window"))
+ (`prompt
+ (if (y-or-n-p
+ (format "Window is dedicated to %s; undedicate it"
+ (window-buffer)))
+ (progn
+ (set-window-dedicated-p nil nil)
+ 'force-same-window)
+ (user-error
+ "Cannot switch buffers in a dedicated window")))
+ (`pop nil)
+ (_ (set-window-dedicated-p nil nil) 'force-same-window))))))
+ (list (read-buffer-to-switch "Switch to buffer: ") nil force-same-window)))
(let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)))
(cond
;; Don't call set-window-buffer if it's not needed since it
next prev parent reply other threads:[~2015-05-05 9:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-30 15:33 bug#20472: 24.4; Cannot switch buffers in a dedicated window - report this error earlier Ed Avis
2015-04-30 16:30 ` martin rudalics
2015-05-01 1:46 ` Stefan Monnier
2015-05-01 10:41 ` martin rudalics
2015-05-01 18:06 ` Stefan Monnier
2015-05-02 8:57 ` martin rudalics
2015-05-04 1:31 ` Stefan Monnier
2015-05-05 9:18 ` martin rudalics [this message]
2015-05-20 9:47 ` martin rudalics
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55488AFC.5040403@gmx.at \
--to=rudalics@gmx.at \
--cc=20472@debbugs.gnu.org \
--cc=eda@waniasset.com \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.