From c6b7e3d74ac1c7b0a5b6136a5dbcbb8c84249e7b Mon Sep 17 00:00:00 2001 From: V Date: Sun, 6 Sep 2020 14:15:53 +0200 Subject: [PATCH 2/2] Add :alt command for go files --- rc/filetype/go.kak | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/rc/filetype/go.kak b/rc/filetype/go.kak index 5d077991..c62d45e1 100644 --- a/rc/filetype/go.kak +++ b/rc/filetype/go.kak @@ -22,7 +22,12 @@ hook global WinSetOption filetype=go %{ hook window InsertChar \{ -group go-indent go-indent-on-opening-curly-brace hook window InsertChar \} -group go-indent go-indent-on-closing-curly-brace - 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 %{ @@ -73,6 +78,23 @@ evaluate-commands %sh{ # 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 %~ evaluate-commands -draft -itersel %= # preserve previous line indent