Subject: bug#62043: [PATCH] Fix enums appearing as structs in c-ts-base-mode's imenu

From: Randy Taylor <[email-masked]>
Date: Thu, 09 Mar 2023 02:04:21 +0000

On Wednesday, March 8th, 2023 at 18:27, Yuan Fu <[email-masked]> wrote:
> 
> > On Mar 7, 2023, at 5:49 PM, Randy Taylor [email-masked] wrote:
> > 
> > X-Debbugs-CC: [email-masked]
> > 
> > With {c, c++}-ts-mode, enums appear as structs in imenu. The attached patch fixes this.
> > 
> > Example:
> > enum Thing { A, B, C };
> > 
> > Should appear as Enum Thing
> > <0001-Fix-enums-appearing-as-structs-in-c-ts-base-mode-s-i.patch>
> 
> 
> Thanks! I wonder what determines which categories to merge together and which to not? If we separate Enums, should we also separate Unions?
> 
> Yuan

I think they should all be separate actually. Attached a patch that does so.

From c9b3104a4cca2e921fd6340a991c5601c1ae6a33 Mon Sep 17 00:00:00 2001
From: Randy Taylor <[email-masked]>
Date: Tue, 7 Mar 2023 20:38:18 -0500
Subject: [PATCH] Fix enums and unions appearing as structs in c-ts-base-mode's
 imenu

* lisp/progmodes/c-ts-mode.el (c-ts-base-mode): Separate enums and unions out
from structs.
---
 lisp/progmodes/c-ts-mode.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index fdd962ff020..ff86b9e0544 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -930,9 +930,9 @@ c-ts-base-mode
   ;; Imenu.
   (setq-local treesit-simple-imenu-settings
               (let ((pred #'c-ts-mode--defun-valid-p))
-                `(("Struct" ,(rx bos (or "struct" "enum" "union")
-                                 "_specifier" eos)
-                   ,pred nil)
+                `(("Enum" "\\`enum_specifier\\'" ,pred nil)
+                  ("Struct" "\\`struct_specifier\\'" ,pred nil)
+                  ("Union" "\\`union_specifier\\'" ,pred nil)
                   ("Variable" ,(rx bos "declaration" eos) ,pred nil)
                   ("Function" "\\`function_definition\\'" ,pred nil)
                   ("Class" ,(rx bos (or "class_specifier"
-- 
2.39.2