Skip to content

Commit

Permalink
fix(configs): use cumulative config
Browse files Browse the repository at this point in the history
  • Loading branch information
bekaboo committed Apr 3, 2023
1 parent 11d1f32 commit fef1b12
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
26 changes: 13 additions & 13 deletions lua/deadcolumn/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ local function redraw_cc()
return
end

if not vim.tbl_contains(configs.user.modes, vim.fn.mode()) then
if not vim.tbl_contains(configs.opts.modes, vim.fn.mode()) then
win_safe_set_option(0, 'cc', '')
return
end

local len = scope_len_fn[configs.user.scope]()
local thresh = configs.user.blending.threshold
local len = scope_len_fn[configs.opts.scope]()
local thresh = configs.opts.blending.threshold
if 0 < thresh and thresh <= 1 then
thresh = math.floor(thresh * cc)
end
Expand All @@ -111,9 +111,9 @@ local function redraw_cc()

-- Show blended color when len < cc
local normal_bg = colors.get_hl(
configs.user.blending.hlgroup[1],
configs.user.blending.hlgroup[2],
configs.user.blending.colorcode
configs.opts.blending.hlgroup[1],
configs.opts.blending.hlgroup[2],
configs.opts.blending.colorcode
)
if len < cc then
vim.api.nvim_set_hl(0, 'ColorColumn', {
Expand All @@ -125,26 +125,26 @@ local function redraw_cc()
})
else -- Show error color when len >= cc
local warning_color = colors.get_hl(
configs.user.warning.hlgroup[1],
configs.user.warning.hlgroup[2],
configs.user.warning.colorcode
configs.opts.warning.hlgroup[1],
configs.opts.warning.hlgroup[2],
configs.opts.warning.colorcode
)
vim.api.nvim_set_hl(0, 'ColorColumn', {
bg = colors.blend(warning_color, normal_bg, configs.user.warning.alpha),
bg = colors.blend(warning_color, normal_bg, configs.opts.warning.alpha),
})
end
end

---Set to be relative to textwidth if textwidth is set
local function set_relative_cc(tbl)
if not configs.user.extra.follow_tw then
if not configs.opts.extra.follow_tw then
return
end
if tbl.event == 'BufWinEnter' and vim.b._cc_last_set_by == 'modeline' then
return
end
if vim.bo.textwidth > 0 then
vim.w.cc = configs.user.extra.follow_tw
vim.w.cc = configs.opts.extra.follow_tw
else
vim.w.cc = str_fallback(vim.b.cc, vim.g.cc)
end
Expand Down Expand Up @@ -257,7 +257,7 @@ local function autocmd_track_cc()
if vim.b.cc == vim.wo.cc then
vim.b._cc_last_set_by = 'modeline'
end
if not vim.tbl_contains(configs.user.modes, vim.fn.mode()) then
if not vim.tbl_contains(configs.opts.modes, vim.fn.mode()) then
win_safe_set_option(0, 'cc', '')
end
end,
Expand Down
34 changes: 17 additions & 17 deletions lua/deadcolumn/configs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local M = {}

---Default options
---@class ColorColumnOptions
M.default = {
M.opts = {
scope = 'line',
modes = { 'i', 'ic', 'ix', 'R', 'Rc', 'Rx', 'Rv', 'Rvc', 'Rvx' },
blending = {
Expand All @@ -21,51 +21,51 @@ M.default = {
}

function M.set_options(user_opts)
M.user = vim.tbl_deep_extend('force', M.default, user_opts or {})
M.opts = vim.tbl_deep_extend('force', M.opts, user_opts or {})
-- Sanity check
if M.user.threshold then
if M.opts.threshold then
vim.notify(
'[deadcolumn] opts.threshold is deprecated and will be removed by 2023-06, use opts.blending.threshold instead',
vim.log.levels.WARN
)
M.user.blending.threshold = M.user.threshold
M.opts.blending.threshold = M.opts.threshold
end
assert(vim.tbl_islist(M.user.modes), 'modes must be a list of strings')
assert(vim.tbl_islist(M.opts.modes), 'modes must be a list of strings')
assert(
vim.tbl_contains({ 'line', 'buffer', 'visible', 'cursor' }, M.user.scope),
vim.tbl_contains({ 'line', 'buffer', 'visible', 'cursor' }, M.opts.scope),
'scope must be one of "line", "buffer", "visible", "cursor"'
)
assert(M.user.blending.threshold >= 0, 'blending.threshold must be >= 0')
assert(M.opts.blending.threshold >= 0, 'blending.threshold must be >= 0')
assert(
M.user.blending.colorcode:match('^#?%x%x%x%x%x%x$'),
M.opts.blending.colorcode:match('^#?%x%x%x%x%x%x$'),
'blending.colorcode must be a 6-digit hex color code'
)
assert(
vim.tbl_contains(
{ 'foreground', 'background' },
M.user.blending.hlgroup[2]
M.opts.blending.hlgroup[2]
),
'blending.hlgroup[2] must be "foreground" or "background"'
)
assert(M.user.warning.alpha >= 0, 'warning.alpha must be >= 0')
assert(M.user.warning.alpha <= 1, 'warning.alpha must be <= 1')
assert(M.opts.warning.alpha >= 0, 'warning.alpha must be >= 0')
assert(M.opts.warning.alpha <= 1, 'warning.alpha must be <= 1')
assert(
M.user.warning.colorcode:match('^#?%x%x%x%x%x%x$'),
M.opts.warning.colorcode:match('^#?%x%x%x%x%x%x$'),
'warning.colorcode must be a 6-digit hex color code'
)
assert(
vim.tbl_contains({ 'foreground', 'background' }, M.user.warning.hlgroup[2]),
vim.tbl_contains({ 'foreground', 'background' }, M.opts.warning.hlgroup[2]),
'warning.hlgroup[2] must be "foreground" or "background"'
)
assert(
type(M.user.extra.follow_tw) == 'nil'
or type(M.user.extra.follow_tw) == 'string',
type(M.opts.extra.follow_tw) == 'nil'
or type(M.opts.extra.follow_tw) == 'string',
'extra.follow_tw must be nil or a string'
)

-- Preprocess
M.user.blending.colorcode = M.user.blending.colorcode:upper()
M.user.warning.colorcode = M.user.warning.colorcode:upper()
M.opts.blending.colorcode = M.opts.blending.colorcode:upper()
M.opts.warning.colorcode = M.opts.warning.colorcode:upper()
end

return M

0 comments on commit fef1b12

Please sign in to comment.