From 61840c8b1157bf5f9ae290e028dbbdd13d6be62e Mon Sep 17 00:00:00 2001 From: Grant Moyer Date: Tue, 26 Mar 2019 20:16:01 -0400 Subject: [PATCH 2/2] 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 --- rc/filetype/c-family.kak | 14 ++++++++++---- test/indent/c-family/preserve-tabs/cmd | 1 + test/indent/c-family/preserve-tabs/in | 1 + test/indent/c-family/preserve-tabs/out | 2 ++ test/indent/c-family/preserve-tabs/rc | 4 ++++ 5 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 test/indent/c-family/preserve-tabs/cmd create mode 100644 test/indent/c-family/preserve-tabs/in create mode 100644 test/indent/c-family/preserve-tabs/out create mode 100644 test/indent/c-family/preserve-tabs/rc 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 [({],[)}] > # Validate selection and get first and last char execute-keys \A[{(](\h*\S+)+\n L - # Remove eventual indent from new line + # Remove possibly incorrect indent from new line which was copied from previous line try %< execute-keys -draft s\h+ 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 & > > > > @@ -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 ^\h+\}$hm1 ] + try %[ + # in case open curly brace follows a closing paren, align indent with opening paren + execute-keys -itersel -draft ^\h+\}$hm )M \A\(.*\)\h\{.*\}\z 1 + ] catch %[ + # otherwise align with open curly brace + execute-keys -itersel -draft ^\h+\}$hm1 + ] ] 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 @@ +cbar 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