|
62 | 62 | M.setup_opts = {}
|
63 | 63 | M.globals = setmetatable({}, {
|
64 | 64 | __index = function(_, index)
|
| 65 | + local function setup_opts() |
| 66 | + return M._profile_opts or M.setup_opts |
| 67 | + end |
| 68 | + local function setup_defaults() |
| 69 | + return M._profile_opts and (M._profile_opts.defaults or {}) or M.setup_opts.defaults or {} |
| 70 | + end |
65 | 71 | -- build normalized globals, option priority below:
|
66 | 72 | -- (1) provider specific globals (post-setup)
|
67 | 73 | -- (2) generic global-defaults (post-setup), i.e. `setup({ defaults = { ... } })`
|
68 | 74 | -- (3) fzf-lua's true defaults (pre-setup, static)
|
69 | 75 | local fzflua_default = utils.map_get(M.defaults, index)
|
70 |
| - local setup_default = utils.map_get(M.setup_opts.defaults, index) |
71 |
| - local setup_value = utils.map_get(M.setup_opts, index) |
| 76 | + local setup_default = utils.map_get(setup_defaults(), index) |
| 77 | + local setup_value = utils.map_get(setup_opts(), index) |
72 | 78 | local function build_bind_tables(keys)
|
73 | 79 | -- bind tables are logical exception, do not merge with defaults unless `[1] == true`
|
74 | 80 | -- normalize all binds as lowercase to prevent duplicate keys (#654)
|
@@ -108,10 +114,10 @@ M.globals = setmetatable({}, {
|
108 | 114 | or (setup_value and (setup_value.actions or setup_value._actions)) then
|
109 | 115 | -- (2) the existence of the `actions` key implies we're dealing with a picker
|
110 | 116 | -- override global provider defaults supplied by the user's setup `defaults` table
|
111 |
| - ret = vim.tbl_deep_extend("force", ret, M.setup_opts.defaults or {}) |
| 117 | + ret = vim.tbl_deep_extend("force", ret, setup_defaults()) |
112 | 118 | end
|
113 | 119 | -- (3) override with the specific provider options from the users's `setup` option
|
114 |
| - ret = vim.tbl_deep_extend("force", ret, utils.map_get(M.setup_opts, index) or {}) |
| 120 | + ret = vim.tbl_deep_extend("force", ret, utils.map_get(setup_opts(), index) or {}) |
115 | 121 | return ret
|
116 | 122 | end,
|
117 | 123 | __newindex = function(_, index, _)
|
@@ -143,6 +149,17 @@ function M.normalize_opts(opts, globals, __resume_key)
|
143 | 149 | opts = opts()
|
144 | 150 | end
|
145 | 151 |
|
| 152 | + local profile = opts.profile or (function() |
| 153 | + if type(globals) == "string" then |
| 154 | + local picker_opts = M.globals[globals] |
| 155 | + return picker_opts.profile or picker_opts[1] |
| 156 | + end |
| 157 | + end)() |
| 158 | + if profile then |
| 159 | + -- TODO: we should probably cache the profiles |
| 160 | + M._profile_opts = utils.load_profiles(profile, 1) |
| 161 | + end |
| 162 | + |
146 | 163 | -- expand opts that were specified with a dot
|
147 | 164 | -- e.g. `:FzfLua files winopts.border=single`
|
148 | 165 | do
|
@@ -858,6 +875,9 @@ function M.normalize_opts(opts, globals, __resume_key)
|
858 | 875 | opts = opts.enrich(opts)
|
859 | 876 | end
|
860 | 877 |
|
| 878 | + -- nullify profile options |
| 879 | + M._profile_opts = nil |
| 880 | + |
861 | 881 | -- mark as normalized
|
862 | 882 | opts._normalized = true
|
863 | 883 |
|
|
0 commit comments