diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-09-07 00:20:08 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-09-07 00:20:08 -0400 |
| commit | 11a3c706093f6656ce33dabe0810f96490403818 (patch) | |
| tree | bb2b20670e51233db05dfd69b5a807be85b098fb /lua/telescope/config.lua | |
| parent | 2592586533868aede5c254f4599601bf53f699da (diff) | |
Begin work on larger global config, to tailor defaults
Diffstat (limited to 'lua/telescope/config.lua')
| -rw-r--r-- | lua/telescope/config.lua | 64 |
1 files changed, 50 insertions, 14 deletions
diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 6139d36..9e1c337 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -1,25 +1,61 @@ -local get_default = require('telescope.utils').get_default +-- Keep the values around between reloads +_TelescopeConfigurationValues = _TelescopeConfigurationValues or {} + +local function first_non_null(...) + local n = select('#', ...) + for i = 1, n do + local value = select(i, ...) + if value ~= nil then + return value + end + end +end -- TODO: Add other major configuration points here. -- border -- borderchars -- selection_strategy --- TODO: use `require('telescope').setup { }` +local config = {} -_TelescopeConfigurationValues = _TelescopeConfigurationValues or {} +config.values = _TelescopeConfigurationValues + +function config.set_defaults(defaults) + defaults = defaults or {} + + local function get(name, default_val) + return first_non_null(defaults[name], config.values[name], default_val) + end + + local function set(name, default_val) + config.values[name] = get(name, default_val) + end + + set("selection_strategy", "reset") + + set("layout_strategy", "horizontal") + set("width", 0.75) + set("winblend", 0) + + -- TODO: Shortenpath + -- Decide how to propagate that to all the opts everywhere. + + -- NOT STABLE. DO NOT USE + set("horizontal_config", { + get_preview_width = function(columns, _) + return math.floor(columns * 0.75) + end, + }) +end + +function config.clear_defaults() + for k, _ in pairs(config.values) do + config.values[k] = nil + end +end -_TelescopeConfigurationValues.default_layout_strategy = get_default( - _TelescopeConfigurationValues.default_layout_strategy, - 'horizontal' -) +config.set_defaults() --- TODO: this should probably be more complicated than just a number. --- If you're going to allow a bunch of layout strats, they should have nested info or something -_TelescopeConfigurationValues.default_window_width = get_default( - _TelescopeConfigurationValues.default_window_width, - 0.75 -) -return _TelescopeConfigurationValues +return config |
