diff --git a/lua/codemp/buffers.lua b/lua/codemp/buffers.lua index fcb56c9..4244e1e 100644 --- a/lua/codemp/buffers.lua +++ b/lua/codemp/buffers.lua @@ -10,7 +10,7 @@ local user_buffer_name = {} local ticks = {} ---@param name string name of buffer to attach to ----@param buffer? integer if provided, use given buffer (will clear content) +---@param buffer integer buffer to use for attaching (will clear content) ---@param content? string if provided, set this content after attaching ---@param nowait? boolean skip waiting for initial content sync ---@return BufferController @@ -18,10 +18,6 @@ local function attach(name, buffer, content, nowait) if buffer_id_map[name] ~= nil then error("already attached to buffer " .. name) end - if buffer == nil then - buffer = vim.api.nvim_create_buf(true, false) - vim.api.nvim_set_current_buf(buffer) - end vim.api.nvim_set_option_value('fileformat', 'unix', { buf = buffer }) vim.api.nvim_buf_set_name(buffer, name) local controller = session.workspace:attach_buffer(name):await() diff --git a/lua/codemp/command.lua b/lua/codemp/command.lua index fe469ba..45d1819 100644 --- a/lua/codemp/command.lua +++ b/lua/codemp/command.lua @@ -110,7 +110,12 @@ local joined_actions = { attach = function(path, bang) if path == nil then error("missing buffer name") end local buffer = nil - if bang then buffer = vim.api.nvim_get_current_buf() end + if bang then + buffer = vim.api.nvim_get_current_buf() + else + buffer = vim.api.nvim_create_buf(true, false) + vim.api.nvim_set_current_buf(buffer) + end buffers.attach(path, buffer) end, diff --git a/lua/codemp/neo-tree/commands.lua b/lua/codemp/neo-tree/commands.lua index e207648..0023d50 100644 --- a/lua/codemp/neo-tree/commands.lua +++ b/lua/codemp/neo-tree/commands.lua @@ -44,8 +44,9 @@ M.open = function(state, path, extra) end if selected.type == "buffer" then local window = utils.get_appropriate_window(state) - local buf = vim.api.nvim_win_get_buf(window) + local buf = vim.api.nvim_create_buf(true, false) vim.api.nvim_set_current_win(window) + vim.api.nvim_win_set_buf(window, buf) buf_manager.attach(selected.name, buf) return end @@ -56,6 +57,17 @@ M.open = function(state, path, extra) error("unrecognized node type") end +M.move = function(state, path, extra) + local selected = state.tree:get_node() + if selected.type == "buffer" then + local window = utils.get_appropriate_window(state) + local buf = vim.api.nvim_win_get_buf(window) + buf_manager.attach(selected.name, buf) + return + end + error("only buffers can be moved to current file") +end + M.add = function(_state) if session.client == nil then vim.ui.input({ prompt = "server address" }, function(input)