diff options
| author | John Isom <John.Isom2001@gmail.com> | 2020-08-01 11:46:35 -0600 |
|---|---|---|
| committer | John Isom <John.Isom2001@gmail.com> | 2020-08-01 11:46:35 -0600 |
| commit | dbb548af2dce84dc557e81f1d7cd1c2951071ce4 (patch) | |
| tree | 8168f19b8d93651c772c9f4c8f90888876efa93d | |
| parent | c36583524cbe7908cd95438806948c6a702eb7c4 (diff) | |
Fill in implementation of `crystal-insert-on-new-line`
| -rw-r--r-- | rc/filetype/crystal.kak | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/rc/filetype/crystal.kak b/rc/filetype/crystal.kak index 65378666..1a55ffde 100644 --- a/rc/filetype/crystal.kak +++ b/rc/filetype/crystal.kak @@ -210,12 +210,29 @@ define-command -hidden crystal-indent-on-new-line %{ } } -define-command -hidden crystal-insert-on-new-line %{ - evaluate-commands -no-hooks -draft -itersel %{ +define-command -hidden crystal-insert-on-new-line %[ + evaluate-commands -no-hooks -draft -itersel %[ # Copy comment prefix and following whitespaces try %{ execute-keys -draft k <a-x> s '^\h*\K#\h*' <ret> y j gl p } - } -} + + # Add `end` token if needs be + # The 'x' register is to save the leading whitespaces of the opening token + evaluate-commands -save-regs x %[ + # Save the leading whitespaces in register 'x' + try %{ execute-keys -draft k <a-x> s ^\h* <ret> \" x y } + try %[ + evaluate-commands -draft %[ + # Make sure previous line opens a block + execute-keys -draft k <a-x> <a-k> ^<c-r>x(?:begin|case|class|def|for|if|module|unless|until|while|.+\bdo\h\|.+(?=\|))[^0-9A-Za-z_!?] <ret> + # Make sure `end` doesn't already exist on indent level + execute-keys -draft }i J <a-x> <a-K> ^<c-r>x(?:end|else|elsif|rescue|when)[^0-9A-Za-z_!?] <ret> + ] + # Insert new line with end prepended by contents of register 'x' + execute-keys -draft o <c-r>x end <esc> + ] + ] + ] +] define-command -hidden crystal-fetch-keywords %{ set-register dquote %sh{ |
