diff options
| author | Grant Moyer <grantmoyer@gmail.com> | 2019-03-26 20:16:01 -0400 |
|---|---|---|
| committer | Grant Moyer <grantmoyer@gmail.com> | 2019-03-28 13:08:02 -0400 |
| commit | 61840c8b1157bf5f9ae290e028dbbdd13d6be62e (patch) | |
| tree | 5711a6c0a5ee170b02387653c1da1eee39427371 | |
| parent | 939471001cad897aaefad818fcf9ff34f6c26662 (diff) | |
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
| -rw-r--r-- | rc/filetype/c-family.kak | 14 | ||||
| -rw-r--r-- | test/indent/c-family/preserve-tabs/cmd | 1 | ||||
| -rw-r--r-- | test/indent/c-family/preserve-tabs/in | 1 | ||||
| -rw-r--r-- | test/indent/c-family/preserve-tabs/out | 2 | ||||
| -rw-r--r-- | test/indent/c-family/preserve-tabs/rc | 4 |
5 files changed, 18 insertions, 4 deletions
diff --git a/rc/filetype/c-family.kak b/rc/filetype/c-family.kak index 461545fb..aad3ed65 100644 --- a/rc/filetype/c-family.kak +++ b/rc/filetype/c-family.kak @@ -66,10 +66,10 @@ define-command -hidden c-family-indent-on-newline %< evaluate-commands -draft -i try %< execute-keys [c [({],[)}] <ret> > # Validate selection and get first and last char 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 > - # Now align that new line with the opening parenthesis/brace - execute-keys & + # Now indent and align that new line with the opening parenthesis/brace + 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 %[ # 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 %[ diff --git a/test/indent/c-family/preserve-tabs/cmd b/test/indent/c-family/preserve-tabs/cmd new file mode 100644 index 00000000..8682d51e --- /dev/null +++ b/test/indent/c-family/preserve-tabs/cmd @@ -0,0 +1 @@ +c<ret>bar<esc> diff --git a/test/indent/c-family/preserve-tabs/in b/test/indent/c-family/preserve-tabs/in new file mode 100644 index 00000000..5ae47bf1 --- /dev/null +++ b/test/indent/c-family/preserve-tabs/in @@ -0,0 +1 @@ + if (foo &&%( ) diff --git a/test/indent/c-family/preserve-tabs/out b/test/indent/c-family/preserve-tabs/out new file mode 100644 index 00000000..dc32be1e --- /dev/null +++ b/test/indent/c-family/preserve-tabs/out @@ -0,0 +1,2 @@ + if (foo && + bar diff --git a/test/indent/c-family/preserve-tabs/rc b/test/indent/c-family/preserve-tabs/rc new file mode 100644 index 00000000..a514cdd8 --- /dev/null +++ b/test/indent/c-family/preserve-tabs/rc @@ -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 |
