nvim-rs
nvim-rs copied to clipboard
[Question] Receive all autocmd's
Hey, I'm trying to write a vim plugin for the first time, I chose to use rust for its speed. I connect the binary file to a job in the plugin .vim file and there's this process I seem to be forced into where I have to define autocmd's and send an rpcnotify() on a specific command from vim in lua. I just want to skip the whole lua thing, I don't want to go from neovim written in c++ to lua to rust, is there a way I can just subscribe to every event that happens in vim from rust after starting the binary job and filter through them myself in rust to find which ones are useful? For example something like this
fn main() {
let session = Session::new_parent().unwrap();
let mut nvim = Neovim::new(session);
let receiver = nvim.session.start_event_loop_channel();
for (event, value) in receiver.receive_all() { // every autocmd triggered in vim will be seen here
match event {
// ...
}
}
}
In NeovimApi there is a nvim.call() that sends to vim
.neovim
.call(
"nvim_win_set_cursor",
call_args![self.code_data.clone(), pos],
)
How are these commands sent by neovim in the opposite direction? I consider the opposite, where nvim sends a neovim.send("nvim_win_set_cursor") when a cursor position is changed in neovim and rust receives it, without the need for a lua interface in the middle, is this possible?
How do these events work? Are they only triggered when lua calls an rpcnotify? Or does nvim announce everything that happens?
Sorry for all the questions but I can't find much information about this
So, generally there's not facility to get sent all aucmds via rpc, you'd need to install a handler and send them to your plugin, as you mentioned. Not sure it's a good idea anyways, you're potentially looking at a lot of rpc traffic.
There are also other events that you can subscribe to, see :h api-buffer-updates (not sure how many others there are, to be honest). Getting updates on the UI state is described in :h ui-events. I'm not sure if that fits your usecase though, since you'd have to register your plugin as a UI, and I'm not exactly sure what that entails (my guess is that you don't want to do that unless you're really writing a UI).
You might wan to look at registering specific aucmds, see the scorched-earth example (https://github.com/KillTheMule/nvim-rs/blob/master/examples/scorched_earth.rs and https://docs.rs/nvim-rs/0.4.0/nvim_rs/examples/scorched_earth/index.html) for at least a subset of this.
It looks like the neovide project uses your rpc library which has become an interesting resource for ui-events, their code uses nvim as a child process, whereas I'm using nvim as a parent. I've never used tokio before so it's a bit cryptic to understand
I can't find any documentation on api-buffer-updates or the nvim_buf_attach command, unfortuantely I can't even find some minimal viable code to get it running to see what it outputs
Yeah, UIs embed neovim, contrary to "other" plugins. There would be several to look at (gnvim, neovim-gtk) if you need more ;)
You can find the API documentation at https://neovim.io/doc/user/api.html#api-buffer-updates, although that should definitely be part of your :h. Are you using a very old version of neovim?
Seems the questions have been answered... if there's anything else for nvim-rs to be done or explained, let me know :)