From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: martin rudalics Newsgroups: gmane.emacs.devel Subject: Re: master 18b680cfd1: Fix bug#52467 by adding a new custom variable 'display-comint-buffer-action' Date: Thu, 30 Dec 2021 11:25:31 +0100 Message-ID: References: <164073060906.21430.4993248796177370312@vcs2.savannah.gnu.org> <20211228223009.6D0BAC002EE@vcs2.savannah.gnu.org> <871r1v8nhf.fsf@gnus.org> <83ilv7jqm7.fsf@gnu.org> <6a9cd581-1630-4a95-62c4-419603561072@gmx.at> <3499cedf-b170-3045-873d-d45d2972ae13@gmx.at> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------06B8487454C694B65D855AD2" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33770"; mail-complaints-to="usenet@ciao.gmane.io" Cc: sdsg@amazon.com, emacs-devel@gnu.org To: Eli Zaretskii , Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Dec 30 11:26:48 2021 Return-path: Envelope-to: ged-emacs-devel@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 1n2sdy-0008eT-Pf for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Dec 2021 11:26:46 +0100 Original-Received: from localhost ([::1]:33902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n2sdx-0000UY-N9 for ged-emacs-devel@m.gmane-mx.org; Thu, 30 Dec 2021 05:26:45 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:55576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2sd2-00089n-Ua for emacs-devel@gnu.org; Thu, 30 Dec 2021 05:25:49 -0500 Original-Received: from mout.gmx.net ([212.227.15.15]:57293) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n2scu-0000Mw-2X; Thu, 30 Dec 2021 05:25:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1640859932; bh=N/5hp9TxD3vYF2h51Unc8YH0B+LnZxJ5pDks968xYfc=; h=X-UI-Sender-Class:Subject:From:To:Cc:References:Date:In-Reply-To; b=J6OxCB803nyBLadZV+Msq1PB3Vz6bkftUHl5sKf52E9iPB1km92pH9j5xKTrORfJp sUvFt/IcX/1jS9iLpmoSs4e26Jb2SkroAirhYMnO26PIm8aeuAYWAXuPGUg7df5IzZ rEQ7WouBj4+1aEAfusmCdPu4tWdYYlUSbRDnVods= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from [192.168.1.101] ([213.142.97.158]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MgvrL-1mUNkH2WHF-00hNQt; Thu, 30 Dec 2021 11:25:32 +0100 In-Reply-To: <3499cedf-b170-3045-873d-d45d2972ae13@gmx.at> Content-Language: en-US X-Provags-ID: V03:K1:xrOlIbcbKGXqy+yHniakheuVsfcpnu8ZOpSbdGuS49M5ARgzBhW n07P3J0QTP1a59ziLfcRYRQgDkhL/MNIeHUbruwipXiE7eDhXRtsINmT5Sn+E6ZmiP1crzR 3mAF0ZxAmmpBWogFMCXOZpTbvTZqGYz8ESzx8524N3hJV1g/iaKN4a/tnSiM2Tu7eyE8ZI5 sNE6yXdE/jvWagUyh2JMg== X-UI-Out-Filterresults: notjunk:1;V03:K0:RfJq1KBpnnA=:HKJLSXl86xTokI5dM9VDEY gBVz0xnOWWrP3cPZo/9K68X5Xl7r5LOj10wavZFGWmPt1BJW1NQqtX6ViBi9UY9oDxVeJp/Sj B2Hd7XBs9nKqE8syBXlwL98BOFKPpxN8zirQmJajtOqEgILuhCjii+QxYExZBnFgrcluy3mmh cqkMwVxVJR/RwTazdjxLQSeh0fmHuGEgMvyo8qn6JvjIYT46vMzRtov7qc/h6UQdE1/cPMjAF Zhu/MkRA4Lv9zxOhoiYOSddVXvYLbXshrjd1Qvt2rH3EgyhrbxFaXi6EkDwj2frWX6sFV79lY m2tzW1FhH+q1DT3vqV+cxFPJbOPp7DUwPBx/Nn/6vFW2SGb3HeCeCjt9eP+Sft57h5jkM3s1f GpGhDx8gRksRlfCaDKmJDX8H/UksdDC2UKe3Lr9AuKwG43Igg9lnxAZt1u3zXLIOZVfAFVTMO iaa0xjYT6Zj4cKmJZK2gtyBIHk09c9G2XRI/vtt7oVIZCHdjfEJcT6zna1DbXl5YYo8kqRm9U SwrTtbco/aLTW9Exi3hY7zashsVp3UZPufboXYTXyD5AzabVUFN2HpfpqFtr6g1oTUJqY3a6X J4K2wuuPSTNjaBneAuOv+p/sUea6Omqzt+NBu0zw++qvEbKS0vALTAVr7roRg8berzlhisJap 64i05MPXhf8t7GKm7tVqA36RoHFcproa0Hhulbr/efpnDmE/aZw1Fomat5s1DCr6wBk/YB1Zs 3uT6tCiINqaci2iKxBroTtbXlLgeYx8IkabeaozGDrgsWKRDwT6Yr9D1PpUEmeBWftk8C/Sx Received-SPF: pass client-ip=212.227.15.15; envelope-from=rudalics@gmx.at; helo=mout.gmx.net X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:283637 Archived-At: This is a multi-part message in MIME format. --------------06B8487454C694B65D855AD2 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit > ... we need a general new display > buffer action that preferably (1) reuses a window already showing the > buffer (2) uses the same window and only then (3) uses another window. > Maybe Juri has an idea. The attached diff should illustrate what I mean here. martin --------------06B8487454C694B65D855AD2 Content-Type: text/x-patch; name="display-buffer-reuse-or-same-window.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="display-buffer-reuse-or-same-window.diff" diff --git a/lisp/window.el b/lisp/window.el index edca4a2da5..d55123bbd2 100644 =2D-- a/lisp/window.el +++ b/lisp/window.el @@ -8119,6 +8119,7 @@ display-buffer--action-function-custom-type (const display-buffer-reuse-window) (const display-buffer-pop-up-window) (const display-buffer-same-window) + (const display-buffer-reuse-or-same-window) (const display-buffer-pop-up-frame) (const display-buffer-in-child-frame) (const display-buffer-below-selected) @@ -8248,6 +8249,16 @@ display-buffer--same-window-action Specifies to call `display-buffer-same-window'.") (put 'display-buffer--same-window-action 'risky-local-variable t) +(defvar display-buffer--reuse-or-same-window-action + '((display-buffer-reuse-window + display-buffer-same-window) + (inhibit-same-window . nil)) + "A `display-buffer' action for reusing a window or using the same one. +If a window showing the buffer exists already, reuse that window. +Otherwise, use preferably the selected window. Specifies to call +`display-buffer-reuse-or-same-window'.") +(put 'display-buffer--reuse-or-same-window-action 'risky-local-variable t= ) + (defvar display-buffer--other-frame-action '((display-buffer-reuse-window display-buffer-pop-up-frame) @@ -8266,7 +8277,9 @@ display-buffer `display-buffer-same-window' -- Use the selected window. `display-buffer-reuse-window' -- Use a window already showing the buffer. - `display-buffer-in-previous-window' -- Use a window that did +`display-buffer-reuse-or-same-window' -- Either reuse a window or + use the selected one. +`display-buffer-in-previous-window' -- Use a window that did show the buffer before. `display-buffer-use-some-window' -- Use some existing window. `display-buffer-use-least-recent-window' -- Try to avoid re-using @@ -8505,6 +8518,20 @@ display-buffer-same-window (window-dedicated-p)) (window--display-buffer buffer (selected-window) 'reuse alist))) +(defun display-buffer-reuse-or-same-window (buffer alist) + "Display BUFFER reusing a window showing it or the selected one. +ALIST is an association list of action symbols and values. See +Info node `(elisp) Buffer Display Action Alists' for details of +such alists. + +First try to use a window already showing BUFFER. If no such +window exists, do like `display-buffer-same-window'." + (or (display-buffer-reuse-window buffer alist) + (unless (or (cdr (assq 'inhibit-same-window alist)) + (window-minibuffer-p) + (window-dedicated-p)) + (window--display-buffer buffer (selected-window) 'reuse alist)))) + (defun display-buffer--maybe-same-window (buffer alist) "Conditionally display BUFFER in the selected window. ALIST is an association list of action symbols and values. See @@ -9339,6 +9366,13 @@ pop-to-buffer-same-window another window." (pop-to-buffer buffer display-buffer--same-window-action norecord)) +(defun pop-to-buffer-reuse-or-same-window (buffer &optional norecord) + "Select specified BUFFER in a window showing it or the same one. +This is like `pop-to-buffer-same-window', but tries first to +reuse a window already showing BUFFER and only if no such window +exists behaves like `pop-to-buffer-same-window'." + (pop-to-buffer buffer display-buffer--reuse-or-same-window-action norec= ord)) + (defun read-buffer-to-switch (prompt) "Read the name of a buffer to switch to, prompting with PROMPT. Return the name of the buffer as a string. --------------06B8487454C694B65D855AD2--