Subject: [PATCH] Fix display-buffer-override-next-command

From: "[email-masked]" <[email-masked]>
Date: Wed, 19 Jun 2024 12:20:19 -0300

When display-buffer-overriding-action's car is set to a function instead of
a list, display-buffer-override-next-command must ensure that the car is a
list before pushing a new element to it, otherwise the car will become a
itself a cons-cell and the clear-fun will trigger a wrong-type-argumen
error when trying to delq the action.

The error can be triggered by using some minor mode that
updates display-buffer-override-next-command (such as purpose-mode) and
then calling other-window-prefix.

The patch was created using the `emacs-29` branch.

----

In GNU Emacs 29.3.50 (build 8, x86_64-pc-linux-gnu, GTK+ Version
 3.24.41, cairo version 1.18.0) of 2024-05-27 built on thnkpd
System Description: Fedora Linux 39 (Workstation Edition)

Configured using:
 'configure --build x86_64-linux-gnu --prefix=/usr/local
 --sharedstatedir=/var/lib --localstatedir=/var/lib --enable-libsystemd
 --with-pop=yes --build x86_64-linux-gnu
 --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/29/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/29/site-lisp:/usr/share/emacs/site-lisp
 --with-sound=alsa --without-gconf --with-mailutils --with-cairo
 --with-x=yes --with-x-toolkit=gtk3 --with-pgtk
 --with-toolkit-scroll-bars --without-xwidgets --with-imagemagick
 --with-native-compilation --with-tree-sitter --with-xinput2'

-- 
Rodrigo Virote Kassick
------------------------------------------------------------
From 8fa11a451949be743d4bdedd5117571d912e2209 Mon Sep 17 00:00:00 2001
From: Rodrigo Kassick <[email-masked]>
Date: Wed, 19 Jun 2024 11:46:35 -0300
Subject: [PATCH] Fix display-buffer-override-next-command

* lisp/window.el (display-buffer-override-next-command):
display-buffer-overriding-action's car can be either a function or a
list of functions. When a function,
(push action (car display-buffer-overriding-action)) will create a
cons-cell (action . function)  instead of a list. In the
clear-fun callback, trying to
(delq action (car display-buffer-overriding-action)) causes an
wrong-type-argument error.
---
 lisp/window.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/window.el b/lisp/window.el
index 13fe1feba10..8db0584c910 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -9109,6 +9109,8 @@ display-buffer-override-next-command
     (when echofun
       (add-hook 'prefix-command-echo-keystrokes-functions echofun))
     (setq switch-to-buffer-obey-display-actions t)
+    (unless (listp (car display-buffer-overriding-action))
+        (setcar display-buffer-overriding-action (list (car display-buffer-overriding-action))))
     (push action (car display-buffer-overriding-action))
     exitfun))
 
-- 
2.45.1