Skip to content

Commit 1473f18

Browse files
committed
refactor: config
1 parent e9a1792 commit 1473f18

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

lua/persisted/config.lua

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
return {
1+
local defaults = {
22
autostart = true, -- Automatically start the plugin on load?
33

44
-- Function to determine if a session should be saved
@@ -33,3 +33,22 @@ return {
3333
},
3434
},
3535
}
36+
37+
local M = {
38+
config = vim.deepcopy(defaults),
39+
}
40+
41+
---@param opts? table
42+
M.setup = function(opts)
43+
opts = opts or {}
44+
M.config = vim.tbl_deep_extend("force", vim.deepcopy(defaults), opts)
45+
end
46+
47+
return setmetatable(M, {
48+
__index = function(_, key)
49+
if key == "setup" then
50+
return M.setup
51+
end
52+
return rawget(M.config, key)
53+
end,
54+
})

lua/persisted/init.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
local config = require("persisted.config")
12
local utils = require("persisted.utils")
23

34
local M = {}
45

5-
local config
66
local start_args = vim.fn.argc() > 0 or vim.g.started_with_stdin
77

88
local e = vim.fn.fnameescape
@@ -220,8 +220,7 @@ end
220220
---Setup the plugin
221221
---@param opts? table
222222
function M.setup(opts)
223-
config = vim.tbl_deep_extend("force", require("persisted.config"), opts or {})
224-
M.config = config
223+
config.setup(opts)
225224

226225
vim.fn.mkdir(config.save_dir, "p")
227226

lua/telescope/_extensions/persisted.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ local _actions = require("telescope._extensions.persisted.actions")
77
local _finders = require("telescope._extensions.persisted.finders")
88

99
local persisted = require("persisted")
10+
local config = require("persisted.config")
1011
local utils = require("persisted.utils")
1112

12-
local config = persisted.config
13-
1413
local telescope_opts = {}
1514

1615
---Escapes special characters before performing string substitution

lua/telescope/_extensions/persisted/actions.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local actions_state = require("telescope.actions.state")
22
local transform_mod = require("telescope.actions.mt").transform_mod
33

44
local persisted = require("persisted")
5-
local config = persisted.config
5+
local config = require("persisted.config")
66

77
local M = {}
88

lua/telescope/_extensions/persisted/finders.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local config = require("persisted").config
1+
local config = require("persisted.config")
22
local finders = require("telescope.finders")
33

44
local M = {}

0 commit comments

Comments
 (0)