diff --git a/rc/filetype/ocaml.kak b/rc/filetype/ocaml.kak index 6be57683..ffafcfe3 100644 --- a/rc/filetype/ocaml.kak +++ b/rc/filetype/ocaml.kak @@ -18,7 +18,11 @@ hook global WinSetOption filetype=ocaml %{ hook -group ocaml-highlight global WinSetOption filetype=ocaml %{ add-highlighter window/ocaml ref ocaml - hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ocaml } + alias window alt ocaml-alternative-file + hook -once -always window WinSetOption filetype=.* %{ + unalias window alt ocaml-alternative-file + remove-highlighter window/ocaml + } } provide-module ocaml %{ @@ -74,4 +78,22 @@ evaluate-commands %sh{ " } +# Conveniences +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +# C has header and source files and you need to often switch between them. +# Similarly OCaml has .ml (implementation) and .mli (interface files) and +# one often needs to switch between them. +# +# This command provides a simple functionality that allows you to accomplish this. +define-command ocaml-alternative-file -docstring 'Switch between .ml and .mli file or vice versa' %{ + evaluate-commands %sh{ + if [ "${kak_buffile##*.}" = 'ml' ]; then + printf "edit -- '%s'" "$(printf %s "${kak_buffile}i" | sed "s/'/''/g")" + elif [ "${kak_buffile##*.}" = 'mli' ]; then + printf "edit -- '%s'" "$(printf %s "${kak_buffile%i}" | sed "s/'/''/g")" + fi + } +} + }