From 60b6f88efecae8c549d962d5672ecb2dcfa078e4 Mon Sep 17 00:00:00 2001 From: Tyler Miller Date: Wed, 25 Sep 2024 21:05:52 -0700 Subject: [PATCH] fix: parent dirs are created for acwrite bufs --- lua/sos/commands.lua | 12 ++++++++++-- lua/sos/impl.lua | 4 +++- lua/sos/util.lua | 8 ++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lua/sos/commands.lua b/lua/sos/commands.lua index 32fb896..6faa709 100644 --- a/lua/sos/commands.lua +++ b/lua/sos/commands.lua @@ -65,8 +65,16 @@ function M.resolve_bufspec(info) local arg = info.fargs[1] -- Use `[$]` for `$`, otherwise we'll get highest bufnr. - buf = vim.fn.bufnr(arg == '$' and '[$]' or arg or '') - if buf < 1 then errmsg 'argument matched none or multiple buffers' end + if arg == '$' then + buf = vim.fn.bufnr '^[$]$' + buf = buf > 0 and buf or vim.fn.bufnr '*[$]*' + else + buf = vim.fn.bufnr(arg or '') + end + + if buf < 1 then + return errmsg 'argument matched none or multiple buffers' + end end return buf diff --git a/lua/sos/impl.lua b/lua/sos/impl.lua index 8053ad0..8d7ec68 100644 --- a/lua/sos/impl.lua +++ b/lua/sos/impl.lua @@ -111,8 +111,10 @@ function M.write_buf_if_needed(buf) return true end - local buftype = vim.bo[buf].bt + local scheme = util.uri_scheme(name) + if scheme then return write_buf(buf) end + local buftype = vim.bo[buf].bt if buftype == 'acwrite' then return write_buf(buf) elseif buftype == '' then diff --git a/lua/sos/util.lua b/lua/sos/util.lua index f62b006..45b68fa 100644 --- a/lua/sos/util.lua +++ b/lua/sos/util.lua @@ -39,4 +39,12 @@ function M.getbufs() return bufs end +---@param path string +---@return string? scheme +function M.uri_scheme(path) + -- Not very strict on purpose + local scheme, _rest = path:match '^[%s%c%z]*(%w[%-_%w+.]+):+(/*)' + return scheme +end + return M