In kakrc:
set global termcmd 'xfce4-terminal -e'
In the debug buffer:
/home/eric/.config/kak/kakrc:29:903: 'set' option not found: 'termcmd'. Use declare-option first
/usr/share/kak/kakrc:5:853: 'evaluate-commands' 100:15153: 'source' 29:903: 'set' option not found: 'termcmd'. Use declare-option first
error while parsing kakrc:
1:1: 'source' 5:853: 'evaluate-commands' 100:15153: 'source' 29:903: 'set' option not found: 'termcmd'. Use declare-option first
Kakoune changes the terminal it uses for operations like :new.
Version:
$ pacman -Qi kakoune |egrep 'Name|Version'
Name : kakoune
Version : 2019.07.01-1
require-module x11
set global termcmd "xfce4-terminal -e"
This is because termcmd is not declared right away by x11.kak, only after it has been required. In the autodetection case, that's in a KakBegin hook (so after kakrc was sourced). Some possible solutions:
Only set it within a KakBegin hook (which will run after the option declaration):
hook global KakBegin .* %{ set global termcmd 'xfce4-terminal -e' }
Pre-emptively declare termcmd. If an option is already declared, re-declaring is a no-op
declare-option str termcmd 'xfce4-terminal -e'
Or force-require the x11 module, as @lenormf pointed out.
But to be honest, I think it would make sense to move the require-module x11 part to the bottom of x11.kak so that the variable is already declared when sourcing kakrc, and it will just work.
require-module x11 is fine if you know for sure that you will never use Kakoune outside X11, say from inside tmux or the console. Otherwise, Kakoune commands like :new will be broken, since the x11 module sets things up in x11-specific ways.
A KakBegin hook is also fine if you know for sure that you will never use Kakoune outside X11. Otherwise, you'll get the same "option not found" error as currently.
The nice way to solve this problem is with a ModuleLoaded hook:
hook global ModuleLoaded x11 %{
set global termcmd 'xterm -e'
}
If you run Kakoune inside X11, the module gets loaded, your setting gets applied, everything's great. If you run Kakoune outside X11, nothing happens.
This is a general issue we have had since we switched to the module system. I am not sure what the best solution is, ModuleLoaded hooks solve the issue, but seems a bit overcomplex for just configuring our favorite terminal, an alternative solution would be to make x11.kak declare that option outside of the modular part, but that makes the module "leaky"...
Any opinion on what the guideline should be here ? This issue will happen for any module that declares options that are exposed to the users (which would likely be all non-hidden options).
OK, I've been staring at this a bit...
I think the right solution is to put the alias global commands inside the conditional in the KakBegin hook instead of the top level of the x11 module.
Here's my rationale: I think the manipulation of the global aliases at the top-level of the module violates the intent of the module loading. Hmm, hard to explain, but it isn't properly decoupled. For example, it re-adds the load order requirements that the module system is supposed to avoid. (I should be able to use both tmux-focus and x11-focus if I want, and certainly configure both facilities.)
I think the require-module x11 by itself, without commands after it, is the red flag. I think require-module should always be followed by a command that refers to the module's commands or options.
I feel like I've explained this badly. Hope it makes sense.
...an alternative solution would be to make x11.kak declare that option outside of the modular part, but that makes the module "leaky"...
The question is, how much of x11.kak do we want to hide when X11 is not available? We definitely want to hide the bits that would be completely broken (like :x11-terminal) and anything that uses those bits (like the :terminal → :x11-terminal alias). We also want to hide anything that is expensive to set up, like a complex set of highlighters or suite of hooks.
Options are neither of those things: having a termcmd option outside X11 is completely harmless, and it is not at all expensive to create, so it seems quite reasonable to declare it inside x11.kak outside the x11 module. It might even be a good thing - imagine somebody writing a Kakoune plugin in tmux with a termcmd option (for whatever reason), and it turns out their plugin breaks when run in X11 because their option conflicts with x11.kak's termcmd option. If options were always declared globally, plugin authors would be less likely to make plugins that conflict with parts of the standard library.
I think the right solution is to put the alias global commands inside the conditional in the KakBegin hook instead of the top level of the x11 module.
If I understand correctly, you want a policy of "a module should declare options and define commands, but not execute anything", so that people can say require-module x11 to talk about the contents of that module without triggering its behaviour.
That makes sense, and we should probably do that anyway, but I don't think it solves the problem in the OP. It is not at all obvious that the termcmd option comes from the x11 module without a recursive grep of the standard library. Perhaps if we established a convention of "all options must be prefixed by the module they're defined in" (in the same way that commands typically are), it would be reasonable to tell people "if you want to set x11_termcmd, you must require-module x11 first", but I don't think it's fair right now.
Most helpful comment
require-module x11is fine if you know for sure that you will never use Kakoune outside X11, say from inside tmux or the console. Otherwise, Kakoune commands like:newwill be broken, since thex11module sets things up in x11-specific ways.A
KakBeginhook is also fine if you know for sure that you will never use Kakoune outside X11. Otherwise, you'll get the same "option not found" error as currently.The nice way to solve this problem is with a
ModuleLoadedhook:If you run Kakoune inside X11, the module gets loaded, your setting gets applied, everything's great. If you run Kakoune outside X11, nothing happens.