generated from eblume/project-template
52 lines
1.3 KiB
Lua
52 lines
1.3 KiB
Lua
|
|
--- 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://*",
|
||
|
|
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://*",
|
||
|
|
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 cleanly on exit.
|
||
|
|
vim.api.nvim_create_autocmd("VimLeavePre", {
|
||
|
|
group = grp,
|
||
|
|
callback = function()
|
||
|
|
pcall(function()
|
||
|
|
require("heph.rpc").close()
|
||
|
|
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,
|
||
|
|
})
|