Subject: Re: bug#76593: 31.0.50; mouse-buffer-menu shows two "Shell" submenus with enough *Async Shell Command* and shell-mode buffers

From: Visuwesh <[email-masked]>
Date: Thu, 27 Feb 2025 15:34:36 +0530

[புதன் பிப்ரவரி 26, 2025] Visuwesh wrote:

> mouse-buffer-menu ends up showing two "Shell" submenus when there are
> enough *Async Shell Command* (major-mode=shell-command-mode) and *shell*
> (major-mode=shell-mode) buffers open.  To reproduce this,
>
>     1. emacs -Q
>     2. Spam M-& sleep 100 three or four times.
>     3. Likewise for C-u M-x shell RET.
>     4. Now, C-<mouse-1> and observe how there are two "Shell" menu
>        items.
>
> To bring back the old behaviour, one can do
>
> diff --git a/lisp/mouse.el b/lisp/mouse.el
> index 1f0ca6a51b6..8caa611277e 100644
> --- a/lisp/mouse.el
> +++ b/lisp/mouse.el
> @@ -2691,6 +2691,7 @@ mouse-buffer-menu-mode-groups
>      ("\\bVM\\b\\|\\bMH\\b\\|Message\\b\\|Mail\\|Group\\|Score\\|Summary\\|Article"
>       . "Mail/News")
>      ("\\<C\\>" . "C")
> +    ("Shell\\'" . "Shell")
>      ("ObjC" . "C")
>      ("Text" . "Text")
>      ("Outline" . "Text")
>
> which consolidates all mode-names that end with "Shell".  Just using
> "Shell" as the regexp erroneously groups sh-script-mode buffers along
> with shell-mode and shell-command-mode buffers.

And here's a proper patch:

>From c1c5faa60f6aed5fa3855d68c73412b8cc9d931e Mon Sep 17 00:00:00 2001
From: Visuwesh <[email-masked]>
Date: Thu, 27 Feb 2025 15:32:04 +0530
Subject: [PATCH] Group shell and shell-command buffers under the same submenu

* lisp/mouse.el (mouse-buffer-menu-mode-groups): Group
'shell-mode' and 'shell-command-mode' buffers under the same
"Shell" submenu item in 'mouse-buffer-menu'.  (Bug#76593)
---
 lisp/mouse.el | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 1f0ca6a51b6..66499db3b34 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -2694,6 +2694,7 @@ mouse-buffer-menu-mode-groups
     ("ObjC" . "C")
     ("Text" . "Text")
     ("Outline" . "Text")
+    ("\\`Shell\\'" . "Shell")
     ("\\(HT\\|SG\\|X\\|XHT\\)ML" . "SGML")
     ("\\blog\\b\\|diff\\|\\bvc\\b\\|cvs\\|Git\\|Annotate" . "Version Control")
     ("Threads\\|Memory\\|Disassembly\\|Breakpoints\\|Frames\\|Locals\\|Registers\\|Inferior I/O\\|Debugger"
-- 
2.47.2

I went with the regexp \`Shell\' to ensure only major-modes with
`mode-name' "Shell" will be matched.