-
Notifications
You must be signed in to change notification settings - Fork 25
API
jbyuki edited this page Nov 26, 2020
·
7 revisions
The API of instant.nvim provides extensibility to integrate with another plugin or build a new plugin.
Its main purpose is:
- Provide notifications events
- Get current connection status
- Send/Receive custom data
local attach_id = require("instant").attach {
on_connect = function()
-- called when the connection is established with the server
end,
on_disconnect = function()
-- called when the connection is closed
end,
on_clientconnected = function(user)
-- called when a new client connects to the server
end,
on_clientdisconnected = function(user)
-- called when a client disconnects from the server
end,
on_data = function(data)
-- called when custom data is received
end,
on_change = function(user, buf, line)
-- called when text edits are made by other clients
-- user: modifying client name
-- buf: buffer number which is afftected (local)
-- line: line number which is afftected, zero-based
end,
}
require("instant").detach(attach_id)
Additionally these functions are provided to get informations about the connection status:
-- get a list of connected users (excluding self)
local connected = require("instant").get_connected_list()
-- get a list of connected buffers (local)
local bufs = require("instant").get_connected_buf_list()
-- send custom data to all clients
require("instant").send_data(data)