summaryrefslogtreecommitdiff
path: root/lisp/progmodes/c-ts-mode.el
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2023-01-19 14:46:17 -0800
committerYuan Fu <casouri@gmail.com>2023-01-19 14:47:25 -0800
commit7b7b2b95138e691f1b155060b91a8998e3905651 (patch)
tree0cca8b748fe53de4ae79470a4fea666fd0c34edb /lisp/progmodes/c-ts-mode.el
parent7ca71d66dc7365a3dd8dd5f20638b4fa612fdc5e (diff)
downloademacs-7b7b2b95138e691f1b155060b91a8998e3905651.tar.gz
emacs-7b7b2b95138e691f1b155060b91a8998e3905651.tar.bz2
emacs-7b7b2b95138e691f1b155060b91a8998e3905651.zip
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.
Diffstat (limited to 'lisp/progmodes/c-ts-mode.el')
-rw-r--r--lisp/progmodes/c-ts-mode.el13
1 files changed, 12 insertions, 1 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 0cf77c21d83..3d887971f64 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -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))))))