I’m integrating some long running asynchronous processes (think ci, linters, style checkers, etc…) and I’ve set them up to send eval -client commands to create highlighters as issues are found. It works as long as I don’t switch buffers between the start and result of the external process, otherwise the highlighter gets applied to the wrong window/buffer. As a minimal example based on Kakoune’s interfacing document, run this in one buffer then switch to another buffer before the sleep expires.
As always seems to be the case, I stumbled on to a solution after finally pulling the trigger on a post. Using execute-keys -draft with a :buffer seems to do the trick.
There’s also eval -buffer $kak_bufname which lets you execute KakScript in the context of an open buffer, whether or not it’s visible in any particular client.