diff options
| author | Yuan Fu | 2022-12-29 00:58:50 -0800 |
|---|---|---|
| committer | Yuan Fu | 2022-12-29 00:58:50 -0800 |
| commit | 784e509bded0fe41dd9908022a92c54ac8c21a2c (patch) | |
| tree | 5630e87b37619e7239c8206805a03cc1997fd611 | |
| parent | 909091d7578b7225601b202fb9257dedae879e9a (diff) | |
| download | emacs-784e509bded0fe41dd9908022a92c54ac8c21a2c.tar.gz emacs-784e509bded0fe41dd9908022a92c54ac8c21a2c.zip | |
Fix c-ts-mode bracket indentation (bug#60398)
* lisp/progmodes/c-ts-mode.el (c-ts-mode--indent-styles): Use new
anchor.
(c-ts-mode--bracket-children-anchor): New anchor function.
| -rw-r--r-- | lisp/progmodes/c-ts-mode.el | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 8ba6cdee42d..82458ba5adb 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el | |||
| @@ -118,7 +118,7 @@ MODE is either `c' or `cpp'." | |||
| 118 | `(((parent-is "translation_unit") parent-bol 0) | 118 | `(((parent-is "translation_unit") parent-bol 0) |
| 119 | ((node-is ")") parent 1) | 119 | ((node-is ")") parent 1) |
| 120 | ((node-is "]") parent-bol 0) | 120 | ((node-is "]") parent-bol 0) |
| 121 | ((node-is "}") (and parent parent-bol) 0) | 121 | ((node-is "}") c-ts-mode--bracket-children-anchor 0) |
| 122 | ((node-is "else") parent-bol 0) | 122 | ((node-is "else") parent-bol 0) |
| 123 | ((node-is "case") parent-bol 0) | 123 | ((node-is "case") parent-bol 0) |
| 124 | ((node-is "preproc_arg") no-indent) | 124 | ((node-is "preproc_arg") no-indent) |
| @@ -133,7 +133,8 @@ MODE is either `c' or `cpp'." | |||
| 133 | ((match "#endif" "preproc_if") point-min 0) | 133 | ((match "#endif" "preproc_if") point-min 0) |
| 134 | ((match "preproc_function_def" "compound_statement") point-min 0) | 134 | ((match "preproc_function_def" "compound_statement") point-min 0) |
| 135 | ((match "preproc_call" "compound_statement") point-min 0) | 135 | ((match "preproc_call" "compound_statement") point-min 0) |
| 136 | ((parent-is "compound_statement") (and parent parent-bol) c-ts-mode-indent-offset) | 136 | ((parent-is "compound_statement") |
| 137 | c-ts-mode--bracket-children-anchor c-ts-mode-indent-offset) | ||
| 137 | ((parent-is "function_definition") parent-bol 0) | 138 | ((parent-is "function_definition") parent-bol 0) |
| 138 | ((parent-is "conditional_expression") first-sibling 0) | 139 | ((parent-is "conditional_expression") first-sibling 0) |
| 139 | ((parent-is "assignment_expression") parent-bol c-ts-mode-indent-offset) | 140 | ((parent-is "assignment_expression") parent-bol c-ts-mode-indent-offset) |
| @@ -189,6 +190,21 @@ MODE is either `c' or `cpp'." | |||
| 189 | ('linux (alist-get 'linux (c-ts-mode--indent-styles mode))))))) | 190 | ('linux (alist-get 'linux (c-ts-mode--indent-styles mode))))))) |
| 190 | `((,mode ,@style)))) | 191 | `((,mode ,@style)))) |
| 191 | 192 | ||
| 193 | (defun c-ts-mode--bracket-children-anchor (_n parent &rest _) | ||
| 194 | "This anchor is used for children of a compound_statement. | ||
| 195 | So anything inside a {} block. PARENT should be the | ||
| 196 | compound_statement. This anchor looks at the {, if itson its own | ||
| 197 | line, anchor at it, if it has stuff before it, anchor at the | ||
| 198 | beginning of grandparent." | ||
| 199 | (save-excursion | ||
| 200 | (goto-char (treesit-node-start parent)) | ||
| 201 | (let ((bol (line-beginning-position))) | ||
| 202 | (skip-chars-backward " \t") | ||
| 203 | (treesit-node-start | ||
| 204 | (if (< bol (point)) | ||
| 205 | (treesit-node-parent parent) | ||
| 206 | parent))))) | ||
| 207 | |||
| 192 | (defun c-ts-mode--looking-at-star (&rest _) | 208 | (defun c-ts-mode--looking-at-star (&rest _) |
| 193 | "A tree-sitter simple indent matcher. | 209 | "A tree-sitter simple indent matcher. |
| 194 | Matches if there is a \"*\" after point (ignoring whitespace in | 210 | Matches if there is a \"*\" after point (ignoring whitespace in |