Subject: bug#76216: closed (Re: bug#76216: 29.4; display-buffer-reuse-mode-window does not respect dedicated flag)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 01 Mar 2025 12:03:02 +0000

Your bug report

#76216: 29.4; display-buffer-reuse-mode-window does not respect dedicated flag

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
76216: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=76216
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#76216: 29.4; display-buffer-reuse-mode-window does not respect dedicated flag
From: Eli Zaretskii <[email-masked]>
To: martin rudalics <[email-masked]>
Cc: [email-masked], [email-masked], [email-masked], [email-masked]
Date: Sat, 01 Mar 2025 14:02:46 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Date: Wed, 12 Feb 2025 16:37:05 +0100
> Cc: [email-masked], Nicolas Richard <[email-masked]>,
>  [email-masked]
> From: martin rudalics <[email-masked]>
> 
>  >> Hey, all.  Per the subject line, I noticed that this display action
>  >> function isn't respecting when I mark a window dedicated to its buffer.
>  >>
>  >> Here's a minimal example you can step through in the scratch buffer:
>  >>
>  >> ```
>  >> (setq *w* (split-window-horizontally)
>  >>        *one* (get-buffer-create "one")
>  >>        *two* (get-buffer-create "two"))
>  >>
>  >> (display-buffer-use-some-window *one* '((inhibit-same-window . t)))
>  >> ;;; should see "one" appear in the *w* window
>  >>
>  >> (set-window-dedicated-p *w* t)
>  >> (display-buffer-use-some-window *two* '((inhibit-same-window . t)))
>  >> ;;; should not see any changes, the function returns nil
>  >> (display-buffer-reuse-mode-window *two* '((inhibit-same-window . t)))
>  >> ;;; bug -- should see "two" appear in the *w* window
>  >> ```
>  >>
>  >> I think this is a bug in -reuse-mode-window, and so I've attached a
>  >> patch that would fix the issue.  Though maybe I'm wrong?  Is
>  >> this intended behavior?
>  >
>  > Adding Martin to the discussion.
> 
> I think both approaches can be considered valid but would favor Trevor's
> variant.  In either case we should document the resulting behavior.
> 
> Adding both addresses of Nicolas Richard, maybe he still is somewhere.

Thanks, I've now installed Trevor's change on the master branch, and
I'm therefore closing this bug.

Subject: 29.4; display-buffer-reuse-mode-window does not respect dedicated flag
From: Trevor Murphy <[email-masked]>
To: [email-masked]
Date: Tue, 11 Feb 2025 17:52:30 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Hey, all.  Per the subject line, I noticed that this display action
function isn't respecting when I mark a window dedicated to its buffer.

Here's a minimal example you can step through in the scratch buffer:

```
(setq *w* (split-window-horizontally)
      *one* (get-buffer-create "one")
      *two* (get-buffer-create "two"))

(display-buffer-use-some-window *one* '((inhibit-same-window . t)))
;;; should see "one" appear in the *w* window

(set-window-dedicated-p *w* t)
(display-buffer-use-some-window *two* '((inhibit-same-window . t)))
;;; should not see any changes, the function returns nil
(display-buffer-reuse-mode-window *two* '((inhibit-same-window . t)))
;;; bug -- should see "two" appear in the *w* window
```

I think this is a bug in -reuse-mode-window, and so I've attached a
patch that would fix the issue.  Though maybe I'm wrong?  Is
this intended behavior?

In GNU Emacs 29.4 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.48,
cairo version 1.18.2)
Repository revision: 324f7b692ab0768891a26fe1c1431f4b555018be
Repository branch: main
System Description: Arch Linux

Configured using:
 'configure --with-pgtk --with-native-compilation=aot --sysconfdir=/etc
 --prefix=/usr --libexecdir=/usr/lib --with-tree-sitter
 --localstatedir=/var --with-cairo --disable-build-details
 --with-harfbuzz --with-libsystemd --with-modules 'CFLAGS=-march=x86-64
 -mtune=generic -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3
 -Wformat -Werror=format-security -fstack-clash-protection
 -fcf-protection -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -g
 -ffile-prefix-map=/home/trevor/pkgbuilds/abs/emacs/src=/usr/src/debug/emacs
 -flto=auto' 'LDFLAGS=-Wl,-O1 -Wl,--sort-common -Wl,--as-needed
 -Wl,-z,relro -Wl,-z,now -Wl,-z,pack-relative-relocs -flto=auto'
 'CXXFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security
 -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer
 -mno-omit-leaf-frame-pointer -Wp,-D_GLIBCXX_ASSERTIONS -g
 -ffile-prefix-map=/home/trevor/pkgbuilds/abs/emacs/src=/usr/src/debug/emacs
 -flto=auto''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER PGTK PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs
comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv cl-extra
help-mode bytecomp byte-compile cl-lib sendmail rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mail-utils rmc iso-transl tooltip cconv
eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/pgtk-win pgtk-win term/common-win pgtk-dnd
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq
simple cl-generic indonesian philippine cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button
loaddefs theme-loaddefs faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads dbusbind
inotify dynamic-setting system-font-setting font-render-setting cairo
gtk pgtk lcms2 multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 76993 6931)
 (symbols 48 7111 0)
 (strings 32 19553 2302)
 (string-bytes 1 592363)
 (vectors 16 15757)
 (vector-slots 8 327500 14961)
 (floats 8 37 46)
 (intervals 56 267 0)
 (buffers 984 11))
From ba34ccbb8b4a9f2cfb57572ebd124eee98e1a654 Mon Sep 17 00:00:00 2001
From: Trevor Murphy <[email-masked]>
Date: Tue, 11 Feb 2025 17:26:55 -0800
Subject: [PATCH] Ignore dedicated windows in
 'display-buffer-reuse-mode-window'.

Unless the dedicated window is already displaying the
buffer-to-be-displayed.  In that case the window may be reused,
according to the setting of inhibit-same-window.

* lisp/window.el (display-buffer-reuse-mode-window): Check
window-dedicated-p before pushing the candidate window onto the stack.
---
 lisp/window.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/window.el b/lisp/window.el
index 13fe1feba10..018bb35f943 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7984,6 +7984,8 @@ display-buffer-reuse-mode-window
                        ((apply #'derived-mode-p allowed-modes)
                         'derived)))))
           (when (and mode?
+                     (or (not (window-dedicated-p window))
+                         (eq buffer (window-buffer window)))
                      (not (and inhibit-same-window-p
                                (eq window curwin))))
             (push window (if (eq curframe (window-frame window))
-- 
2.48.1