Skip to content

Commit

Permalink
Path:write_lines and none jit support for path.sep
Browse files Browse the repository at this point in the history
  • Loading branch information
Conni2461 committed Feb 12, 2021
1 parent f6cc283 commit 099c5d2
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lua/plenary/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ local path = {}
path.home = vim.loop.os_homedir()

path.sep = (function()
if string.lower(jit.os) == 'linux' or string.lower(jit.os) == 'osx' then
return '/'
if jit then
if string.lower(jit.os) == 'linux' or string.lower(jit.os) == 'osx' then
return '/'
else
return '\\'
end
else
return '\\'
return package.config:sub(1, 1)
end
end)()

Expand Down Expand Up @@ -326,9 +330,9 @@ function Path:touch(opts)
Path:new(self:parents()):mkdir({ parents = true })
end

local fd = vim.loop.fs_open(self:_fs_filename(), "w", mode)
local fd = uv.fs_open(self:_fs_filename(), "w", mode)
if not fd then error('Could not create file: ' .. self:_fs_filename()) end
vim.loop.fs_close(fd)
uv.fs_close(fd)

return true
end
Expand Down Expand Up @@ -386,7 +390,7 @@ function Path:parents()
end

function Path:is_file()
local stat = vim.loop.fs_stat(self:expand())
local stat = uv.fs_stat(self:expand())
if stat then
return stat.type == "file" and true or nil
end
Expand All @@ -400,6 +404,13 @@ end
function Path:close()
end

function Path:write(txt, mode)
assert(mode, [[Path:write_text requires a mode! For example: 'w' or 'a']])
local fd = assert(uv.fs_open(self:expand(), mode, 438))
assert(uv.fs_write(fd, txt, -1))
assert(uv.fs_close(fd))
end

-- TODO: Asyncify this and use vim.wait in the meantime.
-- This will allow other events to happen while we're waiting!
function Path:_read()
Expand Down

0 comments on commit 099c5d2

Please sign in to comment.