]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix c-ts-common-baseline-indent-rule for lists (bug#76908)
authorYuan Fu <casouri@gmail.com>
Tue, 11 Mar 2025 09:36:11 +0000 (02:36 -0700)
committerEshel Yaron <me@eshelyaron.com>
Wed, 12 Mar 2025 18:59:13 +0000 (19:59 +0100)
* lisp/progmodes/c-ts-common.el:
(c-ts-common-baseline-indent-rule): Use the first non-comment
sibling rather than first sibling.

(cherry picked from commit 3b3170244da44d3d0d76139b138df65ea6adc064)

lisp/progmodes/c-ts-common.el

index 3c36382666417aa2e53855cca5795aad5e9c3e11..516d5f9b7227f84c77d040d25192bc6f80384c43 100644 (file)
 ;;
 ;; For indenting statements:
 ;;
-;; - Set `c-ts-common-indent-offset', and
-;;   `c-ts-common-indent-type-regexp-alist', then use simple-indent
-;;   offset `c-ts-common-statement-offset' in
-;;   `treesit-simple-indent-rules'.
+;; - Set `c-ts-common-indent-offset'.  Use
+;;   `c-ts-common-baseline-indent-rule' as the fallback indent rule, and
+;;   add override rules to tweak the behavior.
+;;
+;; - There's also a node-level-based indentation algorithm, it's not as
+;;   good as `c-ts-common-baseline-indent-rule', but if you want to play
+;;   with it, set `c-ts-common-indent-type-regexp-alist' and use
+;;   `c-ts-common-statement-offset'.
 
 ;;; Code:
 
@@ -709,6 +713,9 @@ The rule also handles method chaining like
      ((treesit-node-match-p (treesit-node-child parent 0)
                             (rx (or "(" "[")))
       (let ((first-sibling (treesit-node-child parent 0 'named)))
+        (while (treesit-node-match-p
+                first-sibling c-ts-common--comment-regexp 'ignore-missing)
+          (setq first-sibling (treesit-node-next-sibling first-sibling 'named)))
         (cond
          ;; Closing delimiters.
          ((treesit-node-match-p node (rx (or ")" "]")))