Only remove trailing whitespaces on InsertEnd when last insert was auto indent
Fixes #242
This commit is contained in:
parent
5f3a477277
commit
8d7ddfdf8b
|
@ -14,8 +14,10 @@ hook global BufSetOption mimetype=text/x-objc %{
|
||||||
set buffer filetype objc
|
set buffer filetype objc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
decl -hidden bool _c_family_last_change_was_indent false
|
||||||
|
|
||||||
def -hidden _c-family-indent-on-new-line %~
|
def -hidden _c-family-indent-on-new-line %~
|
||||||
eval -draft -itersel %_
|
eval -draft -itersel %=
|
||||||
# preserve previous line indent
|
# preserve previous line indent
|
||||||
try %{ exec -draft \;K<a-&> }
|
try %{ exec -draft \;K<a-&> }
|
||||||
# indent after lines ending with { or (
|
# indent after lines ending with { or (
|
||||||
|
@ -32,7 +34,8 @@ def -hidden _c-family-indent-on-new-line %~
|
||||||
try %[ exec -draft k<a-x> <a-k> ^\h*(public|private|protected):\h*$ <ret> j<a-gt> ]
|
try %[ exec -draft k<a-x> <a-k> ^\h*(public|private|protected):\h*$ <ret> j<a-gt> ]
|
||||||
# indent after if|else|while|for
|
# indent after if|else|while|for
|
||||||
try %[ exec -draft \;<a-F>)MB <a-k> \`(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\' <ret> s \`|.\' <ret> 1<a-&>1<a-space><a-gt> ]
|
try %[ exec -draft \;<a-F>)MB <a-k> \`(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\' <ret> s \`|.\' <ret> 1<a-&>1<a-space><a-gt> ]
|
||||||
_
|
set buffer _c_family_last_change_was_indent true
|
||||||
|
=
|
||||||
~
|
~
|
||||||
|
|
||||||
def -hidden _c-family-indent-on-opening-curly-brace %[
|
def -hidden _c-family-indent-on-opening-curly-brace %[
|
||||||
|
@ -86,8 +89,15 @@ addhl -group /objc/code regex "@(property|synthesize|interface|implementation|pr
|
||||||
addhl -group /objc/code regex "\<(IBAction|IBOutlet)\>" 0:attribute
|
addhl -group /objc/code regex "\<(IBAction|IBOutlet)\>" 0:attribute
|
||||||
|
|
||||||
hook global WinSetOption filetype=(cpp|objc) %[
|
hook global WinSetOption filetype=(cpp|objc) %[
|
||||||
|
hook window BufInsert .* -group c-family-hooks %{ set buffer _c_family_last_change_was_indent false }
|
||||||
|
hook window BufErase .* -group c-family-hooks %{ set buffer _c_family_last_change_was_indent false }
|
||||||
|
|
||||||
# cleanup trailing whitespaces when exiting insert mode
|
# cleanup trailing whitespaces when exiting insert mode
|
||||||
hook window InsertEnd .* -group c-family-hooks %{ try %{ exec -draft <a-x>s\h+$<ret>d } }
|
hook window InsertEnd .* -group c-family-hooks %{ %sh{
|
||||||
|
if [ $kak_opt__c_family_last_change_was_indent = "true" ]; then
|
||||||
|
echo 'try %{ exec -draft <a-x>s\h+$<ret>d }'
|
||||||
|
fi
|
||||||
|
} }
|
||||||
|
|
||||||
hook window InsertChar \n -group c-family-indent _c-family-indent-on-new-line
|
hook window InsertChar \n -group c-family-indent _c-family-indent-on-new-line
|
||||||
hook window InsertChar \{ -group c-family-indent _c-family-indent-on-opening-curly-brace
|
hook window InsertChar \{ -group c-family-indent _c-family-indent-on-opening-curly-brace
|
||||||
|
|
Loading…
Reference in New Issue
Block a user