mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 07:24:52 +01:00
feat: added share command
This commit is contained in:
parent
84afc0a864
commit
e0a5752d11
2 changed files with 24 additions and 3 deletions
|
@ -16,11 +16,10 @@ local function delete(name)
|
|||
print(" -- deleted buffer " .. name)
|
||||
end
|
||||
|
||||
local function attach(name, force)
|
||||
local function attach(name, current, content)
|
||||
local buffer = nil
|
||||
if force then
|
||||
if current then
|
||||
buffer = vim.api.nvim_get_current_buf()
|
||||
utils.buffer.set_content(buffer, "")
|
||||
else
|
||||
buffer = vim.api.nvim_create_buf(true, true)
|
||||
vim.api.nvim_set_option_value('fileformat', 'unix', { buf = buffer })
|
||||
|
@ -36,6 +35,10 @@ local function attach(name, force)
|
|||
buffer_id_map[name] = buffer
|
||||
ticks[buffer] = 0
|
||||
|
||||
if content ~= nil then
|
||||
controller:send(0, 0, content)
|
||||
end
|
||||
|
||||
-- hook serverbound callbacks
|
||||
-- TODO breaks when deleting whole lines at buffer end
|
||||
vim.api.nvim_buf_attach(buffer, false, {
|
||||
|
@ -77,6 +80,7 @@ local function attach(name, force)
|
|||
end, 20) -- wait 20ms before polling again because it overwhelms libuv?
|
||||
|
||||
print(" ++ attached to buffer " .. name)
|
||||
return controller
|
||||
end
|
||||
|
||||
local function detach(name)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
local state = require('codemp.state')
|
||||
local buffers = require('codemp.buffers')
|
||||
local workspace = require('codemp.workspace')
|
||||
local utils = require('codemp.utils')
|
||||
|
||||
local native = require('codemp.loader').load()
|
||||
|
||||
|
@ -52,6 +53,22 @@ local joined_actions = {
|
|||
buffers.create(path)
|
||||
end,
|
||||
|
||||
share = function(path)
|
||||
if path == nil then
|
||||
local cwd = vim.fn.getcwd()
|
||||
local full_path = vim.fn.expand("%:p")
|
||||
path = string.gsub(full_path, cwd .. "/", "")
|
||||
end
|
||||
if #path > 0 then
|
||||
local buf = vim.api.nvim_get_current_buf()
|
||||
buffers.create(path)
|
||||
local content = utils.buffer.get_content(buf)
|
||||
buffers.attach(path, true, content)
|
||||
else
|
||||
print(" !! empty path or open a file")
|
||||
end
|
||||
end,
|
||||
|
||||
delete = function(path)
|
||||
if path == nil then error("missing buffer name") end
|
||||
buffers.delete(path)
|
||||
|
|
Loading…
Reference in a new issue