Preserve tabs during autoindent and alignment with '(' for c-family languages

Also add test for tab preservation during c-family autoindentation, and correct alignment of '}' with opening of block in cases of wrap between '(' and ')' in c-family languages
This commit is contained in:
Grant Moyer 2019-03-26 20:16:01 -04:00
parent 939471001c
commit 61840c8b11
5 changed files with 18 additions and 4 deletions

View File

@ -66,10 +66,10 @@ define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -i
try %< execute-keys [c [({],[)}] <ret> > try %< execute-keys [c [({],[)}] <ret> >
# Validate selection and get first and last char # Validate selection and get first and last char
execute-keys <a-k>\A[{(](\h*\S+)+\n<ret> <a-:><a-\;>L <a-S> execute-keys <a-k>\A[{(](\h*\S+)+\n<ret> <a-:><a-\;>L <a-S>
# Remove eventual indent from new line # Remove possibly incorrect indent from new line which was copied from previous line
try %< execute-keys -draft <space> <a-h> s\h+<ret> d > try %< execute-keys -draft <space> <a-h> s\h+<ret> d >
# Now align that new line with the opening parenthesis/brace # Now indent and align that new line with the opening parenthesis/brace
execute-keys & execute-keys 1<a-&> &
> > > >
> > > >
@ -80,7 +80,13 @@ define-command -hidden c-family-indent-on-opening-curly-brace %[
define-command -hidden c-family-indent-on-closing-curly-brace %[ define-command -hidden c-family-indent-on-closing-curly-brace %[
# align to opening curly brace when alone on a line # align to opening curly brace when alone on a line
try %[ execute-keys -itersel -draft <a-h><a-:><a-k>^\h+\}$<ret>hm<a-S>1<a-&> ] try %[
# in case open curly brace follows a closing paren, align indent with opening paren
execute-keys -itersel -draft <a-h><a-:><a-k>^\h+\}$<ret>hm <a-F>)M <a-k> \A\(.*\)\h\{.*\}\z <ret> <a-S>1<a-&>
] catch %[
# otherwise align with open curly brace
execute-keys -itersel -draft <a-h><a-:><a-k>^\h+\}$<ret>hm<a-S>1<a-&>
]
] ]
define-command -hidden c-family-insert-on-closing-curly-brace %[ define-command -hidden c-family-insert-on-closing-curly-brace %[

View File

@ -0,0 +1 @@
c<ret>bar<esc>

View File

@ -0,0 +1 @@
if (foo &&%( )

View File

@ -0,0 +1,2 @@
if (foo &&
bar

View File

@ -0,0 +1,4 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/c-family.kak"
set buffer indentwidth 0
set buffer filetype cpp