From 2f9b77b748be3f6e3885f2296b2f01a81fd5468e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 21 May 2017 22:31:05 +0100 Subject: [PATCH] Smarter align to opening parenthesis/brace supporting multiline --- rc/core/c-family.kak | 10 ++++++++-- test/indent/c-family/multiline-nested-align/cmd | 1 + test/indent/c-family/multiline-nested-align/in | 5 +++++ test/indent/c-family/multiline-nested-align/out | 7 +++++++ test/indent/c-family/multiline-nested-align/rc | 3 +++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 test/indent/c-family/multiline-nested-align/cmd create mode 100644 test/indent/c-family/multiline-nested-align/in create mode 100644 test/indent/c-family/multiline-nested-align/out create mode 100644 test/indent/c-family/multiline-nested-align/rc diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 81a5b98cb..95be88637 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 000000000..aa392dbb6 --- /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 000000000..932b01b44 --- /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 000000000..d434ac2b1 --- /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 000000000..53c40654e --- /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