diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 81a5b98c..95be8863 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -45,11 +45,17 @@ def -hidden c-family-indent-on-newline %< eval -draft -itersel %< try %< exec -draft k s[a-zA-Z0-9_-]+:\h*$ j > # indent after a statement not followed by an opening brace try %< exec -draft k \b(if|else|for|while)\h*\(.+?\)\h*$ j > - # align to the opening parenthesis or opening bracket (whichever is first) + # align to the opening parenthesis or opening brace (whichever is first) # on a previous line if its followed by text on the same line try %< eval -draft %< + # Go to opening parenthesis and opening brace, then select the most nested one try %< exec [bZ[B > catch %< exec [B > - exec \`[{(][^\n]+\n[^\n]*\n?\' L s\`|.\' & + # Validate selection and get first and last char + exec \`[{(](\h*\S+)+\n L s\`|.\' + # Remove eventual indent from new line + try %< exec -draft s\h+ d > + # Now align that new line with the opening parenthesis/brace + exec & > > > > diff --git a/test/indent/c-family/multiline-nested-align/cmd b/test/indent/c-family/multiline-nested-align/cmd new file mode 100644 index 00000000..aa392dbb --- /dev/null +++ b/test/indent/c-family/multiline-nested-align/cmd @@ -0,0 +1 @@ +cqiz diff --git a/test/indent/c-family/multiline-nested-align/in b/test/indent/c-family/multiline-nested-align/in new file mode 100644 index 00000000..932b01b4 --- /dev/null +++ b/test/indent/c-family/multiline-nested-align/in @@ -0,0 +1,5 @@ +foo{bar(baz, + qux),%( ) + +foo(bar{baz, + qux},%( ) diff --git a/test/indent/c-family/multiline-nested-align/out b/test/indent/c-family/multiline-nested-align/out new file mode 100644 index 00000000..d434ac2b --- /dev/null +++ b/test/indent/c-family/multiline-nested-align/out @@ -0,0 +1,7 @@ +foo{bar(baz, + qux), + qiz + +foo(bar{baz, + qux}, + qiz diff --git a/test/indent/c-family/multiline-nested-align/rc b/test/indent/c-family/multiline-nested-align/rc new file mode 100644 index 00000000..53c40654 --- /dev/null +++ b/test/indent/c-family/multiline-nested-align/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/core/c-family.kak" +set buffer filetype cpp