1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-10-06 09:37:26 +03:00

Fill in implementation of crystal-insert-on-new-line

This commit is contained in:
John Isom 2020-08-01 11:46:35 -06:00
parent c36583524c
commit dbb548af2d

View File

@ -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{