all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Dmitry Gutov <dmitry@gutov.dev>, Juri Linkov <juri@linkov.net>
Cc: 74361@debbugs.gnu.org
Subject: bug#74361: [PATCH] New option xref-navigation-display-window-action
Date: Sat, 23 Nov 2024 10:35:43 +0100	[thread overview]
Message-ID: <78a96965-31c1-4688-b808-2de09d1832c4@gmx.at> (raw)
In-Reply-To: <e740a50f-ab57-4155-a011-053c3f203841@gmx.at>

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

 > In either case, 'display-buffer' would look whether an appropriate
 > window exists and use that window, maybe also ignoring certain aspects
 > (dedicatedness, minimum size) that would otherwise prevent its use.

Attached find how a 'category' list entry could be handled by
'display-buffer-use-some-window' where a 'some-window' entry would be
given precedence.  Tested with

(display-buffer
  (get-buffer-create "*foo*")
  '((display-buffer-use-some-window) (inhibit-same-window . t) (category . foo)))

(display-buffer
  (get-buffer-create "*bar*")
  '((display-buffer-use-some-window) (inhibit-same-window . t) (category . foo)))

martin

[-- Attachment #2: category.diff --]
[-- Type: text/x-patch, Size: 3246 bytes --]

diff --git a/lisp/window.el b/lisp/window.el
index b50770cbd7e..ba79c6e64af 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -2652,6 +2652,24 @@ get-buffer-window-list
 	(setq windows (cons window windows))))
     (nreverse windows)))
 
+(defun get-window-with-category (category &optional frames dedicated not-selected no-other)
+  "Return window matching CATEGORY on specified FRAMES.
+Return first window whose `category' parameter contains CATEGORY.
+The argument FRAMES has the same meaning as for `window-list'.
+
+A minibuffer window is never a candidate.  A dedicated window is never a
+candidate unless DEDICATED is non-nil, so if all windows are dedicated,
+the value is nil.  Optional argument NOT-SELECTED non-nil means never
+return the selected window.  Optional argument NO-OTHER non-nil means to
+never return a window for which `window-no-other-p' returns non-nil."
+  (catch 'found
+    (dolist (window (window-list-1 nil 'nomini frames))
+      (when (and (memq category (window-parameter window 'category))
+		 (or dedicated (not (window-dedicated-p window)))
+		 (or (not not-selected) (not (eq window (selected-window))))
+		 (or (not no-other) (window-no-other-p window)))
+	(throw 'found window)))))
+
 (defun minibuffer-window-active-p (window)
   "Return t if WINDOW is the currently active minibuffer window."
   (and (window-live-p window) (eq window (active-minibuffer-window))))
@@ -7665,6 +7725,13 @@ window--display-buffer
 	  (window-preserve-size window t (car preserve-size))
 	  (window-preserve-size window nil (cdr preserve-size)))))
 
+      (let ((category (cdr (assq 'category alist))))
+	(when category
+	  (let ((parameter (window-parameter window 'category)))
+	    (unless (memq category parameter)
+	      (set-window-parameter
+	       window 'category (cons category parameter))))))
+
       ;; Assign any window parameters specified.
       (let ((parameters (cdr (assq 'window-parameters alist))))
         (dolist (parameter parameters)
@@ -8921,12 +8988,17 @@ 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)))
+	 (category (cdr (assq 'category alist)))
+	 (some-window (assq 'some-window alist))
+	 (some-window-method (cdr some-window))
 	 (frame (or (window--frame-usable-p (selected-frame))
 		    (window--frame-usable-p (last-nonminibuffer-frame))))
 	 (window
 	  ;; Reuse an existing window.
-	  (or (cond
+	  (or (and category (not some-window)
+		   (get-window-with-category
+		    category 'visible  nil not-this-window))
+	      (cond
 	       ((memq some-window-method '(nil lru))
 		(display-buffer--lru-window
 		 ;; If ALIST specifies 'lru-frames' or 'window-min-width'
@@ -8937,6 +9009,9 @@ display-buffer-use-some-window
 		(get-mru-window nil nil t))
 	       ((functionp some-window-method)
 		(funcall some-window-method buffer alist)))
+	      (and category
+		   (get-window-with-category
+		    category 'visible  nil not-this-window))
 	      (let ((window (get-buffer-window buffer 'visible)))
 		(unless (and not-this-window
 			     (eq window (selected-window)))

  reply	other threads:[~2024-11-23  9:35 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-14 22:29 bug#74361: [PATCH] New option xref-navigation-display-window-action Dmitry Gutov
2024-11-15  0:50 ` Dmitry Gutov
2024-11-15  7:49 ` Juri Linkov
2024-11-15 19:05   ` Dmitry Gutov
2024-11-16 19:12     ` Juri Linkov
2024-11-18  1:28       ` Dmitry Gutov
2024-11-19 18:33         ` Juri Linkov
2024-11-19 19:43           ` Dmitry Gutov
2024-11-20  7:11             ` Juri Linkov
2024-11-20 19:12               ` Dmitry Gutov
2024-11-21  7:34                 ` Juri Linkov
2024-11-25  1:58                   ` Dmitry Gutov
2024-11-27  1:45                     ` Dmitry Gutov
2024-11-20  8:37             ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-20 17:31               ` Juri Linkov
2024-11-20 19:10                 ` Dmitry Gutov
2024-11-21  7:29                   ` Juri Linkov
2024-11-20 19:08               ` Dmitry Gutov
2024-11-22  9:22                 ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-23  9:35                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-11-23 18:45                     ` Juri Linkov
2024-11-23 19:16                       ` Juri Linkov
2024-11-24  8:59                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-24 17:40                         ` Juri Linkov
2024-11-25  9:18                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-25 17:49                             ` Juri Linkov
2024-11-26  9:15                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-27  1:52                                 ` Dmitry Gutov
2024-11-27  8:58                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-27 13:07                                     ` Dmitry Gutov
2024-11-28  9:27                                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-28 17:15                                         ` Dmitry Gutov
2024-11-28 18:32                                         ` Juri Linkov
2024-11-28 20:27                                           ` Dmitry Gutov
2024-12-04  7:35                                             ` Juri Linkov
2024-12-04  8:00                                               ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-04 17:14                                                 ` Juri Linkov
2024-12-05  9:23                                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-05 17:52                                                     ` Juri Linkov
2024-12-06  8:31                                                       ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-07 17:18                                                         ` Juri Linkov
2024-12-08 16:55                                                           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-12-05 18:08                                               ` Dmitry Gutov
2024-11-27  7:30                                 ` Juri Linkov
2024-11-27  9:00                                   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-20  8:36           ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-15 12:13 ` Eli Zaretskii
2024-11-15 17:20   ` martin rudalics via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-15 19:10   ` Dmitry Gutov
2024-11-16  8:43     ` Eli Zaretskii
2024-11-18  1:42       ` Dmitry Gutov
2024-11-18 12:25         ` Eli Zaretskii
2024-11-18 16:10           ` Dmitry Gutov
2024-11-18 17:03             ` Eli Zaretskii
2024-11-19  1:21               ` Dmitry Gutov
2024-11-19 15:33                 ` Eli Zaretskii
2024-11-19 19:51                   ` Dmitry Gutov
2024-11-20 12:54                     ` Eli Zaretskii
2024-11-21 10:37                   ` Eli Zaretskii
2024-11-21 18:01                     ` Juri Linkov
2024-11-21 19:16                       ` Eli Zaretskii
2024-11-21 19:39                         ` Juri Linkov
2024-11-21 19:56                           ` Eli Zaretskii
2024-11-22  7:29                             ` Juri Linkov
2024-11-22  8:20                               ` Eli Zaretskii
2024-11-23 18:25                                 ` Juri Linkov
2024-11-23 18:53                                   ` Eli Zaretskii
2024-11-23 19:14                                     ` Juri Linkov
2024-11-23 19:36                                       ` Eli Zaretskii
2024-11-24  7:34                                         ` Juri Linkov
2024-11-24  9:42                                           ` Eli Zaretskii
2024-11-25  7:28                                             ` Juri Linkov
2024-12-04  7:41                                               ` Juri Linkov
2024-11-19 18:36         ` Juri Linkov

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

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

  git send-email \
    --in-reply-to=78a96965-31c1-4688-b808-2de09d1832c4@gmx.at \
    --to=bug-gnu-emacs@gnu.org \
    --cc=74361@debbugs.gnu.org \
    --cc=dmitry@gutov.dev \
    --cc=juri@linkov.net \
    --cc=rudalics@gmx.at \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.