Skip to content

Commit dca2e99

Browse files
__kylechui
authored andcommitted
Defer loading some modules on startup
1 parent ec2dc76 commit dca2e99

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

lua/nvim-surround/config.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
local input = require("nvim-surround.input")
2-
local functional = require("nvim-surround.functional")
3-
41
local M = {}
52

63
---@type user_options
@@ -265,6 +262,7 @@ M.default_opts = {
265262
---@return string|nil @The user input.
266263
---@nodiscard
267264
M.get_input = function(prompt)
265+
local input = require("nvim-surround.input")
268266
return input.get_input(prompt)
269267
end
270268

@@ -546,6 +544,7 @@ end
546544
---@param user_opts user_options The user-provided options.
547545
---@return options @The translated options.
548546
M.translate_opts = function(user_opts)
547+
local input = require("nvim-surround.input")
549548
local opts = {}
550549
for key, value in pairs(user_opts) do
551550
if key == "surrounds" then

lua/nvim-surround/init.lua

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
local buffer = require("nvim-surround.buffer")
2-
local cache = require("nvim-surround.cache")
3-
local config = require("nvim-surround.config")
4-
local input = require("nvim-surround.input")
5-
local utils = require("nvim-surround.utils")
6-
71
local M = {}
82

93
-- Setup the plugin with user-defined options.
104
---@param user_opts user_options|nil The user options.
115
M.setup = function(user_opts)
12-
config.setup(user_opts)
6+
require("nvim-surround.config").setup(user_opts)
137
end
148

159
-- Configure the plugin on a per-buffer basis.
1610
---@param buffer_opts user_options|nil The buffer-local options.
1711
M.buffer_setup = function(buffer_opts)
18-
config.buffer_setup(buffer_opts)
12+
require("nvim-surround.config").buffer_setup(buffer_opts)
1913
end
2014

2115
-- Add delimiters around the cursor, in insert mode.
2216
---@param args { line_mode: boolean } Whether or not the delimiters should get put on new lines.
2317
M.insert_surround = function(args)
18+
local config = require("nvim-surround.config")
19+
local buffer = require("nvim-surround.buffer")
20+
local input = require("nvim-surround.input")
2421
local char = input.get_char()
2522
local curpos = buffer.get_curpos()
2623
local delimiters = config.get_delimiters(char, args.line_mode)
@@ -50,6 +47,9 @@ M.pending_surround = false
5047
---@param args { selection: selection, delimiters: delimiter_pair, line_mode: boolean }
5148
---@return "g@"|nil
5249
M.normal_surround = function(args)
50+
local config = require("nvim-surround.config")
51+
local buffer = require("nvim-surround.buffer")
52+
local cache = require("nvim-surround.cache")
5353
-- Call the operatorfunc if it has not been called yet
5454
if not args.selection then
5555
-- Clear the normal cache (since it was user-called)
@@ -83,6 +83,9 @@ end
8383
-- Add delimiters around a visual selection.
8484
---@param args { line_mode: boolean, curpos: position, curswant: number }
8585
M.visual_surround = function(args)
86+
local config = require("nvim-surround.config")
87+
local buffer = require("nvim-surround.buffer")
88+
local input = require("nvim-surround.input")
8689
local ins_char = input.get_char()
8790

8891
if vim.fn.visualmode() == "V" then
@@ -153,6 +156,10 @@ end
153156
---@param args { del_char: string, curpos: position }|nil
154157
---@return "g@l"|nil
155158
M.delete_surround = function(args)
159+
local config = require("nvim-surround.config")
160+
local buffer = require("nvim-surround.buffer")
161+
local cache = require("nvim-surround.cache")
162+
local utils = require("nvim-surround.utils")
156163
-- Call the operatorfunc if it has not been called yet
157164
if not args then
158165
-- Clear the delete cache (since it was user-called)
@@ -186,6 +193,10 @@ end
186193
---@param args { curpos: position, del_char: string, add_delimiters: add_func, line_mode: boolean }
187194
---@return "g@l"|nil
188195
M.change_surround = function(args)
196+
local config = require("nvim-surround.config")
197+
local buffer = require("nvim-surround.buffer")
198+
local cache = require("nvim-surround.cache")
199+
local utils = require("nvim-surround.utils")
189200
-- Call the operatorfunc if it has not been called yet
190201
if not args.del_char or not args.add_delimiters then
191202
-- Clear the change cache (since it was user-called)
@@ -248,6 +259,10 @@ end
248259

249260
---@param mode "char"|"line"|"block"
250261
M.normal_callback = function(mode)
262+
local config = require("nvim-surround.config")
263+
local buffer = require("nvim-surround.buffer")
264+
local cache = require("nvim-surround.cache")
265+
local input = require("nvim-surround.input")
251266
buffer.restore_curpos({ old_pos = M.normal_curpos })
252267
-- Adjust the ] mark if the operator was in line-mode, e.g. `ip` or `3j`
253268
if mode == "line" then
@@ -307,6 +322,9 @@ M.normal_callback = function(mode)
307322
end
308323

309324
M.delete_callback = function()
325+
local buffer = require("nvim-surround.buffer")
326+
local cache = require("nvim-surround.cache")
327+
local input = require("nvim-surround.input")
310328
-- Save the current position of the cursor
311329
local curpos = buffer.get_curpos()
312330
-- Get a character input if not cached
@@ -322,6 +340,11 @@ M.delete_callback = function()
322340
end
323341

324342
M.change_callback = function()
343+
local config = require("nvim-surround.config")
344+
local buffer = require("nvim-surround.buffer")
345+
local cache = require("nvim-surround.cache")
346+
local input = require("nvim-surround.input")
347+
local utils = require("nvim-surround.utils")
325348
-- Save the current position of the cursor
326349
local curpos = buffer.get_curpos()
327350
if not cache.change.del_char or not cache.change.add_delimiters then

0 commit comments

Comments
 (0)