emacs-diffs
[Top][All Lists]
Advanced

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

emacs-29 f9b7913656f: Fix empty line indentation in c-ts-mode (bug#61997


From: Yuan Fu
Subject: emacs-29 f9b7913656f: Fix empty line indentation in c-ts-mode (bug#61997)
Date: Tue, 7 Mar 2023 19:44:19 -0500 (EST)

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

    Fix empty line indentation in c-ts-mode (bug#61997)
    
    * lisp/progmodes/c-ts-mode.el:
    (c-ts-mode--indent-styles): Handle the empty line case.
    * test/lisp/progmodes/c-ts-mode-resources/indent.erts: New test.
    
    * doc/lispref/modes.texi (Parser-based Indentation): Update manual.
    * lisp/treesit.el (treesit-simple-indent-presets): Support null as
    a value for NODE-TYPE in the 'match' matcher.
---
 doc/lispref/modes.texi                              |  3 +++
 lisp/progmodes/c-ts-mode.el                         |  4 +++-
 lisp/treesit.el                                     |  9 ++++++---
 test/lisp/progmodes/c-ts-mode-resources/indent.erts | 16 ++++++++++++++++
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index c12224230fc..fff1ea65b07 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -5064,6 +5064,9 @@ first child where parent is @code{argument_list}, use
 (match nil "argument_list" nil nil 0 0)
 @end example
 
+In addition, @var{node-type} can be a special value @code{null},
+which matches when the value of @var{node} is @code{nil}.
+
 @item n-p-gp
 Short for ``node-parent-grandparent'', this matcher is a function of 3
 arguments: @var{node-type}, @var{parent-type}, and
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 0b775b2d5c8..fdd962ff020 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -419,7 +419,9 @@ MODE is either `c' or `cpp'."
            ((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)
+           ((or (match nil "compound_statement" nil 1 1)
+                (match null "compound_statement"))
+            standalone-parent c-ts-mode-indent-offset)
            ((parent-is "compound_statement") c-ts-mode--anchor-prev-sibling 0)
            ;; Opening bracket.
            ((node-is "compound_statement") standalone-parent 
c-ts-mode-indent-offset)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 44a93f5e261..c118f5d52a4 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -1107,9 +1107,11 @@ See `treesit-simple-indent-presets'.")
                 (&optional node-type parent-type node-field
                            node-index-min node-index-max)
                 (lambda (node parent &rest _)
-                  (and (or (null node-type)
-                           (string-match-p
-                            node-type (or (treesit-node-type node) "")))
+                  (and (pcase node-type
+                         ('nil t)
+                         ('null (null node))
+                         (_ (string-match-p
+                             node-type (or (treesit-node-type node) ""))))
                        (or (null parent-type)
                            (string-match-p
                             parent-type (treesit-node-type parent)))
@@ -1302,6 +1304,7 @@ MATCHER:
         (match nil \"argument_list\" nil nil 0 0).
 
     NODE-TYPE, PARENT-TYPE, and NODE-FIELD are regexps.
+    NODE-TYPE can also be `null', which matches when NODE is nil.
 
 no-node
 
diff --git a/test/lisp/progmodes/c-ts-mode-resources/indent.erts 
b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
index 77bfeb5ad6e..9e28ef203fd 100644
--- a/test/lisp/progmodes/c-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/c-ts-mode-resources/indent.erts
@@ -418,3 +418,19 @@ required_matrix_height (struct window *w)
   |
 }
 =-=-=
+
+Name: Empty Line
+
+=-=
+int
+main (void)
+{
+|
+}
+=-=
+int
+main (void)
+{
+  |
+}
+=-=-=



reply via email to

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