unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: Eli Zaretskii <eliz@gnu.org>, Lars Ingebrigtsen <larsi@gnus.org>
Cc: sdsg@amazon.com, emacs-devel@gnu.org
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	[thread overview]
Message-ID: <a1f69a2c-d70b-98b5-fa10-989c6cbe9c23@gmx.at> (raw)
In-Reply-To: <3499cedf-b170-3045-873d-d45d2972ae13@gmx.at>

[-- Attachment #1: Type: text/plain, Size: 274 bytes --]

 > ... 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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: display-buffer-reuse-or-same-window.diff --]
[-- Type: text/x-patch; name="display-buffer-reuse-or-same-window.diff", Size: 3557 bytes --]

diff --git a/lisp/window.el b/lisp/window.el
index edca4a2da5..d55123bbd2 100644
--- 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 norecord))
+
 (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.

  reply	other threads:[~2021-12-30 10:25 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <164073060906.21430.4993248796177370312@vcs2.savannah.gnu.org>
     [not found] ` <20211228223009.6D0BAC002EE@vcs2.savannah.gnu.org>
2021-12-28 22:37   ` master 18b680cfd1: Fix bug#52467 by adding a new custom variable 'display-comint-buffer-action' Dmitry Gutov
2021-12-28 22:59     ` jakanakaevangeli
2021-12-29  8:17     ` Juri Linkov
2021-12-29 15:00   ` Lars Ingebrigtsen
2021-12-29 16:57     ` Eli Zaretskii
2021-12-30  8:34       ` martin rudalics
2021-12-30  8:47         ` martin rudalics
2021-12-30 10:25           ` martin rudalics [this message]
2021-12-30 14:40             ` Stefan Monnier
2021-12-30 17:12               ` martin rudalics
2021-12-30 17:29                 ` Lars Ingebrigtsen
2021-12-30 18:30                   ` martin rudalics
2021-12-31 16:29                     ` Lars Ingebrigtsen
2021-12-31 18:41                       ` martin rudalics
2021-12-30 16:04             ` Juri Linkov
2021-12-30 17:14               ` martin rudalics
2021-12-31 16:47                 ` Sam Steingold
2021-12-31 18:42                   ` martin rudalics
2021-12-31 16:38             ` Sam Steingold
2021-12-31 18:42               ` martin rudalics
2021-12-31 18:55                 ` Sam Steingold
2021-12-31 19:40                   ` martin rudalics
2022-01-03 17:22                     ` Sam Steingold
2021-12-30 17:24           ` Dmitry Gutov
2021-12-30 18:30             ` martin rudalics
2021-12-31 16:28               ` Lars Ingebrigtsen
2021-12-31 18:41                 ` martin rudalics
2022-01-02 16:21                   ` Madhu
2022-01-02 17:09                     ` martin rudalics
2022-01-02 17:43                   ` Juri Linkov
2022-01-02 18:40                     ` martin rudalics
2022-01-02 20:52                       ` Dmitry Gutov
2022-01-03  7:45                         ` Juri Linkov
2022-01-03 18:21                           ` martin rudalics
2022-01-03 18:38                             ` Stefan Monnier
2022-01-04 10:25                               ` martin rudalics
2022-01-04 15:48                                 ` Stefan Monnier
2022-01-03 21:07                             ` Juri Linkov
2022-01-04 10:26                               ` martin rudalics
2022-01-06 15:30                                 ` martin rudalics
2022-01-06 19:52                                   ` Juri Linkov
2022-01-07 10:36                                     ` martin rudalics
2022-01-07 18:49                                       ` Sam Steingold
2022-01-07 19:03                                         ` Eli Zaretskii
2022-01-07 19:16                                           ` Sam Steingold
2022-01-11 17:20                                       ` Juri Linkov
2022-01-11 18:02                                         ` martin rudalics
2022-01-11 18:15                                           ` Juri Linkov
2022-01-12  8:43                                             ` martin rudalics
2022-01-03  7:51                       ` Juri Linkov
2021-12-29 17:29     ` Sam Steingold
2021-12-29 16:43   ` Glenn Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a1f69a2c-d70b-98b5-fa10-989c6cbe9c23@gmx.at \
    --to=rudalics@gmx.at \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    --cc=sdsg@amazon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).