fix: if not given, default to current buffer

This commit is contained in:
əlemi 2024-09-15 12:39:50 +02:00
parent 07344401dc
commit 637a6ee11d
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -10,7 +10,7 @@ local user_buffer_name = {}
local ticks = {}
---@param name string name of buffer to attach to
---@param buffer integer buffer to use for attaching (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,6 +18,11 @@ 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_get_current_buf()
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()