Skip to content

Commit

Permalink
Add textobjects and indents to c and cpp
Browse files Browse the repository at this point in the history
Indentation of single line statements doesn't work, i.e.

  for (;;)<hit enter>
leads to
  for(;;)
  <cursor here>

Only blocks with curly braces are indented.
  • Loading branch information
Flakebi committed Jan 3, 2022
1 parent dbaed0b commit e50ffae
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
| Language | Syntax Highlighting | Treesitter Textobjects | Auto Indent | Default LSP |
| --- | --- | --- | --- | --- |
| bash || | | `bash-language-server` |
| c || | | `clangd` |
| c || | | `clangd` |
| c-sharp || | | |
| cmake |||| `cmake-language-server` |
| comment || | | |
| cpp || | | `clangd` |
| cpp || | | `clangd` |
| css || | | |
| dart || || `dart` |
| dockerfile || | | `docker-langserver` |
Expand Down
16 changes: 16 additions & 0 deletions runtime/queries/c/indents.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
indent = [
"compound_statement",
"field_declaration_list",
"enumerator_list",
"parameter_list",
"init_declarator",
"case_statement",
"condition_clause",
"expression_statement",
]

outdent = [
"case",
"}",
"]",
]
13 changes: 13 additions & 0 deletions runtime/queries/c/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function_definition
body: (_) @function.inside) @function.around

(struct_specifier
body: (_) @class.inside) @class.around

(enum_specifier
body: (_) @class.inside) @class.around

(union_specifier
body: (_) @class.inside) @class.around

(parameter_declaration) @parameter.inside
17 changes: 17 additions & 0 deletions runtime/queries/cpp/indents.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
indent = [
"compound_statement",
"field_declaration_list",
"enumerator_list",
"parameter_list",
"init_declarator",
"case_statement",
"condition_clause",
"expression_statement",
]

outdent = [
"case",
"access_specifier",
"}",
"]",
]
7 changes: 7 additions & 0 deletions runtime/queries/cpp/textobjects.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; inherits: c

(lambda_expression
body: (_) @function.inside) @function.around

(class_specifier
body: (_) @class.inside) @class.around

0 comments on commit e50ffae

Please sign in to comment.