From efd2f19f863603f442cdacb22dadb1b54f9404e2 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Mon, 5 Jul 2021 12:56:06 +0200 Subject: [PATCH] load user config from user config directory load user config and plugins from $HOME/.config/lite overriding the default configuration, before there was no way of changing configuration per-user --- TODO | 3 ++- data/core/docview.lua | 12 +++++++----- data/core/init.lua | 19 +++++++++++++++++-- data/user/colors/fall.lua | 28 ---------------------------- data/user/colors/gruvbox_dark.lua | 28 ---------------------------- data/user/colors/summer.lua | 28 ---------------------------- data/user/init.lua | 14 -------------- makefile | 1 + src/main.c | 4 ++++ 9 files changed, 31 insertions(+), 106 deletions(-) delete mode 100644 data/user/colors/fall.lua delete mode 100644 data/user/colors/gruvbox_dark.lua delete mode 100644 data/user/colors/summer.lua delete mode 100644 data/user/init.lua diff --git a/TODO b/TODO index cf99a15..fcbe587 100644 --- a/TODO +++ b/TODO @@ -13,7 +13,8 @@ [ ] that command can be what is selected [ ] add a cross to close tab [ ] prevent overscrolling on treeview -[ ] user config file and/or init.lua +[x] user config file and/or init.lua +[ ] change tmp directory to somewhere in /tmp [ ] save session and restore on reopening [ ] optimize dir tree taking too long to load on big folders [ ] go in background when launching from terminal diff --git a/data/core/docview.lua b/data/core/docview.lua index 58a1586..074d3a9 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -305,10 +305,6 @@ end function DocView:draw_line_body(idx, x, y) local line, col = self.doc:get_selection() - local sw = self:get_font():get_width(" ") - local w = math.ceil(1 * SCALE) - local lh = self:get_line_height() - local color = style.guide or style.selection -- draw selection if it overlaps this line local line1, col1, line2, col2 = self.doc:get_selection(true) @@ -329,7 +325,13 @@ function DocView:draw_line_body(idx, x, y) end -- draw ruler - renderer.draw_rect(x + config.line_limit * sw, y, sw, lh, color) + if config.line_limit > 0 then + local sw = self:get_font():get_width(" ") + local w = math.ceil(1 * SCALE) + local lh = self:get_line_height() + local color = style.guide or style.selection + renderer.draw_rect(x + config.line_limit * sw, y, sw, lh, color) + end -- draw line's text self:draw_line_text(idx, x, y) diff --git a/data/core/init.lua b/data/core/init.lua index 6e0aa2b..381b009 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -113,14 +113,14 @@ function core.init() core.add_thread(project_scan_thread) command.add_defaults() local got_plugin_error = not core.load_plugins() - local got_user_error = not core.try(require, "user") + core.try(require, "user") local got_project_error = not core.load_project_module() for _, filename in ipairs(files) do core.root_view:open_doc(core.open_doc(filename)) end - if got_plugin_error or got_user_error or got_project_error then + if got_plugin_error or got_project_error then command.perform("core:open-log") end end @@ -174,6 +174,7 @@ end function core.load_plugins() local no_errors = true + -- Load global plugins first local files = system.list_dir(EXEDIR .. "/data/plugins") for _, filename in ipairs(files) do local modname = "plugins." .. filename:gsub(".lua$", "") @@ -184,6 +185,20 @@ function core.load_plugins() no_errors = false end end + -- Load user plugins + local files = system.list_dir(USERDIR .. "/plugins") + if not files then + return no_errors + end + for _, filename in ipairs(files) do + local modname = "plugins." .. filename:gsub(".lua$", "") + local ok = core.try(require, modname) + if ok then + core.log_quiet("Loaded plugin %q", modname) + else + no_errors = false + end + end return no_errors end diff --git a/data/user/colors/fall.lua b/data/user/colors/fall.lua deleted file mode 100644 index 0cab762..0000000 --- a/data/user/colors/fall.lua +++ /dev/null @@ -1,28 +0,0 @@ -local style = require "core.style" -local common = require "core.common" - -style.background = { common.color "#343233" } -style.background2 = { common.color "#2c2a2b" } -style.background3 = { common.color "#2c2a2b" } -style.text = { common.color "#c4b398" } -style.caret = { common.color "#61efce" } -style.accent = { common.color "#ffd152" } -style.dim = { common.color "#615d5f" } -style.divider = { common.color "#242223" } -style.selection = { common.color "#454244" } -style.line_number = { common.color "#454244" } -style.line_number2 = { common.color "#615d5f" } -style.line_highlight = { common.color "#383637" } -style.scrollbar = { common.color "#454344" } -style.scrollbar2 = { common.color "#524F50" } - -style.syntax["normal"] = { common.color "#efdab9" } -style.syntax["symbol"] = { common.color "#efdab9" } -style.syntax["comment"] = { common.color "#615d5f" } -style.syntax["keyword"] = { common.color "#d36e2d" } -style.syntax["keyword2"] = { common.color "#ef6179" } -style.syntax["number"] = { common.color "#ffd152" } -style.syntax["literal"] = { common.color "#ffd152" } -style.syntax["string"] = { common.color "#ffd152" } -style.syntax["operator"] = { common.color "#efdab9" } -style.syntax["function"] = { common.color "#61efce" } diff --git a/data/user/colors/gruvbox_dark.lua b/data/user/colors/gruvbox_dark.lua deleted file mode 100644 index ff3e9d8..0000000 --- a/data/user/colors/gruvbox_dark.lua +++ /dev/null @@ -1,28 +0,0 @@ -local style = require "core.style" -local common = require "core.common" - -style.background = { common.color "#282828" } -style.background2 = { common.color "#1d2021" } -style.background3 = { common.color "#1d2021" } -style.text = { common.color "#928374" } -style.caret = { common.color "#fbf1c7" } -style.accent = { common.color "#ebdbb2" } -style.dim = { common.color "#928374" } -style.divider = { common.color "#1d2021" } -style.selection = { common.color "#3c3836" } -style.line_number = { common.color "#928374" } -style.line_number2 = { common.color "#ebdbb2" } -style.line_highlight = { common.color "#32302f" } -style.scrollbar = { common.color "#928374" } -style.scrollbar2 = { common.color "#fbf1c7" } - -style.syntax["normal"] = { common.color "#ebdbb2" } -style.syntax["symbol"] = { common.color "#ebdbb2" } -style.syntax["comment"] = { common.color "#928374" } -style.syntax["keyword"] = { common.color "#fb4934" } -style.syntax["keyword2"] = { common.color "#83a598" } -style.syntax["number"] = { common.color "#d3869b" } -style.syntax["literal"] = { common.color "#d3869b" } -style.syntax["string"] = { common.color "#b8bb26" } -style.syntax["operator"] = { common.color "#ebdbb2" } -style.syntax["function"] = { common.color "#8ec07c" } diff --git a/data/user/colors/summer.lua b/data/user/colors/summer.lua deleted file mode 100644 index 5e48cf7..0000000 --- a/data/user/colors/summer.lua +++ /dev/null @@ -1,28 +0,0 @@ -local style = require "core.style" -local common = require "core.common" - -style.background = { common.color "#fbfbfb" } -style.background2 = { common.color "#f2f2f2" } -style.background3 = { common.color "#f2f2f2" } -style.text = { common.color "#404040" } -style.caret = { common.color "#fc1785" } -style.accent = { common.color "#fc1785" } -style.dim = { common.color "#b0b0b0" } -style.divider = { common.color "#e8e8e8" } -style.selection = { common.color "#b7dce8" } -style.line_number = { common.color "#d0d0d0" } -style.line_number2 = { common.color "#808080" } -style.line_highlight = { common.color "#f2f2f2" } -style.scrollbar = { common.color "#e0e0e0" } -style.scrollbar2 = { common.color "#c0c0c0" } - -style.syntax["normal"] = { common.color "#181818" } -style.syntax["symbol"] = { common.color "#181818" } -style.syntax["comment"] = { common.color "#22a21f" } -style.syntax["keyword"] = { common.color "#fb6620" } -style.syntax["keyword2"] = { common.color "#fc1785" } -style.syntax["number"] = { common.color "#1586d2" } -style.syntax["literal"] = { common.color "#1586d2" } -style.syntax["string"] = { common.color "#1586d2" } -style.syntax["operator"] = { common.color "#fb6620" } -style.syntax["function"] = { common.color "#fc1785" } diff --git a/data/user/init.lua b/data/user/init.lua deleted file mode 100644 index 4f3c1d8..0000000 --- a/data/user/init.lua +++ /dev/null @@ -1,14 +0,0 @@ --- put user settings here --- this module will be loaded after everything else when the application starts - -local keymap = require "core.keymap" -local config = require "core.config" -local style = require "core.style" - --- light theme: --- require "user.colors.summer" -require "user.colors.gruvbox_dark" - --- key binding: --- keymap.add { ["ctrl+escape"] = "core:quit" } - diff --git a/makefile b/makefile index 45c98c6..a9d64c1 100644 --- a/makefile +++ b/makefile @@ -18,6 +18,7 @@ install: lite mkdir -p ${DESTDIR}${PREFIX}/share/lite cp -f lite ${DESTDIR}${PREFIX}/share/lite/lite chmod 755 ${DESTDIR}${PREFIX}/share/lite/lite + rm -rf ${DESTDIR}${PREFIX}/share/lite/data cp -rf data/. ${DESTDIR}${PREFIX}/share/lite/data mkdir -p ${DESTDIR}${PREFIX}/bin ln -sf ${DESTDIR}${PREFIX}/share/lite/lite ${DESTDIR}${PREFIX}/bin/lite diff --git a/src/main.c b/src/main.c index c4a9b45..e582238 100644 --- a/src/main.c +++ b/src/main.c @@ -95,10 +95,14 @@ int main(int argc, char **argv) "local core\n" "xpcall(function()\n" " SCALE = tonumber(os.getenv(\"LITE_SCALE\")) or SCALE\n" + " USERDIR = os.getenv(\"HOME\") .. '/.config/lite'\n" " PATHSEP = package.config:sub(1, 1)\n" " EXEDIR = EXEFILE:match(\"^(.+)[/\\\\].*$\")\n" " package.path = EXEDIR .. '/data/?.lua;' .. package.path\n" " package.path = EXEDIR .. '/data/?/init.lua;' .. package.path\n" + // load user config file + " package.path = USERDIR .. '/?.lua;' .. package.path\n" + " package.path = USERDIR .. '/?/init.lua;' .. package.path\n" " core = require('core')\n" " core.init()\n" " core.run()\n"