Skip to content

Commit

Permalink
Add textobjects and indents to c and cpp
Browse files Browse the repository at this point in the history
Somehow, indentation inside conditions doesn't work, i.e.

  while (1 +<hit enter>)
leads to
  while (1 +
  )
but the expected result should be
  while (1 +
    )

But it is a lot better than before.
  • Loading branch information
Flakebi committed Dec 18, 2021
1 parent f174d27 commit d39f6ec
Show file tree
Hide file tree
Showing 5 changed files with 60 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,10 +1,10 @@
| Language | Syntax Highlighting | Treesitter Textobjects | Auto Indent | Default LSP |
| --- | --- | --- | --- | --- |
| bash || | | `bash-language-server` |
| c || | | `clangd` |
| c || | | `clangd` |
| c-sharp || | | |
| cmake || | | `cmake-language-server` |
| cpp || | | `clangd` |
| cpp || | | `clangd` |
| css || | | |
| dart || || `dart` |
| elixir || | | `elixir-ls` |
Expand Down
20 changes: 20 additions & 0 deletions runtime/queries/c/indents.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
indent = [
"compound_statement",
"field_declaration_list",
"enumerator_list",
"parameter_list",
"init_declarator",
"case_statement",
"condition_clause",
"expression_statement",
"if_statement",
"for_statement",
"while_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
21 changes: 21 additions & 0 deletions runtime/queries/cpp/indents.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
indent = [
"compound_statement",
"field_declaration_list",
"enumerator_list",
"parameter_list",
"init_declarator",
"case_statement",
"condition_clause",
"expression_statement",
"if_statement",
"for_statement",
"while_statement",
]

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

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

0 comments on commit d39f6ec

Please sign in to comment.