Best solution to autoclose tools clients when all non tools exited

First time I’ve encountered this problem was when I was developing tagbar.kak. The thing is, that in Tmux, tagbar.kak behaves like a sidebar, and when main client exits, there’s no point of having tagbar open anymore. I’ve developed some hooks, that check on client close, that if the only client left is tagbar, it tries to exit himself. But if there’s unsaved changes it can’t do this. Now there’s also kaktree, which also acts as a side panel. And when main client is exited, I have both tagbar and kaktree tmux panes opened. I also like to spawn tools client for things like grep and others, and if I exit main client, I’ll have three panes left. I hope you see the problem.

I’ve thought about a list of tool related clients, but it doesn’t seem to solve anything. I’ve also thought about list of regular clients, that is managed by Kakoune, e.g. regular clients (which are not tool clients) are added to the list, and you can’t kill main kakoune client if any of those clients have unsaved states. But that’s kinda complicated.

The main problem though is that I want regular client to fail to exit in case if there are no regular clients left, but there’s plenty of tool clients, and some buffers have unsaved states.

I’ve thought about a list of tool related clients, but it doesn’t seem to solve anything. I’ve also thought about list of regular clients, that is managed by Kakoune, e.g. regular clients (which are not tool clients) are added to the list, and you can’t kill main kakoune client if any of those clients have unsaved states. But that’s kinda complicated.

Maybe Kakoune should distinguish between clients showing scratch buffers
and clients showing regular buffers. For example, if I type :q in the
only client showing a regular buffer, Kakoune should shut down all the
other clients and the server too (unless some other buffer has unsaved
changes).

A more conservative approach might be to only shut down
scratch-buffer-clients when the client containing the last regular
buffer is closed. That way, there can be no “unsaved buffers”.

that’s nice idea