feat: allow attaching to local buffers

This commit is contained in:
əlemi 2023-12-30 06:35:19 +01:00
parent 78adebd82e
commit e926bdf7a3

View file

@ -205,6 +205,7 @@ vim.api.nvim_create_user_command(
if args.bang then if args.bang then
local buf = vim.api.nvim_get_current_buf() local buf = vim.api.nvim_get_current_buf()
content = buffer_get_content(buf) content = buffer_get_content(buf)
-- TODO send content!
end end
codemp.create(args.args, content) codemp.create(args.args, content)
@ -216,11 +217,17 @@ vim.api.nvim_create_user_command(
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(
"Attach", "Attach",
function (args) function (args)
local buffer = vim.api.nvim_create_buf(true, true) local buffer = nil
vim.api.nvim_buf_set_option(buffer, 'fileformat', 'unix') if args.bang then
vim.api.nvim_buf_set_option(buffer, 'filetype', 'codemp') buffer = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_set_name(buffer, "codemp::" .. args.args) buffer_set_content(buffer, "")
vim.api.nvim_set_current_buf(buffer) else
buffer = vim.api.nvim_create_buf(true, true)
vim.api.nvim_buf_set_option(buffer, 'fileformat', 'unix')
vim.api.nvim_buf_set_option(buffer, 'filetype', 'codemp')
vim.api.nvim_buf_set_name(buffer, "codemp::" .. args.args)
vim.api.nvim_set_current_buf(buffer)
end
local controller = codemp.attach(args.args) local controller = codemp.attach(args.args)
-- TODO map name to uuid -- TODO map name to uuid
@ -262,7 +269,7 @@ vim.api.nvim_create_user_command(
print(" ++ attached to buffer " .. args.args) print(" ++ attached to buffer " .. args.args)
end, end,
{ nargs = 1 } { nargs = 1, bang = true }
) )
vim.api.nvim_create_user_command( vim.api.nvim_create_user_command(