diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index ea4351ec..5e1c006f 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -28,26 +28,27 @@ def -hidden c-family-trim-autoindent %[ eval -draft -itersel %[ try %[ exec 1s^(\h+)$ d ] ] ] -def -hidden c-family-indent-on-newline %[ eval -draft -itersel %[ +def -hidden c-family-indent-on-newline %< eval -draft -itersel %< exec \; - try %[ + try %< # if previous line closed a paren, copy indent of the opening paren line exec -draft k 1s(\))(\h+\w+)*\h*(\;\h*)?$ mJ s\`|.\' 1 - ] catch %[ + > catch %< # else indent new lines with the same level as the previous one exec -draft K - ] + > # remove previous empty lines resulting from the automatic indent - try %[ exec -draft k ^\h+$ Hd ] + try %< exec -draft k ^\h+$ Hd > # indent after an opening brace - try %[ exec -draft k s\{\h*$ j ] + try %< exec -draft k s\{\h*$ j > # indent after a label - try %[ exec -draft k s[a-zA-Z0-9_-]+:\h*$ j ] + 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 on a previous line if its followed by text on the same line - try %[ exec -draft {b \`\([^\n]+\n[^\n]*\n?\' L s\`|.\' & ] -] ] + try %< exec -draft k \b(if|else|for|while)\h*\(.+?\)\h*$ j > + # align to the opening parenthesis or opening bracket (whichever is first) + # on a previous line if its followed by text on the same line + try %< exec -draft [b Z[B \`[{(][^\n]+\n[^\n]*\n?\' L s\`|.\' & > +> > def -hidden c-family-indent-on-opening-curly-brace %[ # align indent with opening paren when { is entered on a new line after the closing paren diff --git a/test/indent/c-family/construct-align/cmd b/test/indent/c-family/construct-align/cmd new file mode 100644 index 00000000..76003030 --- /dev/null +++ b/test/indent/c-family/construct-align/cmd @@ -0,0 +1 @@ +c diff --git a/test/indent/c-family/construct-align/in b/test/indent/c-family/construct-align/in new file mode 100644 index 00000000..ed49c653 --- /dev/null +++ b/test/indent/c-family/construct-align/in @@ -0,0 +1 @@ +MyObject obj{param1,%( )param2}; diff --git a/test/indent/c-family/construct-align/out b/test/indent/c-family/construct-align/out new file mode 100644 index 00000000..bdf7fad5 --- /dev/null +++ b/test/indent/c-family/construct-align/out @@ -0,0 +1,2 @@ +MyObject obj{param1, + param2}; diff --git a/test/indent/c-family/construct-align/rc b/test/indent/c-family/construct-align/rc new file mode 100644 index 00000000..53c40654 --- /dev/null +++ b/test/indent/c-family/construct-align/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/core/c-family.kak" +set buffer filetype cpp diff --git a/test/indent/c-family/nested-align/cmd b/test/indent/c-family/nested-align/cmd new file mode 100644 index 00000000..6e034658 --- /dev/null +++ b/test/indent/c-family/nested-align/cmd @@ -0,0 +1 @@ +cqux diff --git a/test/indent/c-family/nested-align/in b/test/indent/c-family/nested-align/in new file mode 100644 index 00000000..e368eef6 --- /dev/null +++ b/test/indent/c-family/nested-align/in @@ -0,0 +1,3 @@ +foo{bar(baz,%( ) + +foo(bar{baz,%( ) diff --git a/test/indent/c-family/nested-align/out b/test/indent/c-family/nested-align/out new file mode 100644 index 00000000..d53cc96d --- /dev/null +++ b/test/indent/c-family/nested-align/out @@ -0,0 +1,5 @@ +foo{bar(baz, + qux + +foo(bar{baz, + qux diff --git a/test/indent/c-family/nested-align/rc b/test/indent/c-family/nested-align/rc new file mode 100644 index 00000000..53c40654 --- /dev/null +++ b/test/indent/c-family/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