Skip to content

Commit

Permalink
fix: parent dirs are created for acwrite bufs
Browse files Browse the repository at this point in the history
  • Loading branch information
tmillr committed Sep 26, 2024
1 parent c7aa1de commit 60b6f88
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lua/sos/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lua/sos/impl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lua/sos/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 60b6f88

Please sign in to comment.