-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allowing users to pass in function to override instead of simpl…
…y a list
- Loading branch information
Showing
6 changed files
with
27 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- Main configuration engine logic for extending a default configuration table with either a function override or a table to merge into the default option | ||
|
||
-- @param overrides the override definition, either a table or a function that takes a single parameter of the original table | ||
-- @param default the default configuration table | ||
-- @return the new configuration table | ||
local function func_or_extend(overrides, default) | ||
-- if the override is a table, use vim.tbl_deep_extend | ||
if type(overrides) == 'table' then | ||
local opts = overrides or {} | ||
default = default and vim.tbl_deep_extend('force', default, opts) or opts | ||
-- if the override is a function, call it with the default and overwrite default with the return value | ||
elseif type(overrides) == 'function' then | ||
default = overrides(default) | ||
end | ||
-- return the modified default table | ||
return default | ||
end | ||
return func_or_extend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters