How to get client name after startup?


#1

Both

hook global WinSetOption filetype=.* %{
    echo -debug "client: %val{client}"
}

And

hook global KakBegin .* %{
    echo -debug "client: %val{client}"
}

print client: in *debug* buffer.

Is there a proper way to obtain client right on startup?


#2

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?


#3

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.


#4

WinDisplay is likely the first hook to run in the client context, so I would expect a “once” hook on WinDisplay to work.


#5

@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?


#6

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.


#7

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
}}

But no luck.


#8

I mean it works if I delete some window though, but not when I exit the client with :q.


#9

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.


#10

it’s left after I’ve tried to put it to background and use the normalIdle hook