GNU bug report logs -
#78814
31.0.50; problems setting custom c++-ts-mode indent style
Previous Next
Reported by: "Jacek Świerk" <jacekswierk <at> gmail.com>
Date: Tue, 17 Jun 2025 10:02:02 UTC
Severity: normal
Found in version 31.0.50
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #11 received at 78814 <at> debbugs.gnu.org (full text, mbox):
[Please use Reply All to reply, to keep the bug tracker CC'ed.]
> From: Jacek Świerk <jacekswierk <at> gmail.com>
> Date: Sat, 21 Jun 2025 16:29:19 +0200
>
> Here's more detailed reproduction recipe:
>
> 1. Define a custom indentation style for C++:
> (defun my--c++-ts-mode-indent-style ()
> "Use BSD style but don't indent inside namespaces."
> `((cpp
> ((n-p-gp nil nil "namespace_definition") grand-parent 0)
> ,@(cdr (car (c-ts-mode--simple-indent-rules 'cpp 'bsd))))))
>
> 2. Set the custom style as default:
> (setopt c-ts-mode-indent-style 'my--c++-ts-mode-indent-style)
>
> 3. Enable C++ treesit mode:
> (c++-ts-mode)
>
> 4. Verify `treesit-simple-indent-rules` - it shows only `((cpp))` instead of the expected rules.
>
> This happens because c-ts-mode--simple-indent-rules, which is called while
> changing major mode (line 1563) to c++-ts-mode, has pcase only for 4 styles
> (gnu, k&r, linux and bsd), meaning it doesn't handle the situation when
> c-ts-mode-indent-style is set to some custom function. I can work around it by
> calling (setopt c-ts-mode-indent-style 'my--c++-ts-mode-indent-style) after
> switching to c++-ts-mode with a hook but is this the expected flow?
Thanks. Does the patch below fix the problem?
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 0df9fe3..5155193 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -1487,8 +1487,10 @@ c-ts-mode
(setq-local comment-end " */")
;; Indent.
(setq-local treesit-simple-indent-rules
- (c-ts-mode--simple-indent-rules
- 'c c-ts-mode-indent-style))
+ (if (functionp c-ts-mode-indent-style)
+ (funcall c-ts-mode-indent-style)
+ (c-ts-mode--simple-indent-rules
+ 'c c-ts-mode-indent-style)))
;; (setq-local treesit-simple-indent-rules
;; `((c . ,(alist-get 'gnu (c-ts-mode--indent-styles 'c)))))
;; Font-lock.
@@ -1560,8 +1562,10 @@ c++-ts-mode
;; Indent.
(setq-local treesit-simple-indent-rules
- (c-ts-mode--simple-indent-rules
- 'cpp c-ts-mode-indent-style))
+ (if (functionp c-ts-mode-indent-style)
+ (funcall c-ts-mode-indent-style)
+ (c-ts-mode--simple-indent-rules
+ 'cpp c-ts-mode-indent-style)))
;; Font-lock.
(setq-local treesit-font-lock-settings
This bug report was last modified 25 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.