From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#70949: display-buffer-choose-some-window Date: Mon, 20 May 2024 09:15:11 +0300 Organization: LINKOV.NET Message-ID: <86ed9xvz3o.fsf@mail.linkov.net> References: <86jzjwqqmd.fsf@mail.linkov.net> <8d1947c7-a4d1-4920-8638-f8ae17acfe65@gmx.at> <86r0e32fnj.fsf@mail.linkov.net> <867cft0xt2.fsf@mail.linkov.net> 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="29490"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu) Cc: 70949@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 20 08:20:21 2024 Return-path: 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 ) id 1s8wNg-0007Xl-JA for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 20 May 2024 08:20:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s8wNX-0004XS-G9; Mon, 20 May 2024 02:20:11 -0400 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 ) id 1s8wLP-0003o4-6y for bug-gnu-emacs@gnu.org; Mon, 20 May 2024 02:18:00 -0400 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 ) id 1s8wLN-0002mZ-VZ for bug-gnu-emacs@gnu.org; Mon, 20 May 2024 02:17:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s8wLS-0004y1-6N for bug-gnu-emacs@gnu.org; Mon, 20 May 2024 02:18:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 20 May 2024 06:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70949 X-GNU-PR-Package: emacs Original-Received: via spool by 70949-submit@debbugs.gnu.org id=B70949.171618586919087 (code B ref 70949); Mon, 20 May 2024 06:18:02 +0000 Original-Received: (at 70949) by debbugs.gnu.org; 20 May 2024 06:17:49 +0000 Original-Received: from localhost ([127.0.0.1]:40317 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8wLE-0004xn-Lj for submit@debbugs.gnu.org; Mon, 20 May 2024 02:17:49 -0400 Original-Received: from relay1-d.mail.gandi.net ([217.70.183.193]:44513) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s8wL8-0004xh-NJ for 70949@debbugs.gnu.org; Mon, 20 May 2024 02:17:47 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id 3BB9D240005; Mon, 20 May 2024 06:17:10 +0000 (UTC) In-Reply-To: (martin rudalics's message of "Sat, 18 May 2024 11:21:52 +0200") X-GND-Sasl: juri@linkov.net 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" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-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:285462 Archived-At: --=-=-= Content-Type: text/plain >> I already considered adding an alist entry, but the problem is that >> it's not clear where users would put it to cover display of all buffers. >> But I could reconsider such solution, if you will suggest a suitable place >> for users to add such an alist like (some-window . mru) for all buffers. > > Why would that be a problem? Any "(some-window . mru)" entry would > exclusively affect the execution of 'display-buffer-use-some-window'. > So what would be wrong with > > (customize-set-variable > 'display-buffer-alist > (cons '(".*" nil (some-window . mru)) display-buffer-alist)) Or maybe users could customize base-action: (setq display-buffer-base-action '(nil . ((some-window . mru)))) Ok, here is a new patch with a new alist entry: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=some-window-method.patch diff --git a/lisp/window.el b/lisp/window.el index 8feeba0d83e..5f9dec1dc25 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -7851,7 +7856,16 @@ display-buffer and `preserve-size' are applied. The function is supposed to fill the window body with some contents that might depend on dimensions of the displayed window. - `post-command-select-window' -- A non-nil value means that after the + `some-window' -- This entry defines which window + `display-buffer-use-some-window' should choose. The possible choices + are `lru' or nil (the default) to select the least recently used window, + and `mru' to select the most recently used window . When a function, it + takes two arguments: a buffer and an alist, and should return the window + where to display the buffer. When the value is `lru', it avoids + selecting windows that are not full-width and windows on another frame. + When the value is `mru', it avoids selecting an already selected window + and windows on another frame. + `post-command-select-window' -- A non-nil value means that after the current command is executed and the hook `post-command-hook' is called, the window displayed by this function will be selected. A nil value means that if functions like `pop-to-buffer' selected another window, @@ -8739,15 +8753,22 @@ display-buffer-use-some-window called only by `display-buffer' or a function directly or indirectly called by the latter." (let* ((not-this-window (cdr (assq 'inhibit-same-window alist))) + (some-window-method (cdr (assq 'some-window alist))) (frame (or (window--frame-usable-p (selected-frame)) (window--frame-usable-p (last-nonminibuffer-frame)))) (window ;; Reuse an existing window. - (or (display-buffer--lru-window - ;; If ALIST specifies 'lru-frames' or 'window-min-width' - ;; let them prevail. - (append alist `((lru-frames . ,frame) - (window-min-width . full-width)))) + (or (cond + ((memq some-window-method '(nil lru)) + (display-buffer--lru-window + ;; If ALIST specifies 'lru-frames' or 'window-min-width' + ;; let them prevail. + (append alist `((lru-frames . ,frame) + (window-min-width . full-width))))) + ((eq some-window-method 'mru) + (get-mru-window nil nil t)) + ((functionp some-window-method) + (funcall some-window-method buffer alist))) (let ((window (get-buffer-window buffer 'visible))) (unless (and not-this-window (eq window (selected-window))) --=-=-=--