luar plugin by @gustavo-hms got me thinking about custom expansions idea proposed by @bugabinga
declare-expansion lua '/usr/bin/lua'
evaluate-commands %lua{ print("set-option makecmd '" .. os.getenv'kak_buffile' .. "'") }
I’d like to share some thoughts on this:
- expansion behave like functions with single parameter and single return value, therefore custom expansions could be more that simple shorthand for
%sh{!#/usr/bin/lua ...},
- currently pattern
%sh{!#/usr/bin/lua ...},
cannot be abstracted because there is no way to return anything from command. For example - in luar plugin there is:lua
command. To return anything from lua code we have to set variable in Kakoune.
Maybe custom expansion should not point directly to some executable, instead they could behave like commands with ability to return single value:
define-expansion lua %{
return %sh{ lua -e '$@' }
}
echo %lua{ print "foo" } # evaluates to echo foo