Subject: 31.0.50; problems setting custom c++-ts-mode indent style

From: "Jacek Świerk" <[email-masked]>
Date: Tue, 17 Jun 2025 07:17:39 +0200

I encountered two separate issues while configuring a non-default
indentation style in c++-ts-mode (although one of them also applies to
c-ts-mode).

When invoking C-c . to set a style, c-ts-mode-set-style incorrectly sets
treesit-simple-indent-rules to nil, preventing proper indentation.

I believe the issue stems from a typo in the c-ts-mode-set-style
function. Specifically, when the mode is c++-ts-mode, the function
passes the symbol 'c++ to c-ts-mode--simple-indent-rules, but the
function expects the symbol 'cpp instead.

To reproduce:

M-x c++-ts-mode
C-c . and pick any style
C-h v treesit-simple-indent-rules should show nil and indentation does
not work correctly

As for the second issue, in definitions of both c-ts-mode and
c++-ts-mode, treesit-simple-indent-rules is derived from the return
value of c-ts-mode--simple-indent-rules (lines 1486 and 1559). However,
if the user customizes the indentation style by setting
c-ts-mode-indent-style to a function, the current implementation breaks.
The c-ts-mode--simple-indent-rules function expects one of the four
predefined styles, but when c-ts-mode-indent-style is a custom function,
it does not handle this correctly.

To reproduce:

Set c-ts-mode-indent-style to some custom function
M-x c++-ts-mode
C-h v treesit-simple-indent-rules should show ((cpp)) and indentation
does not work correctly

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.49, cairo version 1.18.4) of 2025-06-13 built on arch
Repository revision: bec823b107ef7d3b51b8e430ccab82c81bd63d24
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12401006
System Description: Arch Linux

Configured using:
'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
--localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
--with-modules --without-m17n-flt --without-gconf
--with-native-compilation=yes --with-xinput2 --with-x-toolkit=gtk3
--without-xaw3d --with-sound=no --with-tree-sitter --without-gpm
--without-compress-install
'--program-transform-name=s/\([ec]tags\)/\1.emacs/'
'CFLAGS=-march=native -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' 'LDFLAGS=-Wl,-O1 -Wl,--sort-common
-Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,-z,pack-relative-relocs
-fuse-ld=mold''

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG
LCMS2 LIBOTF LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY
PDUMPER PNG RSVG SECCOMP SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP X11 XDBE XIM XINERAMA XINPUT2 XPM XRANDR GTK3 ZLIB

Important settings:
value of $LC_MESSAGES: en_US.UTF-8
value of $LANG: en_US.UTF-8
value of $XMODIFIERS: im=fcit
locale-coding-system: utf-8-unix

Major mode: C++//

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
minibuffer-regexp-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 compile comint ansi-osc ansi-color ring emacsbug
lisp-mnt 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 mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils time-date subr-x cl-extra cl-print
thingatpt help-fns byte-opt gv radix-tree help-mode comp-run bytecomp
byte-compile comp-common rx cl-seq c++-ts-mode c-ts-mode c-ts-common
treesit cl-loaddefs cl-lib rmc iso-transl tooltip cconv eldoc paren
electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel
term/x-win x-win term/common-win x-dnd touch-screen 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 lcms2
dynamic-setting system-font-setting font-render-setting cairo gtk
x-toolkit xinput2 x multi-tty move-toolbar make-network-process
tty-child-frames native-compile emacs)

Memory information:
((conses 16 86721 11062) (symbols 48 7857 0) (strings 32 23041 2379)
(string-bytes 1 683662) (vectors 16 13204)
(vector-slots 8 177281 10463) (floats 8 82 1) (intervals 56 335 0)
(buffers 1064 12))