Subject: [PATCH] [Tree-sitter] Align C++ access specifiers to their enclosing class/struct/union
From: Daniel Martín <[email-masked]>
To: [email-masked]
Date: Sun, 11 Dec 2022 16:19:13 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

The following C++ class is indented differently in c++-mode and
c++-ts-mode:

class Sample {
public:
void sample();
private:
int a;
};

c++-mode indents it like

class Sample {
public:
  void sample();
private:
  int a;
};

c++-ts-mode indents it like

class Sample {
public:
void sample();
private:
int a;
};

I've attached a patch so that C++ classes are indented the same in
c++-mode and c++-ts-mode when the default style is used.

Thanks.

From b1fb292835772ed6f4da4f91fa58e84ce7582a50 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <[email-masked]>
Date: Sun, 11 Dec 2022 15:57:43 +0100
Subject: [PATCH] Align C++ access specifiers to their enclosing
 class/struct/union

The default style in c++-mode aligns access specifiers like "private",
"public" or "protected" to their enclosing class, struct, or union.
The "ellemtel" style indents access specifiers, but this C++ style is
not supported by c++-ts-mode yet.

* lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Align access
specifiers to their enclosing class/struct/union.
---
 lisp/progmodes/c-ts-mode.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 824325d83e..5dab9879dc 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -120,6 +120,8 @@ c-ts-mode--indent-styles
            ((query "(call_expression arguments: (_) @indent)") parent c-ts-mode-indent-offset)
            ((parent-is "call_expression") parent 0)
            ((parent-is "enumerator_list") parent-bol c-ts-mode-indent-offset)
+           ,@(when (eq mode 'cpp)
+               '(((node-is "access_specifier") parent-bol 0)))
            ((parent-is "field_declaration_list") parent-bol c-ts-mode-indent-offset)
            ((parent-is "initializer_list") parent-bol c-ts-mode-indent-offset)
            ((parent-is "if_statement") parent-bol c-ts-mode-indent-offset)
-- 
2.34.1