hephaestus/heph.nvim/plugin/heph.lua

55 lines
1.5 KiB
Lua
Raw Normal View History

--- heph.nvim plugin entry: register the `heph://` buffer autocmds and the
--- `:Heph` command. Loaded once by Neovim from `runtimepath/plugin/`.
if vim.g.loaded_heph then
return
end
vim.g.loaded_heph = true
local grp = vim.api.nvim_create_augroup("heph", { clear = true })
-- `heph://node/<id>` buffers load and save through the daemon (tech-spec §8).
vim.api.nvim_create_autocmd("BufReadCmd", {
group = grp,
pattern = "heph://node/*",
callback = function(ev)
local ok, err = pcall(require("heph.node").read, ev.buf, ev.match)
if not ok then
vim.notify(tostring(err), vim.log.levels.ERROR)
end
end,
})
vim.api.nvim_create_autocmd("BufWriteCmd", {
group = grp,
pattern = "heph://node/*",
callback = function(ev)
local ok, err = pcall(require("heph.node").write, ev.buf, ev.match)
if not ok then
vim.notify(tostring(err), vim.log.levels.ERROR)
end
end,
})
-- Release the socket and stop any daemon this nvim spawned, cleanly, on exit.
vim.api.nvim_create_autocmd("VimLeavePre", {
group = grp,
callback = function()
pcall(function()
require("heph.rpc").close()
end)
pcall(function()
require("heph.daemon").stop_spawned()
end)
end,
})
vim.api.nvim_create_user_command("Heph", function(opts)
require("heph.command").run(opts)
end, {
nargs = "*",
desc = "hephaestus",
complete = function(arglead, cmdline, cursorpos)
return require("heph.command").complete(arglead, cmdline, cursorpos)
end,
})