Fix c-ts-mode indent (bug#60873)

* 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.
This commit is contained in:
Yuan Fu 2023-01-19 14:46:17 -08:00
parent 7ca71d66dc
commit 7b7b2b9513
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
2 changed files with 25 additions and 1 deletions

View file

@ -285,7 +285,18 @@ PARENT is NODE's parent."
(cl-incf level) (cl-incf level)
(save-excursion (save-excursion
(goto-char (treesit-node-start node)) (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)) ((looking-back (rx bol (* whitespace))
(line-beginning-position)) (line-beginning-position))
(cl-incf level)))))) (cl-incf level))))))

View 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) Name: Multiline Parameter List (bug#60398)
=-= =-=