From 35abce1ce13dede74265b868a0ab3254534614d6 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 6 Mar 2021 23:48:18 +0100 Subject: [PATCH 1/5] Add run-local option to download and test a plugin --- dev-utils/run-local | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dev-utils/run-local b/dev-utils/run-local index e0d6a059..c26b94bb 100755 --- a/dev-utils/run-local +++ b/dev-utils/run-local @@ -13,6 +13,10 @@ while [[ "$#" -gt 0 ]]; do -keep) option_copy=off ;; + -plugin=*) + # should be like -plugin=franko/lite-plugins/master/plugins/autowrap.lua + plugins+=("${1#-plugin=}") + ;; -global) option_global=on ;; @@ -81,8 +85,22 @@ run_lite () { fi } +fetch_plugins () { + for name in "$@"; do + local url="$(github_raw_content "$name")" + local modname="${url##*/}" + if [ "$modname" == init.lua ]; then + local m1="${name#*/}" + modname="${m1%%/*}.lua" + fi + echo "installed $name as $modname from $url" + curl --insecure -L "$url" -o "$datadir/plugins/${modname}" + done +} + if [ $option_copy == on ]; then build_lite copy_lite_build fi +fetch_plugins "${plugins[@]}" run_lite From 991db1487725fa305df2d2c1dff0eb7d97adf8c4 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 6 Mar 2021 23:36:05 +0100 Subject: [PATCH 2/5] Ensure filename are store relative to project directory --- data/core/common.lua | 28 ++++++++++++++++++++++++++++ data/plugins/treeview.lua | 3 ++- data/plugins/workspace.lua | 30 +----------------------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/data/core/common.lua b/data/core/common.lua index 763d5f00..e459476a 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -238,4 +238,32 @@ function common.normalize_path(filename) end +local function split_on_slash(s, sep_pattern) + local t = {} + for fragment in string.gmatch(s, "([^/\\]+)") do + t[#t + 1] = fragment + end + return t +end + + +function common.relative_path(ref_dir, dir) + local ref_ls = split_on_slash(ref_dir) + local dir_ls = split_on_slash(dir) + local i = 1 + while i <= #ref_ls do + if dir_ls[i] ~= ref_ls[i] then + break + end + i = i + 1 + end + local ups = "" + for k = i, #ref_ls do + ups = ups .. "../" + end + local rel_path = ups .. table.concat(dir_ls, "/", i) + return rel_path ~= "" and rel_path or "." +end + + return common diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index c9a1c74c..82b6790e 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -185,7 +185,8 @@ function TreeView:on_mouse_pressed(button, x, y, clicks) end else core.try(function() - core.root_view:open_doc(core.open_doc(self.hovered_item.abs_filename)) + local doc_filename = common.relative_path(core.project_dir, self.hovered_item.abs_filename) + core.root_view:open_doc(core.open_doc(doc_filename)) end) end end diff --git a/data/plugins/workspace.lua b/data/plugins/workspace.lua index 8712e52d..81d2207d 100644 --- a/data/plugins/workspace.lua +++ b/data/plugins/workspace.lua @@ -159,39 +159,11 @@ local function load_node(node, t) end -local function split_on_slash(s, sep_pattern) - local t = {} - for fragment in string.gmatch(s, "([^/\\]+)") do - t[#t + 1] = fragment - end - return t -end - - -local function relative_path(ref_dir, dir) - local ref_ls = split_on_slash(ref_dir) - local dir_ls = split_on_slash(dir) - local i = 1 - while i <= #ref_ls do - if dir_ls[i] ~= ref_ls[i] then - break - end - i = i + 1 - end - local ups = "" - for k = i, #ref_ls do - ups = ups .. "../" - end - local rel_path = ups .. table.concat(dir_ls, "/", i) - return rel_path ~= "" and rel_path or "." -end - - local function save_directories() local project_dir = core.project_dir local dir_list = {} for i = 2, #core.project_directories do - dir_list[#dir_list + 1] = relative_path(project_dir, core.project_directories[i].name) + dir_list[#dir_list + 1] = common.relative_path(project_dir, core.project_directories[i].name) end return dir_list end From 199476547b74724dadf3fca7488e4dbc533cdb99 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sat, 6 Mar 2021 23:05:04 +0100 Subject: [PATCH 3/5] Fix error related to panes resize along y --- data/core/rootview.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/core/rootview.lua b/data/core/rootview.lua index 4890806b..2d43f642 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -626,7 +626,7 @@ function RootView:on_mouse_moved(x, y, dx, dy) x = common.clamp(x, 0, self.root_node.size.x * 0.95) resize_child_node(node, "x", x, dx) elseif node.type == "vsplit" then - y = common.clamp(x, 0, self.root_node.size.y * 0.95) + y = common.clamp(y, 0, self.root_node.size.y * 0.95) resize_child_node(node, "y", y, dy) end node.divider = common.clamp(node.divider, 0.01, 0.99) From 23a053e1eeffd239b77d0118306726c17df85489 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 7 Mar 2021 09:48:44 +0100 Subject: [PATCH 4/5] Ensure error and stack trace are written to stdout To address https://github.com/franko/lite-xl/issues/87 --- data/core/init.lua | 2 +- src/main.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/data/core/init.lua b/data/core/init.lua index 819f26bd..0732a3e8 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -879,7 +879,7 @@ function core.on_error(err) -- write error to file local fp = io.open(USERDIR .. "/error.txt", "wb") fp:write("Error: " .. tostring(err) .. "\n") - fp:write(debug.traceback(nil, 4)) + fp:write(debug.traceback(nil, 4) .. "\n") fp:close() -- save copy of all unsaved documents for _, doc in ipairs(core.docs) do diff --git a/src/main.c b/src/main.c index 95f04840..47998e5d 100644 --- a/src/main.c +++ b/src/main.c @@ -135,7 +135,8 @@ init_lua: " core.run()\n" "end, function(err)\n" " local error_dir\n" - " print('ERROR', err)\n" + " io.stdout:write('Error: '..tostring(err)..'\\n')\n" + " io.stdout:write(debug.traceback(nil, 4)..'\\n')\n" " if core and core.on_error then\n" " error_dir=USERDIR\n" " pcall(core.on_error, err)\n" @@ -143,7 +144,7 @@ init_lua: " error_dir=system.absolute_path('.')\n" " local fp = io.open('error.txt', 'wb')\n" " fp:write('Error: ' .. tostring(err) .. '\\n')\n" - " fp:write(debug.traceback(nil, 4))\n" + " fp:write(debug.traceback(nil, 4)..'\\n')\n" " fp:close()\n" " end\n" " system.show_fatal_error('Lite XL internal error',\n" From be878a39c4ac11af30c54d01915f28d294b6486d Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Sun, 7 Mar 2021 09:49:08 +0100 Subject: [PATCH 5/5] Add missing function in script run-local --- dev-utils/run-local | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dev-utils/run-local b/dev-utils/run-local index c26b94bb..2cda7b2c 100755 --- a/dev-utils/run-local +++ b/dev-utils/run-local @@ -85,6 +85,10 @@ run_lite () { fi } +github_raw_content () { + echo "https://raw.githubusercontent.com/$1" +} + fetch_plugins () { for name in "$@"; do local url="$(github_raw_content "$name")"