From: Chong Yidong <cyd@stupidchicken.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Juanma Barranquero <lekktu@gmail.com>,
emacs-devel@gnu.org, martin rudalics <rudalics@gmx.at>
Subject: Re: switch-to-buffer: for interactive use only
Date: Sat, 09 Jul 2011 15:25:29 -0400 [thread overview]
Message-ID: <871uxzxnme.fsf@stupidchicken.com> (raw)
In-Reply-To: <jwvhb6wqhlv.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 08 Jul 2011 23:09:38 -0400")
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> Fair enough. So, I propose the following:
>> - Make switch-to-buffer basically do
>> (pop-to-buffer buffer-or-name 'same-window norecord label)
>
> OK. So mostly revert to Emacs-23 behavior.
>
> Note that (set-window-buffer (selected-window) buffer) isn't quite
> good enough, since set-window-buffer will be happy to change the
> buffer of a mini-window, whereas callers of switch-to-buffer that want
> to operate on the selected window should signal an error in that case.
> I think adding a `selected-window-only' argument to switch-to-buffer
> is a better solution so callers don't need to worry about such details
> of set-window-buffer.
How's this patch?
*** lisp/window.el 2011-07-09 12:32:38 +0000
--- lisp/window.el 2011-07-09 19:21:36 +0000
***************
*** 5925,5931 ****
buffer))
(other-buffer)))
! (defun switch-to-buffer (buffer-or-name &optional norecord)
"Switch to buffer BUFFER-OR-NAME in the selected window.
If called interactively, prompt for the buffer name using the
minibuffer. The variable `confirm-nonexistent-file-or-buffer'
--- 5925,5931 ----
buffer))
(other-buffer)))
! (defun switch-to-buffer (buffer-or-name &optional norecord force-same-window)
"Switch to buffer BUFFER-OR-NAME in the selected window.
If called interactively, prompt for the buffer name using the
minibuffer. The variable `confirm-nonexistent-file-or-buffer'
***************
*** 5941,5965 ****
Optional argument NORECORD non-nil means do not put the buffer
specified by BUFFER-OR-NAME at the front of the buffer list and
do not make the window displaying it the most recently selected
! one. Return the buffer switched to.
! This function is intended for interactive use only. Lisp
! functions should call `pop-to-buffer-same-window' instead."
(interactive
(list (read-buffer-to-switch "Switch to buffer: ")))
(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
! ;; might signal an error (e.g. if the window is dedicated).
! ((eq buffer (window-buffer)) nil)
! ((window-minibuffer-p)
! (error "Cannot switch buffers in minibuffer window"))
! ((eq (window-dedicated-p) t)
! (error "Cannot switch buffers in a dedicated window"))
! (t (set-window-buffer nil buffer)))
! (unless norecord
! (select-window (selected-window)))
! (set-buffer buffer)))
(defun switch-to-buffer-same-frame (buffer-or-name &optional norecord)
"Switch to buffer BUFFER-OR-NAME in a window on the selected frame.
--- 5941,5967 ----
Optional argument NORECORD non-nil means do not put the buffer
specified by BUFFER-OR-NAME at the front of the buffer list and
do not make the window displaying it the most recently selected
! one.
! If the selected window is weakly dedicated, switch to
! BUFFER-OR-NAME anyway (see `set-window-dedicated-p'). If the
! selected window is strongly dedicated, display BUFFER-OR-NAME in
! another window if FORCE-SAME-WINDOW is nil, and signal an error
! if FORCE-SAME-WINDOW if non-nil.
!
! Return the buffer switched to."
(interactive
(list (read-buffer-to-switch "Switch to buffer: ")))
(let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)))
! (when force-same-window
! (cond
! ((window-minibuffer-p)
! (error "Cannot switch buffers in minibuffer window"))
! ((eq (window-dedicated-p) t)
! (error "Cannot switch buffers in a dedicated window"))))
! (pop-to-buffer buffer-or-name
! '(same-window (reuse-window-dedicated . weak))
! norecord nil)))
(defun switch-to-buffer-same-frame (buffer-or-name &optional norecord)
"Switch to buffer BUFFER-OR-NAME in a window on the selected frame.
next prev parent reply other threads:[~2011-07-09 19:25 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-05 21:40 switch-to-buffer: for interactive use only Glenn Morris
2011-07-05 23:23 ` Juanma Barranquero
2011-07-05 23:32 ` Glenn Morris
2011-07-05 23:34 ` Juanma Barranquero
2011-07-05 23:41 ` Juanma Barranquero
2011-07-06 1:18 ` Stefan Monnier
2011-07-06 1:49 ` Glenn Morris
2011-07-06 2:27 ` Glenn Morris
2011-07-06 5:55 ` Andreas Röhler
2011-07-06 21:10 ` Chong Yidong
2011-07-07 9:19 ` Štěpán Němec
2011-07-07 19:52 ` Stefan Monnier
2011-07-07 20:50 ` Chong Yidong
2011-07-07 21:11 ` Stefan Monnier
2011-07-07 23:39 ` Chong Yidong
2011-07-08 0:09 ` Juanma Barranquero
2011-07-08 1:12 ` Chong Yidong
2011-07-08 6:44 ` martin rudalics
2011-07-08 6:44 ` martin rudalics
2011-07-08 6:43 ` martin rudalics
2011-07-08 12:57 ` Stefan Monnier
2011-07-08 14:03 ` martin rudalics
2011-07-08 15:46 ` Stefan Monnier
2011-07-08 16:45 ` martin rudalics
2011-07-08 18:46 ` Stefan Monnier
2011-07-08 20:12 ` Chong Yidong
2011-07-08 20:34 ` Juanma Barranquero
2011-07-08 20:50 ` Chong Yidong
2011-07-08 23:16 ` Juanma Barranquero
2011-07-09 2:35 ` Chong Yidong
2011-07-09 3:09 ` Stefan Monnier
2011-07-09 8:45 ` martin rudalics
2011-07-11 3:41 ` Stefan Monnier
2011-07-11 9:43 ` martin rudalics
2011-07-09 19:25 ` Chong Yidong [this message]
2011-07-10 9:00 ` martin rudalics
2011-07-10 13:09 ` Chong Yidong
2011-07-10 13:31 ` martin rudalics
2011-07-11 3:45 ` Stefan Monnier
2011-07-11 14:56 ` Chong Yidong
2011-07-12 4:25 ` Stefan Monnier
2011-07-12 8:36 ` martin rudalics
2011-07-13 15:42 ` Chong Yidong
2011-07-13 17:18 ` martin rudalics
2011-07-13 21:53 ` Chong Yidong
2011-07-09 8:45 ` martin rudalics
-- strict thread matches above, loose matches on Subject: below --
2011-07-13 22:13 grischka
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=871uxzxnme.fsf@stupidchicken.com \
--to=cyd@stupidchicken.com \
--cc=emacs-devel@gnu.org \
--cc=lekktu@gmail.com \
--cc=monnier@iro.umontreal.ca \
--cc=rudalics@gmx.at \
/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.