From 1ce1c114ba4a2d4b43e7cd984a16efe2f655c001 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 17 Feb 2021 19:20:00 +0100 Subject: [PATCH] Fix reload module problem on windows --- data/core/commands/doc.lua | 2 +- data/core/common.lua | 10 ++++++++++ data/core/doc/init.lua | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index ad590f19..97e6dfe4 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -67,7 +67,7 @@ end local function save(filename) doc():save(filename) - if doc().filename == (USERDIR .. PATHSEP .. "init.lua") then + if doc().filename == common.normalize_path(USERDIR .. PATHSEP .. "init.lua") then core.reload_module("core.style") core.load_user_directory() end diff --git a/data/core/common.lua b/data/core/common.lua index 452f4a67..763d5f00 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -228,4 +228,14 @@ function common.home_expand(text) end +function common.normalize_path(filename) + if PATHSEP == '\\' then + filename = filename:gsub('[/\\]', '\\') + local drive, rem = filename:match('^([a-zA-Z])(:.*)') + return drive and drive:upper() .. rem or filename + end + return filename +end + + return common diff --git a/data/core/doc/init.lua b/data/core/doc/init.lua index 83b5fc01..096c6aa9 100644 --- a/data/core/doc/init.lua +++ b/data/core/doc/init.lua @@ -67,6 +67,7 @@ end function Doc:load(filename) local fp = assert( io.open(filename, "rb") ) + filename = common.normalize_path(filename) self:reset() self.filename = filename self.lines = {} @@ -93,7 +94,7 @@ function Doc:save(filename) fp:write(line) end fp:close() - self.filename = filename or self.filename + self.filename = common.normalize_path(filename or self.filename) self:reset_syntax() self:clean() end