Merge remote-tracking branch 'deviant/add-go-alternative-file' into master

This commit is contained in:
Maxime Coste 2020-09-17 19:38:59 +10:00
commit b8f56a65ed

View File

@ -23,7 +23,12 @@ hook global WinSetOption filetype=go %{
hook window InsertChar \} -group go-indent go-indent-on-closing-curly-brace hook window InsertChar \} -group go-indent go-indent-on-closing-curly-brace
hook window InsertChar \n -group go-insert go-insert-on-new-line hook window InsertChar \n -group go-insert go-insert-on-new-line
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window go-.+ } alias window alt go-alternative-file
hook -once -always window WinSetOption filetype=.* %{
remove-hooks window go-.+
unalias window alt go-alternative-file
}
} }
hook -group go-highlight global WinSetOption filetype=go %{ hook -group go-highlight global WinSetOption filetype=go %{
@ -75,6 +80,23 @@ evaluate-commands %sh{
# Commands # Commands
# ‾‾‾‾‾‾‾‾ # ‾‾‾‾‾‾‾‾
define-command go-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ evaluate-commands %sh{
case $kak_buffile in
*_test.go)
altfile=${kak_buffile%_test.go}.go
test ! -f "$altfile" && echo "fail 'implementation file not found'" && exit
;;
*.go)
altfile=${kak_buffile%.go}_test.go
test ! -f "$altfile" && echo "fail 'test file not found'" && exit
;;
*)
echo "fail 'alternative file not found'" && exit
;;
esac
printf "edit -- '%s'" "$(printf %s "$altfile" | sed "s/'/''/g")"
}}
define-command -hidden go-indent-on-new-line %~ define-command -hidden go-indent-on-new-line %~
evaluate-commands -draft -itersel %= evaluate-commands -draft -itersel %=
# preserve previous line indent # preserve previous line indent