From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org> Newsgroups: gmane.emacs.bugs Subject: bug#67249: 30.0.50; `same-frame` equivalent for `display-buffer-alist` Date: Thu, 23 Nov 2023 21:52:18 -0500 Message-ID: <jwvlean7ulh.fsf-monnier+emacs@gnu.org> References: <jwv34x4m50o.fsf@iro.umontreal.ca> <159cd3c2-a0c4-63e2-ebb2-ce0f5f8c343e@gmx.at> <jwv1qcmfm22.fsf-monnier+emacs@gnu.org> <cbc6a073-2718-7809-c85e-cf338341c712@gmx.at> <jwvv89xesho.fsf-monnier+emacs@gnu.org> <69e6899b-9e93-9a97-a8bc-4ce9a9f0ae4c@gmx.at> <jwvwmucd0mq.fsf-monnier+emacs@gnu.org> <69387717-1eaa-6019-0000-4c95c61e1bc3@gmx.at> <jwvwmubrkx7.fsf-monnier+emacs@gnu.org> <1f026837-af56-435f-9d4e-048a18af07eb@gmx.at> <jwv8r6pssbu.fsf-monnier+emacs@gnu.org> <a3b664a2-bb53-2f84-edb1-ab4d9d3567bd@gmx.at> Reply-To: Stefan Monnier <monnier@iro.umontreal.ca> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3934"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 67249@debbugs.gnu.org To: martin rudalics <rudalics@gmx.at> Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 24 03:53:26 2023 Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org> Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org>) id 1r6MJp-0000qC-59 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 Nov 2023 03:53:25 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from <bug-gnu-emacs-bounces@gnu.org>) id 1r6MJP-0005uX-LJ; Thu, 23 Nov 2023 21:52:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1r6MJO-0005uO-Ic for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2023 21:52:58 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1r6MJO-0005Q5-AE for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2023 21:52:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1r6MJR-00011r-QD for bug-gnu-emacs@gnu.org; Thu, 23 Nov 2023 21:53:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier <monnier@iro.umontreal.ca> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org> Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Nov 2023 02:53:01 +0000 Resent-Message-ID: <handler.67249.B67249.17007943693936@debbugs.gnu.org> Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 67249 X-GNU-PR-Package: emacs Original-Received: via spool by 67249-submit@debbugs.gnu.org id=B67249.17007943693936 (code B ref 67249); Fri, 24 Nov 2023 02:53:01 +0000 Original-Received: (at 67249) by debbugs.gnu.org; 24 Nov 2023 02:52:49 +0000 Original-Received: from localhost ([127.0.0.1]:35382 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>) id 1r6MJE-00011P-Lx for submit@debbugs.gnu.org; Thu, 23 Nov 2023 21:52:49 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:22075) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <monnier@iro.umontreal.ca>) id 1r6MJ4-000113-JG for 67249@debbugs.gnu.org; Thu, 23 Nov 2023 21:52:47 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 68CBD80781; Thu, 23 Nov 2023 21:52:28 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1700794347; bh=dW6DjLDGgRikutZ4onvS1hhltlRJoDVkqaWIQoJq3uY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=X3YRpXwpahTjh/2nqTL3pKGPXM0L8WTQetdASmJRs103+CkXIYSwwcjik4L3oUK2h MTxQaNP6t7gHTbrUTOxho16F0tesA4MA3NR/v0rzanup3DcxUapBkj43kPs+6M1stt q6iHUR3zDb63IZ+OoDHhiU1e3H23ZXdLGcvwGPLt80SXGVIf+Z4XH/YgmOa90A+NLn 1oewfRWrdJRCDodGF/GqMKhAtS9Fc6mKrLGcnNaPHHUIEAWvG62qFhzVS8dI7P3I9p vOdHJqW1ivER49+2VzDrgRpPISaJ2wp831zPk3xqJ6CHeDB7LxhF4BPHKE3myR5R1F 8ZCGXpqDjiU6w== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id EF76280091; Thu, 23 Nov 2023 21:52:26 -0500 (EST) Original-Received: from pastel (unknown [45.72.227.120]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C638E1202FF; Thu, 23 Nov 2023 21:52:26 -0500 (EST) In-Reply-To: <a3b664a2-bb53-2f84-edb1-ab4d9d3567bd@gmx.at> (martin rudalics's message of "Thu, 23 Nov 2023 10:59:55 +0100") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe> List-Archive: <https://lists.gnu.org/archive/html/bug-gnu-emacs> List-Post: <mailto:bug-gnu-emacs@gnu.org> List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe> Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:274839 Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/274839> --=-=-= Content-Type: text/plain >>> If OT1H 'same-frame' is ignored when the selected frame is a >>> minibuffer-only frame (so a new frame gets popped up instead) and OTOH >>> the remaining action functions do use the last non-minibuffer frame in >>> such case, then the behavior of 'display-buffer' is inconsistent in my >>> regard. >> Ah, yes, I see. >> IIUC, the "inhibit-new-frame" semantics seems less susceptible to this >> problem then the "same-frame", no? > When I type M-x to invoke a custom function for displaying a buffer, I'd > probably want 'inhibit-new-frame' to do what it advertises regardless of > whether I'm in a stand-alone minibuffer frame or in a normal minibuffer > window. Indeed, but the difference between "same frame" and "inhibit new frame" is that the meaning of "same frame" depends on the `selected-frame` whereas "inhibit new frame" doesn't, so I think we're OK. Here's a first candidate patch. I introduced a new function `display-buffer--pop-up-frame` so as to ignore `inhibit-new-frame` as a last resort. I also modified `display-buffer--other-frame-action` to use `display-buffer--pop-up-frame`, because it seems this is used only(?) in response to an explicit user request where the user does expect a new frame (like `C-x 5 b`) and so it seems to make sense to override even an `inhibit-new-frame` coming from `display-buffer-alist`. Stefan PS: Am I the only one who finds it confusing how some functions named `display-buffer-<foo>` are meant to be used from the ACTIONs (i.e. from within `display-buffer`) while others are implemented on top of `display-buffer` (and thus should not be used within ACTIONS)? Could we try and find a clear naming convention to distinguish the two, or am I even more confused than I thought and several of those functions can be used either way? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=inhibit-new-frame.patch diff --git a/lisp/window.el b/lisp/window.el index 0c5ccf167dc..34027c58cae 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -6860,6 +6860,7 @@ special-display-popup-frame If ARGS is a list whose car is a symbol, use (car ARGS) as a function to do the work. Pass it BUFFER as first argument, and pass the elements of (cdr ARGS) as the remaining arguments." + (declare (obsolete display-buffer-pop-up-frame "30.1")) (if (and args (symbolp (car args))) (apply (car args) buffer (cdr args)) (let ((window (get-buffer-window buffer 0))) @@ -7627,7 +7628,7 @@ display-buffer-fallback-action display-buffer-in-previous-window display-buffer-use-some-window ;; If all else fails, pop up a new frame. - display-buffer-pop-up-frame)) + display-buffer--pop-up-frame)) "Default fallback action for `display-buffer'. This is the action used by `display-buffer' if no other actions have been specified, for example, by the user options @@ -7657,7 +7658,7 @@ display-buffer--same-window-action (defvar display-buffer--other-frame-action '((display-buffer-reuse-window - display-buffer-pop-up-frame) + display-buffer--pop-up-frame) (reusable-frames . 0) (inhibit-same-window . t)) "A `display-buffer' action for displaying in another frame. @@ -7735,6 +7736,8 @@ display-buffer Note that a window manager may still raise a new frame and give it focus, effectively overriding the value specified here. + `inhibit-new-frame' -- A non-nil value forces the use of an + existing frame to display the buffer. `reusable-frames' -- The value specifies the set of frames to search for a window that already displays the buffer. Possible values are nil (the selected frame), t (any live @@ -7828,12 +7831,12 @@ display-buffer user-action special-action action extra-action display-buffer-base-action display-buffer-fallback-action)) - (functions (apply 'append + (functions (apply #'append (mapcar (lambda (x) (setq x (car x)) (if (functionp x) (list x) x)) actions))) - (alist (apply 'append (mapcar 'cdr actions))) + (alist (apply #'append (mapcar #'cdr actions))) window) (unless (buffer-live-p buffer) (error "Invalid buffer")) @@ -8090,10 +8093,16 @@ display-buffer--special-action (funcall special-display-function buffer (if (listp pars) pars))))))))) +(defun display-buffer--pop-up-frame (buffer alist) + "Like `display-buffer--pop-up-frame' but ignores `inhibit-new-frame'. +Used only in exceptional cases." + (display-buffer-pop-up-frame buffer `((inhibit-new-frame . nil) ,@alist))) + (defun display-buffer-pop-up-frame (buffer alist) "Display BUFFER in a new frame. This works by calling `pop-up-frame-function'. If successful, return the window used; otherwise return nil. +Do nothing if ALIST's `inhibit-new-frame' is non-nil. ALIST is an association list of action symbols and values. See Info node `(elisp) Buffer Display Action Alists' for details of @@ -8107,15 +8116,16 @@ display-buffer-pop-up-frame node `(elisp) Buffer Display Action Functions'. It should be called only by `display-buffer' or a function directly or indirectly called by the latter." - (let* ((params (cdr (assq 'pop-up-frame-parameters alist))) - (pop-up-frame-alist (append params pop-up-frame-alist)) - (fun pop-up-frame-function) + (let* ((fun pop-up-frame-function) frame window) (when (and fun + (not (alist-get 'inhibit-new-frame alist)) ;; Make BUFFER current so `make-frame' will use it as the ;; new frame's buffer (Bug#15133). (with-current-buffer buffer - (setq frame (funcall fun))) + (let* ((params (cdr (assq 'pop-up-frame-parameters alist))) + (pop-up-frame-alist (append params pop-up-frame-alist))) + (setq frame (funcall fun)))) (setq window (frame-selected-window frame))) (prog1 (window--display-buffer buffer window 'frame alist) (unless (cdr (assq 'inhibit-switch-frame alist)) --=-=-=--