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: display-buffer-alist simplifications Date: Wed, 31 Aug 2011 22:04:57 -0400 Message-ID: <877h5tow52.fsf@stupidchicken.com> References: <87mxgem09k.fsf@stupidchicken.com> <4E3FA812.3080009@gmx.at> <87zkjkb572.fsf@mail.jurta.org> <4E3FD5ED.5000206@gmx.at> <4E412E2D.90908@gmx.at> <4E422ECA.2020207@gmx.at> <4E43A253.9040404@gmx.at> <4E59F6D1.5060800@gmx.at> <4E5BE2B9.9030307@gmx.at> <87zkiqicdo.fsf@stupidchicken.com> <87hb4ythby.fsf@stupidchicken.com> <4E5DFFE1.6080200@gmx.at> <877h5t377e.fsf@stupidchicken.com> <4E5ED10D.7010309@gmx.at> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1314842718 31493 80.91.229.12 (1 Sep 2011 02:05:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 1 Sep 2011 02:05:18 +0000 (UTC) Cc: 'Juri Linkov' , 'Stefan Monnier' , Drew Adams , emacs-devel@gnu.org To: martin rudalics Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Sep 01 04:05:13 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 1QyweV-0003ZR-K2 for ged-emacs-devel@m.gmane.org; Thu, 01 Sep 2011 04:05:11 +0200 Original-Received: from localhost ([::1]:43761 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QyweP-000614-OT for ged-emacs-devel@m.gmane.org; Wed, 31 Aug 2011 22:05:05 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:39306) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QyweN-00060w-22 for emacs-devel@gnu.org; Wed, 31 Aug 2011 22:05:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QyweL-00016a-Pb for emacs-devel@gnu.org; Wed, 31 Aug 2011 22:05:03 -0400 Original-Received: from vm-emlprdomr-03.its.yale.edu ([130.132.50.144]:47747) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QyweL-00016J-Nb for emacs-devel@gnu.org; Wed, 31 Aug 2011 22:05:01 -0400 Original-Received: from furball (dhcp-128-36-14-41.central.yale.edu [128.36.14.41]) (authenticated bits=0) by vm-emlprdomr-03.its.yale.edu (8.14.4/8.14.4) with ESMTP id p8124vK9001982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Wed, 31 Aug 2011 22:04:58 -0400 In-Reply-To: <4E5ED10D.7010309@gmx.at> (martin rudalics's message of "Thu, 01 Sep 2011 02:25:49 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Scanned-By: MIMEDefang 2.71 on 130.132.50.144 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 130.132.50.144 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:143674 Archived-At: martin rudalics writes: > I don't know. If we do so, then the action list should be probably also > made an argument of the switch-to-* family of functions which, IIUC, > according to Stefan should remain callable from programs. > > I wouldn't have included the pop-to-* functions in the first place but > there are already too many callers around. So please rewrite them the > way you consider most suitable. OK, I understand better now. The pop-to-* function should NOT be "action functions" (in the sense of display-buffer-alist), because they select the window in addition to displaying it. But, they should make use of action functions. TRT is to define two functions, `display-buffer-same-window' and `display-buffer-other-window', which serve as action functions, which handle the window selection/display part. Then the implementation of the pop-to-* functions is very simple: it consists choosing a particular order for two action functions, or omitting one of them; and then selecting the window. This involves a simple re-factoring of your code: (defun display-buffer-same-window (buffer alist) "Display BUFFER in the selected window, and return the window. If BUFFER cannot be displayed in the selected window (usually because it is dedicated to another buffer), return nil." (setq buffer (window-normalize-buffer-to-display buffer)) (let ((norecord (cadr (assq 'norecord alist)))) (cond ((eq buffer (window-buffer)) (selected-window)) ((not (or (window-minibuffer-p) (window-dedicated-p))) (set-window-buffer nil buffer) (selected-window))))) (defun display-buffer-other-window (buffer alist) "Display BUFFER in another window, and return BUFFER. If BUFFER cannot be displayed in another window, just return nil." (display-buffer-default buffer t)) (defun pop-to-buffer (buffer-or-name &optional other-window norecord) "..." (interactive "BPop to buffer:\nP") (if other-window (let ((same-window-buffer-names nil) (same-window-regexps nil)) (pop-to-buffer-1 buffer-or-name '((display-buffer-other-window)) norecord)) (pop-to-buffer-1 buffer-or-name '((display-buffer-other-window display-buffer-same-window)) norecord))) (defun pop-to-buffer-same-window (&optional buffer-or-name norecord) "..." (interactive "BPop to buffer in selected window:\nP") (pop-to-buffer-1 buffer-or-name '((display-buffer-same-window display-buffer-other-window)) norecord)) (defun pop-to-buffer-other-window (&optional buffer-or-name norecord) "..." (interactive "BPop to buffer in another window:\nP") (let ((pop-up-windows t) (same-window-buffer-names nil) (same-window-regexps nil)) (pop-to-buffer-1 buffer-or-name '((display-buffer-other-window display-buffer-same-window)) norecord))) (defun pop-to-buffer-other-frame (&optional buffer-or-name norecord) "..." (interactive "BPop to buffer on another frame:\nP") (let ((pop-up-frames t) (same-window-buffer-names nil) (same-window-regexps nil)) (pop-to-buffer-1 buffer-or-name '((display-buffer-other-window display-buffer-same-window)) norecord))) (defun pop-to-buffer-1 (buffer-or-name action norecord) (let ((buffer (window-normalize-buffer-to-display ;; BUFFER-OR-NAME nil means another buffer. (or buffer-or-name (other-buffer (current-buffer)))))) (set-buffer buffer) (let* ((old-window (selected-window)) (old-frame (selected-frame)) (window (display-buffer buffer action)) (frame (window-frame window))) (if (eq frame old-frame) ;; Make sure new window gets selected (Bug#8615), (Bug#6954). (select-window window norecord) ;; `display-buffer' has chosen another frame, make sure it gets ;; input focus and is risen. (select-frame-set-input-focus frame norecord)) buffer)))