]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix c-ts-mode indent (bug#60873)
authorYuan Fu <casouri@gmail.com>
Thu, 19 Jan 2023 22:46:17 +0000 (14:46 -0800)
committerYuan Fu <casouri@gmail.com>
Thu, 19 Jan 2023 22:47:25 +0000 (14:47 -0800)
* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--statement-offset): Handle the edge case.
* test/lisp/progmodes/c-ts-mode-resources/indent.erts: Add a test.

lisp/progmodes/c-ts-mode.el
test/lisp/progmodes/c-ts-mode-resources/indent.erts

index 0cf77c21d83b2a89884e57affbcf693644d52dbc..3d887971f643fd9b159b23b395f23dbf0370f524 100644 (file)
@@ -285,7 +285,18 @@ PARENT is NODE's parent."
         (cl-incf level)
         (save-excursion
           (goto-char (treesit-node-start node))
-          (cond ((bolp) nil)
+          ;; Add an extra level if the opening bracket is on its own
+          ;; line, except (1) it's at top-level, or (2) it's immedate
+          ;; parent is another block.
+          (cond ((bolp) nil) ; Case (1).
+                ((let ((parent-type (treesit-node-type
+                                     (treesit-node-parent node))))
+                   ;; Case (2).
+                   (and parent-type
+                        (string-match-p c-ts-mode-indent-block-type-regexp
+                                        parent-type)))
+                 nil)
+                ;; Add a level.
                 ((looking-back (rx bol (* whitespace))
                                (line-beginning-position))
                  (cl-incf level))))))
index 70fce68b0ec4bba6226a9a3e4bafef0e622b817f..b8524432d028d33f3006eead7ef555fa31f9aca5 100644 (file)
@@ -92,6 +92,19 @@ int main()
 }
 =-=-=
 
+Name: Concecutive blocks (GNU Style) (bug#60873)
+
+=-=
+int
+main (int   argc,
+      char *argv[])
+{
+  {
+    int i = 0;
+  }
+}
+=-=-=
+
 Name: Multiline Parameter List (bug#60398)
 
 =-=