diff options
author | Adam Harrison <adamdharrison@gmail.com> | 2021-07-13 10:47:39 -0400 |
---|---|---|
committer | Adam Harrison <adamdharrison@gmail.com> | 2021-08-17 09:52:24 -0400 |
commit | 466798679e7a2889622a491c776530c06668ca9f (patch) | |
tree | c0ebb8bdc0cc940f7cce465899a126f0f79a04ba | |
parent | fb647f8f0d972e85ac323b12eb65edf9c56b48cb (diff) | |
download | lite-xl-plugins-466798679e7a2889622a491c776530c06668ca9f.tar.gz lite-xl-plugins-466798679e7a2889622a491c776530c06668ca9f.zip |
Namespaced plugin configs.
-rw-r--r-- | plugins/autoinsert.lua | 10 | ||||
-rw-r--r-- | plugins/autosave.lua | 6 | ||||
-rw-r--r-- | plugins/autowrap.lua | 4 | ||||
-rw-r--r-- | plugins/bigclock.lua | 14 | ||||
-rw-r--r-- | plugins/copyfilelocation.lua | 2 | ||||
-rw-r--r-- | plugins/datetimestamps.lua | 23 | ||||
-rw-r--r-- | plugins/lfautoinsert.lua | 8 | ||||
-rw-r--r-- | plugins/minimap.lua | 56 | ||||
-rw-r--r-- | plugins/motiontrail.lua | 4 | ||||
-rw-r--r-- | plugins/openfilelocation.lua | 11 | ||||
-rw-r--r-- | plugins/scalestatus.lua | 4 | ||||
-rw-r--r-- | plugins/selectionhighlight.lua | 1 | ||||
-rw-r--r-- | plugins/spellcheck.lua | 15 |
13 files changed, 76 insertions, 82 deletions
diff --git a/plugins/autoinsert.lua b/plugins/autoinsert.lua index fd2888a..8be47c9 100644 --- a/plugins/autoinsert.lua +++ b/plugins/autoinsert.lua @@ -7,18 +7,18 @@ local command = require "core.command" local keymap = require "core.keymap" -config.autoinsert_map = { +config.plugins.autoinsert = { map = { ["["] = "]", ["{"] = "}", ["("] = ")", ['"'] = '"', ["'"] = "'", ["`"] = "`", -} +} } local function is_closer(chr) - for _, v in pairs(config.autoinsert_map) do + for _, v in pairs(config.plugins.autoinsert.map) do if v == chr then return true end @@ -37,7 +37,7 @@ end local on_text_input = DocView.on_text_input function DocView:on_text_input(text) - local mapping = config.autoinsert_map[text] + local mapping = config.plugins.autoinsert.map[text] -- prevents plugin from operating on `CommandView` if getmetatable(self) ~= DocView then @@ -89,7 +89,7 @@ command.add(predicate, { local doc = core.active_view.doc local l, c = doc:get_selection() local chr = doc:get_char(l, c) - if config.autoinsert_map[doc:get_char(l, c - 1)] and is_closer(chr) then + if config.plugins.autoinsert.map[doc:get_char(l, c - 1)] and is_closer(chr) then doc:delete_to(1) end command.perform "doc:backspace" diff --git a/plugins/autosave.lua b/plugins/autosave.lua index e64ba0d..ef1985d 100644 --- a/plugins/autosave.lua +++ b/plugins/autosave.lua @@ -10,18 +10,18 @@ local last_keypress = os.time() local looping = false local on_text_change = Doc.on_text_change -- the approximate amount of time, in seconds, that it takes to trigger an autosave -config.autosave_timeout = 1 +config.plugins.autosave = { timeout = 1 } local function loop_for_save() while looping do - if os.difftime(os.time(), last_keypress) >= config.autosave_timeout then + if os.difftime(os.time(), last_keypress) >= config.plugins.autosave.timeout then command.perform "doc:save" -- stop loop looping = false end -- wait the timeout. may cause timeout to be slightly imprescise - coroutine.yield(config.autosave_timeout) + coroutine.yield(config.plugins.autosave.timeout) end end diff --git a/plugins/autowrap.lua b/plugins/autowrap.lua index 090e338..acfd37f 100644 --- a/plugins/autowrap.lua +++ b/plugins/autowrap.lua @@ -4,7 +4,7 @@ local config = require "core.config" local command = require "core.command" local DocView = require "core.docview" -config.autowrap_files = { "%.md$", "%.txt$" } +config.plugins.autowrap = { files = { "%.md$", "%.txt$" } } local on_text_input = DocView.on_text_input @@ -15,7 +15,7 @@ DocView.on_text_input = function(self, ...) -- early-exit if the filename does not match a file type pattern local filename = self.doc.filename or "" local matched = false - for _, ptn in ipairs(config.autowrap_files) do + for _, ptn in ipairs(config.plugins.autowrap.files) do if filename:match(ptn) then matched = true break diff --git a/plugins/bigclock.lua b/plugins/bigclock.lua index c7e2eb1..62cbc0c 100644 --- a/plugins/bigclock.lua +++ b/plugins/bigclock.lua @@ -7,9 +7,11 @@ local config = require "core.config" local View = require "core.view" -config.bigclock_time_format = "%H:%M:%S" -config.bigclock_date_format = "%A, %d %B %Y" -config.bigclock_scale = 1 +config.plugins.bigclock = { + time_format = "%H:%M:%S", + date_format = "%A, %d %B %Y" + scale = 1 +} local ClockView = View:extend() @@ -28,7 +30,7 @@ end function ClockView:update_fonts() - local size = math.floor(self.size.x * 0.15 / 15) * 15 * config.bigclock_scale + local size = math.floor(self.size.x * 0.15 / 15) * 15 * config.plugins.bigclock.scale if self.font_size ~= size then self.time_font = renderer.font.load(DATADIR .. "/fonts/font.ttf", size) self.date_font = renderer.font.load(DATADIR .. "/fonts/font.ttf", size * 0.3) @@ -40,8 +42,8 @@ end function ClockView:update() - local time_text = os.date(config.bigclock_time_format) - local date_text = os.date(config.bigclock_date_format) + local time_text = os.date(config.plugins.bigclock.time_format) + local date_text = os.date(config.plugins.bigclock.date_format) if self.time_text ~= time_text or self.date_text ~= date_text then core.redraw = true self.time_text = time_text diff --git a/plugins/copyfilelocation.lua b/plugins/copyfilelocation.lua index 0f395ea..b370090 100644 --- a/plugins/copyfilelocation.lua +++ b/plugins/copyfilelocation.lua @@ -1,8 +1,6 @@ -- mod-version:1 -- lite-xl 2.00 local core = require "core" local command = require "core.command" -local config = require "core.config" - command.add("core.docview", { ["copy-file-location:copy-file-location"] = function() diff --git a/plugins/datetimestamps.lua b/plugins/datetimestamps.lua index 4d09e27..c1b1199 100644 --- a/plugins/datetimestamps.lua +++ b/plugins/datetimestamps.lua @@ -25,32 +25,25 @@ from https://www.lua.org/pil/22.1.html %y two-digit year (98) [00-99] %% the character `%ยด --]] -config.datetimestamps_format_datestamp = "%Y%m%d" -config.datetimestamps_format_datetimestamp = "%Y%m%d_%H%M%S" -config.datetimestamps_format_timestamp = "%H%M%S" +config.plugins.datetimestamps = { + format_datestamp = "%Y%m%d" + format_datetimestamp = "%Y%m%d_%H%M%S" + format_timestamp = "%H%M%S" +} local function datestamp() - - local sOut = os.date(config.datetimestamps_format_datestamp) - + local sOut = os.date(config.plugins.datetimestamps.format_datestamp) core.active_view.doc:text_input(sOut) - end local function datetimestamp() - - local sOut = os.date(config.datetimestamps_format_datetimestamp) - + local sOut = os.date(config.plugins.datetimestamps.format_datetimestamp) core.active_view.doc:text_input(sOut) - end local function timestamp() - - local sOut = os.date(config.datetimestamps_format_timestamp) - + local sOut = os.date(config.plugins.datetimestamps.format_timestamp) core.active_view.doc:text_input(sOut) - end command.add("core.docview", { diff --git a/plugins/lfautoinsert.lua b/plugins/lfautoinsert.lua index bbfb60c..3a8369e 100644 --- a/plugins/lfautoinsert.lua +++ b/plugins/lfautoinsert.lua @@ -5,7 +5,7 @@ local common = require "core.common" local config = require "core.config" local keymap = require "core.keymap" -config.lfautoinsert_map = { +config.plugins.lfautoinsert = { map = { ["{%s*\n"] = "}", ["%(%s*\n"] = ")", ["%f[[]%[%s*\n"] = "]", @@ -36,11 +36,11 @@ config.lfautoinsert_map = { ["%[%[%s*\n"] = "]]" } }, -} +} } local function get_autoinsert_map(filename) local map = {} - for pattern, closing in pairs(config.lfautoinsert_map) do + for pattern, closing in pairs(config.plugins.lfautoinsert.map) do if type(closing) == "table" then if common.match_pattern(filename, closing.file_patterns) then for p, e in pairs(closing.map) do @@ -101,7 +101,7 @@ keymap.add { return { add = function(file_patterns, map) table.insert( - config.lfautoinsert_map, + config.plugins.lfautoinsert.map, { file_patterns = file_patterns, map=map } ) end diff --git a/plugins/minimap.lua b/plugins/minimap.lua index ecae5eb..01f93c5 100644 --- a/plugins/minimap.lua +++ b/plugins/minimap.lua @@ -6,26 +6,26 @@ local style = require "core.style" local DocView = require "core.docview" -- General plugin settings -config.minimap_enabled = true -config.minimap_width = 100 -config.minimap_instant_scroll = false -config.minimap_syntax_highlight = true -config.minimap_scale = 1 - --- how many spaces one tab is equivalent to -config.minimap_tab_width = 4 - -config.minimap_draw_background = true +config.plugins.minimap = { + enabled = true, + width = 100, + instant_scroll = false, + syntax_highlight = true, + scale = 1, + -- how many spaces one tab is equivalent to + tab_width = 4, + draw_background = true +} -- Configure size for rendering each char in the minimap -local char_height = 1 * SCALE * config.minimap_scale -local char_spacing = 0.8 * SCALE * config.minimap_scale -local line_spacing = 2 * SCALE * config.minimap_scale +local char_height = 1 * SCALE * config.plugins.minimap.scale +local char_spacing = 0.8 * SCALE * config.plugins.minimap.scale +local line_spacing = 2 * SCALE * config.plugins.minimap.scale -- Overloaded since the default implementation adds a extra x3 size of hotspot for the mouse to hit the scrollbar. local prev_scrollbar_overlaps_point = DocView.scrollbar_overlaps_point DocView.scrollbar_overlaps_point = function(self, x, y) - if not config.minimap_enabled then + if not config.plugins.minimap.enabled then return prev_scrollbar_overlaps_point(self, x, y) end @@ -46,7 +46,7 @@ end -- Overloaded with an extra check if the user clicked inside the minimap to automatically scroll to that line. local prev_on_mouse_pressed = DocView.on_mouse_pressed DocView.on_mouse_pressed = function(self, button, x, y, clicks) - if not config.minimap_enabled then + if not config.plugins.minimap.enabled then return prev_on_mouse_pressed(self, button, x, y, clicks) end @@ -100,7 +100,7 @@ DocView.on_mouse_pressed = function(self, button, x, y, clicks) -- if user didn't click on the visible area (ie not dragging), scroll accordingly if not hit_visible_area then - self:scroll_to_line(jump_to_line, false, config.minimap_instant_scroll) + self:scroll_to_line(jump_to_line, false, config.plugins.minimap.instant_scroll) return end @@ -114,7 +114,7 @@ end -- since the "scrollbar" essentially represents the lines visible in the content view. local prev_on_mouse_moved = DocView.on_mouse_moved DocView.on_mouse_moved = function(self, x, y, dx, dy) - if not config.minimap_enabled then + if not config.plugins.minimap.enabled then return prev_on_mouse_moved(self, x, y, dx, dy) end @@ -143,16 +143,16 @@ end -- not juse the scrollbar. local prev_get_scrollbar_rect = DocView.get_scrollbar_rect DocView.get_scrollbar_rect = function(self) - if not config.minimap_enabled then return prev_get_scrollbar_rect(self) end + if not config.plugins.minimap.enabled then return prev_get_scrollbar_rect(self) end - return self.position.x + self.size.x - config.minimap_width * SCALE, - self.position.y, config.minimap_width * SCALE, self.size.y + return self.position.x + self.size.x - config.plugins.minimap.width * SCALE, + self.position.y, config.plugins.minimap.width * SCALE, self.size.y end -- Overloaded so we can render the minimap in the "scrollbar area". local prev_draw_scrollbar = DocView.draw_scrollbar DocView.draw_scrollbar = function(self) - if not config.minimap_enabled then return prev_draw_scrollbar(self) end + if not config.plugins.minimap.enabled then return prev_draw_scrollbar(self) end local x, y, w, h = self:get_scrollbar_rect() @@ -190,7 +190,7 @@ DocView.draw_scrollbar = function(self) line_count - max_minmap_lines)) end - if config.minimap_draw_background then + if config.plugins.minimap.draw_background then renderer.draw_rect(x, y, w, h, style.minimap_background or style.background) end -- draw visual rect @@ -206,12 +206,12 @@ DocView.draw_scrollbar = function(self) -- we try to "batch" characters so that they can be rendered as just one rectangle instead of one for each. local batch_width = 0 local batch_start = x - local minimap_cutoff_x = x + config.minimap_width * SCALE + local minimap_cutoff_x = x + config.plugins.minimap.width * SCALE local batch_syntax_type = nil local function flush_batch(type) local old_color = color color = style.syntax[batch_syntax_type] - if config.minimap_syntax_highlight and color ~= nil then + if config.plugins.minimap.syntax_highlight and color ~= nil then -- fetch and dim colors color = {color[1], color[2], color[3], color[4] * 0.5} else @@ -226,7 +226,7 @@ DocView.draw_scrollbar = function(self) end -- render lines with syntax highlighting - if config.minimap_syntax_highlight then + if config.plugins.minimap.syntax_highlight then -- keep track of the highlight type, since this needs to break batches as well batch_syntax_type = nil @@ -252,7 +252,7 @@ DocView.draw_scrollbar = function(self) batch_start = batch_start + char_spacing elseif char == " " then flush_batch(type) - batch_start = batch_start + (char_spacing * config.minimap_tab_width) + batch_start = batch_start + (char_spacing * config.plugins.minimap.tab_width) elseif batch_start + batch_width > minimap_cutoff_x then flush_batch(type) break @@ -291,9 +291,9 @@ end command.add(nil, { ["minimap:toggle-visibility"] = function() - config.minimap_enabled = not config.minimap_enabled + config.plugins.minimap.enabled = not config.plugins.minimap.enabled end, ["minimap:toggle-syntax-highlighting"] = function() - config.minimap_syntax_highlight = not config.minimap_syntax_highlight + config.plugins.minimap.syntax_highlight = not config.plugins.minimap.syntax_highlight end }) diff --git a/plugins/motiontrail.lua b/plugins/motiontrail.lua index 9bbca86..f5f3a90 100644 --- a/plugins/motiontrail.lua +++ b/plugins/motiontrail.lua @@ -4,7 +4,7 @@ local config = require "core.config" local style = require "core.style" local DocView = require "core.docview" -config.motiontrail_steps = 50 +config.plugins.motiontrail = { steps = 50 } local function lerp(a, b, t) @@ -32,7 +32,7 @@ function DocView:draw(...) if last_view == self and (x ~= last_x or y ~= last_y) then local lx = x - for i = 0, 1, 1 / config.motiontrail_steps do + for i = 0, 1, 1 / config.plugins.motiontrail.steps do local ix = lerp(x, last_x, i) local iy = lerp(y, last_y, i) local iw = math.max(w, math.ceil(math.abs(ix - lx))) diff --git a/plugins/openfilelocation.lua b/plugins/openfilelocation.lua index d6c03b1..69fe9fa 100644 --- a/plugins/openfilelocation.lua +++ b/plugins/openfilelocation.lua @@ -4,12 +4,13 @@ local command = require "core.command" local config = require "core.config" +config.plugins.openfilelocation = {} if PLATFORM == "Windows" then - config.filemanager = "explorer" + config.plugins.openfilelocation.filemanager = "explorer" elseif PLATFORM == "Mac OS X" then - config.filemanager = "open" + config.plugins.openfilelocation.filemanager = "open" else - config.filemanager = "xdg-open" + config.plugins.openfilelocation.filemanager = "xdg-open" end @@ -23,9 +24,9 @@ command.add("core.docview", { local folder = doc.filename:match("^(.*)[/\\].*$") or "." core.log("Opening \"%s\"", folder) if PLATFORM == "Windows" then - system.exec(string.format("%s %s", config.filemanager, folder)) + system.exec(string.format("%s %s", config.plugins.openfilelocation.filemanager, folder)) else - system.exec(string.format("%s %q", config.filemanager, folder)) + system.exec(string.format("%s %q", config.plugins.openfilelocation.filemanager, folder)) end end }) diff --git a/plugins/scalestatus.lua b/plugins/scalestatus.lua index c9c6d58..f486310 100644 --- a/plugins/scalestatus.lua +++ b/plugins/scalestatus.lua @@ -10,7 +10,7 @@ local scale = require "plugins.scale" local config = require "core.config" local StatusView = require "core.statusview" -config.scalestatus_format = '%.0f%%' +config.plugins.scalestatus = { format = '%.0f%%' } local get_items = StatusView.get_items function StatusView:get_items() @@ -19,7 +19,7 @@ function StatusView:get_items() local t = { self.separator, - string.format(config.scalestatus_format, scale.get() * 100), + string.format(config.plugins.scalestatus.format, scale.get() * 100), } for _, item in ipairs(t) do diff --git a/plugins/selectionhighlight.lua b/plugins/selectionhighlight.lua index a7d2aa8..9183c82 100644 --- a/plugins/selectionhighlight.lua +++ b/plugins/selectionhighlight.lua @@ -1,7 +1,6 @@ -- mod-version:1 -- lite-xl 2.00 local style = require "core.style" local DocView = require "core.docview" -local config = require "core.config" -- originally written by luveti diff --git a/plugins/spellcheck.lua b/plugins/spellcheck.lua index 3cf710e..0e5e8bf 100644 --- a/plugins/spellcheck.lua +++ b/plugins/spellcheck.lua @@ -7,11 +7,12 @@ local common = require "core.common" local DocView = require "core.docview" local Doc = require "core.doc" -config.spellcheck_files = { "%.txt$", "%.md$", "%.markdown$" } +config.plugins.spellcheck = {} +config.spellcheck.files = { "%.txt$", "%.md$", "%.markdown$" } if PLATFORM == "Windows" then - config.dictionary_file = EXEDIR .. "/words.txt" + config.plugins.spellcheck.dictionary_file = EXEDIR .. "/words.txt" else - config.dictionary_file = "/usr/share/dict/words" + config.plugins.spellcheck.dictionary_file = "/usr/share/dict/words" end @@ -22,7 +23,7 @@ local words core.add_thread(function() local t = {} local i = 0 - for line in io.lines(config.dictionary_file) do + for line in io.lines(config.plugins.spellcheck.dictionary_file) do for word in line:gmatch(word_pattern) do t[word:lower()] = true end @@ -31,7 +32,7 @@ core.add_thread(function() end words = t core.redraw = true - core.log_quiet("Finished loading dictionary file: \"%s\"", config.dictionary_file) + core.log_quiet("Finished loading dictionary file: \"%s\"", config.plugins.spellcheck.dictionary_file) end) @@ -64,7 +65,7 @@ function DocView:draw_line_text(idx, x, y) draw_line_text(self, idx, x, y) if not words - or not matches_any(self.doc.filename or "", config.spellcheck_files) then + or not matches_any(self.doc.filename or "", config.plugins.spellcheck.files) then return end @@ -120,7 +121,7 @@ command.add("core.docview", { return end if word then - local fp = assert(io.open(config.dictionary_file, "a")) + local fp = assert(io.open(config.plugins.spellcheck.dictionary_file, "a")) fp:write("\n" .. word .. "\n") fp:close() words[word] = true |