emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 b06d5519664 2/2: Fix c-ts-mode empty line indentation (bug#6189


From: Yuan Fu
Subject: emacs-29 b06d5519664 2/2: Fix c-ts-mode empty line indentation (bug#61893)
Date: Wed, 1 Mar 2023 17:08:05 -0500 (EST)

branch: emacs-29
commit b06d5519664b0f417be7f415964b0a4decc0f732
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Fix c-ts-mode empty line indentation (bug#61893)
    
    * lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Make the
    "rest sibling" matchers catch the case where NODE is nil, when
    indenting an empty line.
    * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New test.
---
 lisp/progmodes/c-ts-mode.el                        |  8 +++---
 .../lisp/progmodes/c-ts-mode-resources/indent.erts | 33 ++++++++++++++++------
 2 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index cc99b8e213e..259b96d342e 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -356,17 +356,17 @@ MODE is either `c' or `cpp'."
 
            ;; int[5] a = { 0, 0, 0, 0 };
            ((match nil "initializer_list" nil 1 1) parent-bol 
c-ts-mode-indent-offset)
-           ((match nil "initializer_list" nil 2) 
c-ts-mode--anchor-prev-sibling 0)
+           ((parent-is "initializer_list") c-ts-mode--anchor-prev-sibling 0)
            ;; Statement in enum.
            ((match nil "enumerator_list" nil 1 1) standalone-parent 
c-ts-mode-indent-offset)
-           ((match nil "enumerator_list" nil 2) c-ts-mode--anchor-prev-sibling 
0)
+           ((parent-is "enumerator_list") c-ts-mode--anchor-prev-sibling 0)
            ;; Statement in struct and union.
            ((match nil "field_declaration_list" nil 1 1) standalone-parent 
c-ts-mode-indent-offset)
-           ((match nil "field_declaration_list" nil 2) 
c-ts-mode--anchor-prev-sibling 0)
+           ((parent-is "field_declaration_list") 
c-ts-mode--anchor-prev-sibling 0)
 
            ;; Statement in {} blocks.
            ((match nil "compound_statement" nil 1 1) standalone-parent 
c-ts-mode-indent-offset)
-           ((match nil "compound_statement" nil 2) 
c-ts-mode--anchor-prev-sibling 0)
+           ((parent-is "compound_statement") c-ts-mode--anchor-prev-sibling 0)
            ;; Opening bracket.
            ((node-is "compound_statement") standalone-parent 
c-ts-mode-indent-offset)
            ;; Bug#61291.
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts 
b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 36d7af4faf1..904c6498cb5 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -84,14 +84,6 @@ int main()
 }
 =-=-=
 
-Name: Empty Line
-=-=
-int main()
-{
-  |
-}
-=-=-=
-
 Name: Concecutive blocks (GNU Style) (bug#60873)
 
 =-=
@@ -385,3 +377,28 @@ namespace test {
   };
 }
 =-=-=
+
+Code:
+  (lambda ()
+    (c-ts-mode)
+    (setq-local indent-tabs-mode nil)
+    (setq-local c-ts-mode-indent-offset 2)
+    (c-ts-mode-set-style 'gnu)
+    (indent-for-tab-command))
+
+Name: Empty Line
+=-=
+int main()
+{
+  |
+}
+=-=-=
+
+Name: Empty Line Previous Sibling
+=-=
+int main()
+{
+  int a = 1;
+  |
+}
+=-=-=



reply via email to

[Prev in Thread] Current Thread [Next in Thread]