WinSetOption is executed in a draft context, so it doesn’t have access to client information. I’m guessing KakBegin is executed on the server, so there is no relevant client there, either.
I believe WinDisplay is the only window-related hook not executed in a draft context, so that might work. Otherwise, perhaps hook -once NormalIdle?
The event I’m trying to accomplish will happen when certain filetype changes. However if Kakoune started with this filetype I get an error that there’s no client.
@mawww maybe you also can say if I could watch for Kakoune exiting while only one specific client left, and close this client instead of forking server?
I dont quite get what you are asking for. Kakoune’s server will exit once there is not clients left, so I dont see how it could exit with one specific client left.
Well. I’ve made a plugin that acts like a side panel when run in tmux. It spawns new client, renames it and watches for other clients. When I exit main client, the terminal appears, and Kakoune is no longer opened but the server is forked for this panel like plugin. This panel is meaningless without any normal Kakoune client, so it just needs to be closed. But I can’t do this.
I’ve tried to add such hook:
hook -group tagbar-watchers global WinClose .* %{ nop %sh{
if [ "$kak_client_list" = "$kak_opt_tagbarclient" ]; then
printf "%s\n" "evaluate-commands -client $kak_opt_tagbarclient quit!" | kak -p $kak_session
fi
}}
The problem here is that WinClose is a pretty useless hook, it will only be called once we either close the buffer the window is referring to, or when we quit Kakoune. It would probably make sense to replace it with a WinHide counterpart to WinDisplay.
Additionally, in your sample hook, things would be simpler if instead of nop you’d use evaluate-commands as you would not need to pipe the command through kak -p.