]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix c-ts-common-statement-offset and c-ts-common--node-is
authorYuan Fu <casouri@gmail.com>
Sat, 25 Feb 2023 03:31:34 +0000 (19:31 -0800)
committerYuan Fu <casouri@gmail.com>
Sat, 25 Feb 2023 03:51:43 +0000 (19:51 -0800)
* lisp/progmodes/c-ts-common.el:
(c-ts-common--node-is): Guard against case where the node has no field
name.
(c-ts-common-statement-offset): Do indent a level if the "if" in the
"else if" is on an independent line.

lisp/progmodes/c-ts-common.el

index 72df65a228732761b3888b5761c0b8ba1e2b47d9..de0ec0d28768c77451e0d73ba0f44b53d548ce61 100644 (file)
@@ -305,6 +305,7 @@ If NODE is nil, return nil."
                        (and parent
                             (string-match-p (car regexp)
                                             (treesit-node-type parent))
+                            (treesit-node-field-name node)
                             (string-match-p (cdr regexp)
                                             (treesit-node-field-name
                                              node)))
@@ -363,7 +364,13 @@ characters on the current line."
           (cl-incf level))
         ;; Flatten "else if" statements.
         (when (and (c-ts-common--node-is node 'else)
-                   (c-ts-common--node-is node 'if))
+                   (c-ts-common--node-is node 'if)
+                   ;; But if the "if" is on it's own line, still
+                   ;; indent a level.
+                   (not (save-excursion
+                          (goto-char (treesit-node-start node))
+                          (looking-back (rx bol (* whitespace))
+                                        (line-beginning-position)))))
           (cl-decf level)))
       ;; Go up the tree.
       (setq node (treesit-node-parent node)))