From d13315ecb978327e8e1f1ab3bd28ed7be153cd86 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sun, 5 Dec 2021 18:32:20 -0500 Subject: [PATCH] Added in new merge method, and run it on plugins. Also made it so plugin configs can be set anywhere, even if we don't know the plugin beforehand. --- data/core/common.lua | 8 ++++++++ data/core/config.lua | 10 ++++++++-- data/plugins/autocomplete.lua | 4 ++-- data/plugins/scale.lua | 4 ++-- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/data/core/common.lua b/data/core/common.lua index ab21b758..3896b55e 100644 --- a/data/core/common.lua +++ b/data/core/common.lua @@ -17,6 +17,14 @@ function common.clamp(n, lo, hi) end +function common.merge(a, b) + local t = {} + for k, v in pairs(a) do t[k] = v end + if b then for k, v in pairs(b) do t[k] = v end end + return t +end + + function common.round(n) return n >= 0 and math.floor(n + 0.5) or math.ceil(n - 0.5) end diff --git a/data/core/config.lua b/data/core/config.lua index 71e83994..cf12bf51 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -29,10 +29,16 @@ config.borderless = false config.tab_close_button = true config.max_clicks = 3 --- Disable plugin loading setting to false the config entry --- of the same name. config.plugins = {} +-- Allow you to set plugin configs even if we haven't seen the plugin before. +setmetatable(config.plugins, { + __index = function(t, k) + if rawget(t, k) == nil then rawset(t, k, {}) end + return rawget(t, k) + end +}) +-- Disable these plugins by default. config.plugins.trimwhitespace = false config.plugins.lineguide = false config.plugins.drawwhitespace = false diff --git a/data/plugins/autocomplete.lua b/data/plugins/autocomplete.lua index fde9487e..4686fdf3 100644 --- a/data/plugins/autocomplete.lua +++ b/data/plugins/autocomplete.lua @@ -10,14 +10,14 @@ local RootView = require "core.rootview" local DocView = require "core.docview" local Doc = require "core.doc" -config.plugins.autocomplete = { +config.plugins.autocomplete = common.merge({ -- Amount of characters that need to be written for autocomplete min_len = 3, -- The max amount of visible items max_height = 6, -- The max amount of scrollable items max_suggestions = 100, -} +}, config.plugins.autocomplete) local autocomplete = {} diff --git a/data/plugins/scale.lua b/data/plugins/scale.lua index 616ee40b..f36b1ff3 100644 --- a/data/plugins/scale.lua +++ b/data/plugins/scale.lua @@ -8,10 +8,10 @@ local style = require "core.style" local RootView = require "core.rootview" local CommandView = require "core.commandview" -config.plugins.scale = { +config.plugins.scale = common.merge({ mode = "code", use_mousewheel = true -} +}, config.plugins.scale) local scale_steps = 0.05