From 436446dd9ad83b35dbcd990b3380f36b737bf05e Mon Sep 17 00:00:00 2001 From: bud Date: Mon, 15 Feb 2021 21:05:06 +0100 Subject: [PATCH 01/12] ADD: in core.step() show full path if view is a document and config.full_path_in_window_title is true --- data/core/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/init.lua b/data/core/init.lua index 60a39d89..1fbafc4a 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -725,7 +725,7 @@ function core.step() -- update window title local name = core.active_view:get_name() - local title = (name ~= "---") and (name .. " - lite") or "lite" + local title = (name ~= "---") and ( (config.full_path_in_window_title and core.active_view.doc.filename or name) .. " - lite") or "lite" if title ~= core.window_title then system.set_window_title(title) core.window_title = title From 7e3eb4a408377c606668b6a6f920f34263d56397 Mon Sep 17 00:00:00 2001 From: bud Date: Mon, 15 Feb 2021 21:06:03 +0100 Subject: [PATCH 02/12] ADD: default value (false) for full_path_in_window_title --- data/core/config.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/data/core/config.lua b/data/core/config.lua index d6f87bcd..c87d48c1 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -18,5 +18,6 @@ config.tab_type = "soft" config.line_limit = 80 config.max_symbols = 4000 config.max_project_files = 2000 +config.full_path_in_window_title = false return config From cc9aa233405cf0f3f0994398a812fb1561091fe2 Mon Sep 17 00:00:00 2001 From: bud Date: Mon, 15 Feb 2021 22:09:06 +0100 Subject: [PATCH 03/12] REMOVE: dont add reload on save hook in core:open-user-module, its automatically done in doc:save() --- data/core/commands/core.lua | 6 ------ 1 file changed, 6 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index e7bc3190..a3fd948c 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -107,12 +107,6 @@ command.add(nil, { ["core:open-user-module"] = function() local user_module_doc = core.open_doc(USERDIR .. "/init.lua") if not user_module_doc then return end - local doc_save = user_module_doc.save - user_module_doc.save = function(self) - doc_save(self) - core.reload_module("core.style") - core.load_user_directory() - end core.root_view:open_doc(user_module_doc) end, From b9fcb6e5ae6eb08908fdf6f4e765a087346c254a Mon Sep 17 00:00:00 2001 From: bud Date: Mon, 15 Feb 2021 22:09:25 +0100 Subject: [PATCH 04/12] ADD: test in doc:save(), if the file is the user module, automatically reload config --- data/core/commands/doc.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index e8eae510..d0e0ddde 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -67,6 +67,10 @@ end local function save(filename) doc():save(filename) + if doc().filename == (USERDIR .. "/init.lua") then + core.reload_module("core.style") + core.load_user_directory() + end core.log("Saved \"%s\"", doc().filename) end From dd30725d84c2d06241b4478e48946c9f41af02e7 Mon Sep 17 00:00:00 2001 From: bud Date: Mon, 15 Feb 2021 22:38:29 +0100 Subject: [PATCH 05/12] FIX: before setting full path to window title, make sure activeView is DocView --- data/core/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/core/init.lua b/data/core/init.lua index 1fbafc4a..e8a147b5 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -7,6 +7,7 @@ local keymap local RootView local StatusView local CommandView +local DocView local Doc local core = {} @@ -688,6 +689,7 @@ function core.step() local did_keymap = false local mouse_moved = false local mouse = { x = 0, y = 0, dx = 0, dy = 0 } + DocView = require "core.docview" for type, a,b,c,d in system.poll_event do if type == "mousemoved" then @@ -725,7 +727,7 @@ function core.step() -- update window title local name = core.active_view:get_name() - local title = (name ~= "---") and ( (config.full_path_in_window_title and core.active_view.doc.filename or name) .. " - lite") or "lite" + local title = (name ~= "---") and ( (config.full_path_in_window_title and core.active_view:is(DocView) and core.active_view.doc.filename or name) .. " - lite") or "lite" if title ~= core.window_title then system.set_window_title(title) core.window_title = title From 36935569589b244f3c20d84ff6a3776085090789 Mon Sep 17 00:00:00 2001 From: bud Date: Tue, 16 Feb 2021 19:12:56 +0100 Subject: [PATCH 06/12] FIX: get DocView in init instead of step, remove option for window title format' --- data/core/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index e8a147b5..d5c57fb6 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -330,6 +330,7 @@ function core.init() RootView = require "core.rootview" StatusView = require "core.statusview" CommandView = require "core.commandview" + DocView = require "core.docview" Doc = require "core.doc" do @@ -689,7 +690,7 @@ function core.step() local did_keymap = false local mouse_moved = false local mouse = { x = 0, y = 0, dx = 0, dy = 0 } - DocView = require "core.docview" + for type, a,b,c,d in system.poll_event do if type == "mousemoved" then @@ -727,7 +728,7 @@ function core.step() -- update window title local name = core.active_view:get_name() - local title = (name ~= "---") and ( (config.full_path_in_window_title and core.active_view:is(DocView) and core.active_view.doc.filename or name) .. " - lite") or "lite" + local title = (name ~= "---") and ( (core.active_view:is(DocView) and core.active_view.doc.filename or name) .. " - lite") or "lite" if title ~= core.window_title then system.set_window_title(title) core.window_title = title From 4917be3dafbc5d088e7c43d28f50a7799e707120 Mon Sep 17 00:00:00 2001 From: bud Date: Tue, 16 Feb 2021 19:13:41 +0100 Subject: [PATCH 07/12] remove config for window title format --- data/core/config.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/data/core/config.lua b/data/core/config.lua index c87d48c1..d6f87bcd 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -18,6 +18,5 @@ config.tab_type = "soft" config.line_limit = 80 config.max_symbols = 4000 config.max_project_files = 2000 -config.full_path_in_window_title = false return config From 63b024cb815ec18855dbc2f852a8a04c6705acc9 Mon Sep 17 00:00:00 2001 From: bud Date: Tue, 16 Feb 2021 19:25:40 +0100 Subject: [PATCH 08/12] FIX: Use PATHSEP instead of hardcoded "/" path separator --- data/core/commands/doc.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index d0e0ddde..3d1cd7b5 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 .. "/init.lua") then + if doc().filename == (USERDIR .. PATHSEP .. "init.lua") then core.reload_module("core.style") core.load_user_directory() end From 6369a7f7609fa545860f05c7d3176ff860ae94c5 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Tue, 16 Feb 2021 22:52:55 +0100 Subject: [PATCH 09/12] Use tilde expansion when running save-as command --- data/core/commands/core.lua | 14 +++----------- data/core/commands/doc.lua | 6 ++++-- data/core/common.lua | 9 +++++++++ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index a3fd948c..725d3b02 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -7,17 +7,9 @@ local LogView = require "core.logview" local fullscreen = false -local function home_encode_list(paths) - local t = {} - for i = 1, #paths do - t[i] = common.home_encode(paths[i]) - end - return t -end - local function suggest_directory(text) text = common.home_expand(text) - return home_encode_list(text == "" and core.recent_projects or common.dir_path_suggest(text)) + return common.home_encode_list(text == "" and core.recent_projects or common.dir_path_suggest(text)) end command.add(nil, { @@ -95,7 +87,7 @@ command.add(nil, { core.command_view:enter("Open File", function(text) core.root_view:open_doc(core.open_doc(common.home_expand(text))) end, function (text) - return home_encode_list(common.path_suggest(common.home_expand(text))) + return common.home_encode_list(common.path_suggest(common.home_expand(text))) end) end, @@ -178,7 +170,7 @@ command.add(nil, { end end, function(text) text = common.home_expand(text) - return home_encode_list(common.dir_list_suggest(text, dir_list)) + return common.home_encode_list(common.dir_list_suggest(text, dir_list)) end) end, }) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 3d1cd7b5..ad590f19 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -301,8 +301,10 @@ local commands = { core.command_view:set_text(doc().filename) end core.command_view:enter("Save As", function(filename) - save(filename) - end, common.path_suggest) + save(common.home_expand(filename)) + end, function (text) + return common.home_encode_list(common.path_suggest(common.home_expand(text))) + end) end, ["doc:save"] = function() diff --git a/data/core/common.lua b/data/core/common.lua index 6918a2b5..452f4a67 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -214,6 +214,15 @@ function common.home_encode(text) end +function common.home_encode_list(paths) + local t = {} + for i = 1, #paths do + t[i] = common.home_encode(paths[i]) + end + return t +end + + function common.home_expand(text) return HOME and text:gsub("^~", HOME) or text end From 588755b15a95dd39080ec95079e0a84398eb04e9 Mon Sep 17 00:00:00 2001 From: francesco-st <68635116+francesco-st@users.noreply.github.com> Date: Wed, 17 Feb 2021 18:42:38 +0100 Subject: [PATCH 10/12] Use -static-libgcc only if the compiler is gcc clang does not accept the -static-libgcc flag and apparently -static-libstdc++ is accepted but has no effect. --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 70c5247f..edd6a730 100644 --- a/meson.build +++ b/meson.build @@ -28,7 +28,7 @@ foreach data_module : ['core', 'fonts', 'plugins', 'colors'] endforeach lite_link_args = [] -if get_option('buildtype') == 'release' +if cc.get_id() == 'gcc' and get_option('buildtype') == 'release' lite_link_args += ['-static-libgcc', '-static-libstdc++'] endif From 1ce1c114ba4a2d4b43e7cd984a16efe2f655c001 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 17 Feb 2021 19:20:00 +0100 Subject: [PATCH 11/12] 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 From 9b271802672ed547092a3ffb162144c2f33597b6 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Wed, 17 Feb 2021 20:10:39 +0100 Subject: [PATCH 12/12] Use doc on_save hooks to reload user module --- data/core/commands/doc.lua | 5 +---- data/core/init.lua | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 97e6dfe4..7ff8d529 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -67,10 +67,7 @@ end local function save(filename) doc():save(filename) - if doc().filename == common.normalize_path(USERDIR .. PATHSEP .. "init.lua") then - core.reload_module("core.style") - core.load_user_directory() - end + core.on_doc_save(filename) core.log("Saved \"%s\"", doc().filename) end diff --git a/data/core/init.lua b/data/core/init.lua index d5c57fb6..b8223472 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -457,6 +457,19 @@ do core.on_enter_project = do_nothing end + +core.doc_save_hooks = {} +function core.add_save_hook(fn) + core.doc_save_hooks[#core.doc_save_hooks + 1] = fn +end + + +function core.on_doc_save(filename) + for _, hook in ipairs(core.doc_save_hooks) do + hook(filename) + end +end + local function quit_with_function(quit_fn, force) if force then delete_temp_files() @@ -821,4 +834,13 @@ function core.on_error(err) end +core.add_save_hook(function(filename) + local doc = core.active_view.doc + if doc and doc:is(Doc) and doc.filename == common.normalize_path(USERDIR .. PATHSEP .. "init.lua") then + core.reload_module("core.style") + core.load_user_directory() + end +end) + + return core