indents: allow aligned_indent for unfinished calls in C and Python

This commit is contained in:
Stephan Seitz 2022-01-22 14:50:51 +01:00
parent 62982378b8
commit 059fbc487c
7 changed files with 26 additions and 3 deletions

View file

@ -122,7 +122,8 @@ function M.get_indent(lnum)
is_processed = true
end
if q.aligned_indent[node:id()] and srow ~= erow then
-- do not indent for nodes that starts-and-ends on same line and starts on target line (lnum)
if q.aligned_indent[node:id()] and srow ~= erow and (srow ~= lnum - 1) then
local metadata = q.aligned_indent[node:id()]
local opening_delimiter = metadata.delimiter:sub(1, 1)
local o_delim_node, pos = get_matching_prev_sibling(node, { srow, #vim.fn.getline(srow + 1) - 1 }, function(n)

View file

@ -7,7 +7,6 @@
(enumerator_list)
(struct_specifier)
(compound_literal_expression)
(parameter_list)
(initializer_list)
(concatenated_string)
(while_statement)
@ -44,3 +43,8 @@
] @ignore
(binary_expression) @auto
((ERROR (parameter_declaration)) @aligned_indent
(#set! "delimiter" "()"))
([(argument_list) (parameter_list)] @aligned_indent
(#set! "delimiter" "()"))

View file

@ -32,6 +32,8 @@
condition: (parenthesized_expression) @aligned_indent
(#set! "delimiter" "()")
)
((ERROR "(" . (_)) @aligned_indent
(#set! "delimiter" "()"))
((argument_list) @aligned_indent
(#set! "delimiter" "()"))
((argument_list) @aligned_indent

View file

@ -0,0 +1,10 @@
void foo(int a,
int b,
int c);
void foo(int a,
int b

View file

@ -21,7 +21,7 @@ int f4(
}
int f5(int x,
int y)
int y)
{
return 1;
}

View file

@ -0,0 +1,3 @@
int a[] = {
1, 2, 3,
4};

View file

@ -9,3 +9,6 @@ aligned_indent(1,
aligned_indent(1,
2
)
foodsadsa(sdada,
2