mirror of
https://github.com/zoriya/telescope.nvim.git
synced 2026-08-16 02:45:09 +00:00
Begin work on larger global config, to tailor defaults
This commit is contained in:
+50
-14
@@ -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
|
||||
|
||||
_TelescopeConfigurationValues.default_layout_strategy = get_default(
|
||||
_TelescopeConfigurationValues.default_layout_strategy,
|
||||
'horizontal'
|
||||
)
|
||||
function config.set_defaults(defaults)
|
||||
defaults = defaults or {}
|
||||
|
||||
-- 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
|
||||
)
|
||||
local function get(name, default_val)
|
||||
return first_non_null(defaults[name], config.values[name], default_val)
|
||||
end
|
||||
|
||||
return _TelescopeConfigurationValues
|
||||
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
|
||||
|
||||
config.set_defaults()
|
||||
|
||||
|
||||
return config
|
||||
|
||||
Reference in New Issue
Block a user