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 9, 2021
1 parent b189497 commit 09c487b
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 @@ -19,10 +19,14 @@ local S_IF = {
local path = {}

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 @@ -274,9 +278,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 @@ -334,7 +338,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 @@ -348,6 +352,13 @@ end
function Path:close()
end

function Path:write_text(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 09c487b

Please sign in to comment.