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