Inserting closing character does not skip over whitespace
lePerdu opened this issue · comments
Zach Peltzer commented
It would be nice if inserting the closing character of a pair would skip over whitespace (including new lines) if the character is already in place. Example:
Buffer:
void main() {
return 0;|
}
Input: }
Result:
void main() {
return 0;
}|
I tried to implement this like so:
define-command -hidden -params 2 auto-pairs-insert-closer %{ try %{
execute-keys -draft "hf%arg(2)<a-k>\Q%arg(2)\E\s*\Q%arg(2)<ret>"
execute-keys -with-hooks "<backspace><esc>hf%arg(2)a"
}}
but it results in a bunch of extra selection and doesn't work twice in a row (without leaving insert mode) because hooks aren't executed recursively.
Is there a better way to accomplish this with Kakoune's awkward scripting?