aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorGeorge Harker <george@george-graphics.co.uk>2023-03-19 18:09:18 -0700
committerAmaan Qureshi <amaanq12@gmail.com>2023-03-24 13:07:53 -0400
commitd1333dd7e51729a581fed3e429fa035bff77a3db (patch)
tree961499041e8e3da94963e7331e09754d423b40a1 /doc
parentfix: shim 0.9 deprecations (diff)
downloadnvim-treesitter-d1333dd7e51729a581fed3e429fa035bff77a3db.tar
nvim-treesitter-d1333dd7e51729a581fed3e429fa035bff77a3db.tar.gz
nvim-treesitter-d1333dd7e51729a581fed3e429fa035bff77a3db.tar.bz2
nvim-treesitter-d1333dd7e51729a581fed3e429fa035bff77a3db.tar.lz
nvim-treesitter-d1333dd7e51729a581fed3e429fa035bff77a3db.tar.xz
nvim-treesitter-d1333dd7e51729a581fed3e429fa035bff77a3db.tar.zst
nvim-treesitter-d1333dd7e51729a581fed3e429fa035bff77a3db.zip
refactor(indent)!: Rework indent, aligned indent
indents now use @indent.X style captures, and indent.PROP for properties to set on those captures, as documented in the help. Captures are: indent.auto indent.begin indent.end indent.dedent indent.branch indent.ignore indent.align indent.zero Properties are: indent.immediate indent.start_at_same_line indent.open_delimiter indent.close_delimiter indent.increment indent.avoid_last_matching_next Multiple opening delims on one line and multiple closing on a line are collapsed so as not to over indent, The final line of @indent.align blocks which must in some cases be treated specially to avoid clashing with the next line is treated the same regardless of whether the @indent.align capture actually uses aligned indentation or just normal indentation. The indent.avoid_last_matching_next property controls this. Adjust python to use these. List, set, dict and tuple all use @indent.align which permits both hanging and aligned styles. Finally, try: on it’s own will indent when typing live but make no guaranteeds about whole-file formatting. Includes lucario387:fix-align-indent
Diffstat (limited to 'doc')
-rw-r--r--doc/nvim-treesitter.txt105
1 files changed, 105 insertions, 0 deletions
diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt
index f05693676..5509dc8af 100644
--- a/doc/nvim-treesitter.txt
+++ b/doc/nvim-treesitter.txt
@@ -222,7 +222,112 @@ Supported options:
enable = true
},
}
+
+`@indent` *nvim-treesitter-indentation-queries*
+Queries can use the following captures: `@indent` and `@dedent`,
+`@branch`, `@indent_end` or `@aligned_indent`. An `@ignore` capture tells
+treesitter to ignore indentation and a `@zero_indent` capture sets
+the indentation to 0.
+
+`@indent` *nvim-treesitter-indentation-indent*
+The `@indent` specifies that the next line should be indented. Multiple
+indents on the same line get collapsed. Eg.
+
+>
+ (
+ (if_statement)
+ (ERROR "else") @indent
+ )
<
+Indent can also have `immediate_indent` set using a `#set!` directive, which
+permits the next line to indent even when the block intended to be indented
+has no content yet, improving interactive typing.
+
+eg for python:
+>
+ ((if_statement) @indent
+ (#set! "immediate_indent" 1))
+<
+
+Will allow:
+>
+ if True:<CR>
+ # Auto indent to here
+
+`@indent_end` *nvim-treesitter-indentation-indent_end*
+An `@indent_end` capture is used to specify that the indented region ends and
+any text subsequent to the capture should be dedented.
+
+`@branch` *nvim-treesitter-indentation-branch*
+An `@branch` capture is used to specify that a dedented region starts
+at the line including the captured nodes.
+
+`@dedent` *nvim-treesitter-indentation-dedent*
+A `@dedent` capture specifies dedenting starting on the next line.
+>
+`@aligned_indent` *nvim-treesitter-indentation-aligned_indent*
+Aligned indent blocks may be specified with the `@aligned_indent` capture.
+This permits
+
+>
+ foo(a,
+ b,
+ c)
+<
+As well as
+>
+ foo(
+ a,
+ b,
+ c)
+<
+and finally
+>
+ foo(
+ a,
+ b,
+ c
+ )
+<
+To specify the delimiters to use `open_delimiter` and `close_delimiter`
+should be used. Eg.
+>
+ ((argument_list) @aligned_indent
+ (#set! "open_delimiter" "(")
+ (#set! "close_delimiter" ")"))
+<
+
+For some languages the last line of an `aligned_indent` block must not be
+the same indent as the natural next line.
+
+For example in python:
+
+>
+ if (a > b and
+ c < d):
+ pass
+
+Is not correct, whereas
+>
+ if (a > b and
+ c < d):
+ pass
+
+Would be correctly indented. This behavior may be chosen using
+`avoid_last_matching_next`. Eg.
+
+>
+ (if_statement
+ condition: (parenthesized_expression) @aligned_indent
+ (#set! "open_delimiter" "(")
+ (#set! "close_delimiter" ")")
+ (#set! "avoid_last_matching_next" 1)
+ )
+<
+Could be used to specify that the last line of an `@aligned_indent` capture
+should be additionally indented to avoid clashing with the indent of the first
+line of the block inside an if.
+
==============================================================================
COMMANDS *nvim-treesitter-commands*