From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: switch-to-buffer: for interactive use only Date: Sat, 09 Jul 2011 15:25:29 -0400 Message-ID: <871uxzxnme.fsf@stupidchicken.com> References: <0aiprg76eu.fsf@fencepost.gnu.org> <87hb6zt8rg.fsf@stupidchicken.com> <8739ihlsry.fsf@stupidchicken.com> <4E16A728.5040002@gmx.at> <4E170E48.5040408@gmx.at> <4E173412.3090804@gmx.at> <87d3hkmt0k.fsf@stupidchicken.com> <87vcvcmr8y.fsf@stupidchicken.com> <87zkkokwp7.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1310239557 29669 80.91.229.12 (9 Jul 2011 19:25:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 9 Jul 2011 19:25:57 +0000 (UTC) Cc: Juanma Barranquero , emacs-devel@gnu.org, martin rudalics To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jul 09 21:25:53 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Qfd9z-0003jM-Ok for ged-emacs-devel@m.gmane.org; Sat, 09 Jul 2011 21:25:52 +0200 Original-Received: from localhost ([::1]:53042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qfd9y-0002cI-Tb for ged-emacs-devel@m.gmane.org; Sat, 09 Jul 2011 15:25:50 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:48575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qfd9l-0002cB-Dm for emacs-devel@gnu.org; Sat, 09 Jul 2011 15:25:38 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qfd9j-0005Fq-H8 for emacs-devel@gnu.org; Sat, 09 Jul 2011 15:25:37 -0400 Original-Received: from vm-emlprdomr-05.its.yale.edu ([130.132.50.146]:59271) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qfd9j-0005Fe-Dd for emacs-devel@gnu.org; Sat, 09 Jul 2011 15:25:35 -0400 Original-Received: from furball ([64.134.100.161]) (authenticated bits=0) by vm-emlprdomr-05.its.yale.edu (8.14.4/8.14.4) with ESMTP id p69JPTq4005472 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Sat, 9 Jul 2011 15:25:30 -0400 In-Reply-To: (Stefan Monnier's message of "Fri, 08 Jul 2011 23:09:38 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Scanned-By: MIMEDefang 2.71 on 130.132.50.146 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 130.132.50.146 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:141859 Archived-At: Stefan Monnier 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.