From 101425e28938e1cb8b3161ee9efaad7349dd9282 Mon Sep 17 00:00:00 2001 From: Sidharth Kshatriya Date: Thu, 4 Nov 2021 12:11:37 +0530 Subject: [PATCH] OCaml: Add a command to shift between .ml and .mli files and vice versa 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 commit provides a simple functionality that allows you to accomplish this. --- rc/filetype/ocaml.kak | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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 + } +} + }