diff --git a/data/core/common.lua b/data/core/common.lua index bae6636a..37d30436 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 a887d579..1233595b 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -30,10 +30,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