diff --git a/lua/nvim-surround/config.lua b/lua/nvim-surround/config.lua index 487409c..313bc5e 100644 --- a/lua/nvim-surround/config.lua +++ b/lua/nvim-surround/config.lua @@ -1,6 +1,3 @@ -local input = require("nvim-surround.input") -local functional = require("nvim-surround.functional") - local M = {} ---@type user_options @@ -265,6 +262,7 @@ M.default_opts = { ---@return string|nil @The user input. ---@nodiscard M.get_input = function(prompt) + local input = require("nvim-surround.input") return input.get_input(prompt) end @@ -546,6 +544,7 @@ end ---@param user_opts user_options The user-provided options. ---@return options @The translated options. M.translate_opts = function(user_opts) + local input = require("nvim-surround.input") local opts = {} for key, value in pairs(user_opts) do if key == "surrounds" then diff --git a/lua/nvim-surround/init.lua b/lua/nvim-surround/init.lua index 588e424..0732bde 100644 --- a/lua/nvim-surround/init.lua +++ b/lua/nvim-surround/init.lua @@ -1,26 +1,23 @@ -local buffer = require("nvim-surround.buffer") -local cache = require("nvim-surround.cache") -local config = require("nvim-surround.config") -local input = require("nvim-surround.input") -local utils = require("nvim-surround.utils") - local M = {} -- Setup the plugin with user-defined options. ---@param user_opts user_options|nil The user options. M.setup = function(user_opts) - config.setup(user_opts) + require("nvim-surround.config").setup(user_opts) end -- Configure the plugin on a per-buffer basis. ---@param buffer_opts user_options|nil The buffer-local options. M.buffer_setup = function(buffer_opts) - config.buffer_setup(buffer_opts) + require("nvim-surround.config").buffer_setup(buffer_opts) end -- Add delimiters around the cursor, in insert mode. ---@param args { line_mode: boolean } Whether or not the delimiters should get put on new lines. M.insert_surround = function(args) + local config = require("nvim-surround.config") + local buffer = require("nvim-surround.buffer") + local input = require("nvim-surround.input") local char = input.get_char() local curpos = buffer.get_curpos() local delimiters = config.get_delimiters(char, args.line_mode) @@ -50,6 +47,9 @@ M.pending_surround = false ---@param args { selection: selection, delimiters: delimiter_pair, line_mode: boolean } ---@return "g@"|nil M.normal_surround = function(args) + local config = require("nvim-surround.config") + local buffer = require("nvim-surround.buffer") + local cache = require("nvim-surround.cache") -- Call the operatorfunc if it has not been called yet if not args.selection then -- Clear the normal cache (since it was user-called) @@ -83,6 +83,9 @@ end -- Add delimiters around a visual selection. ---@param args { line_mode: boolean, curpos: position, curswant: number } M.visual_surround = function(args) + local config = require("nvim-surround.config") + local buffer = require("nvim-surround.buffer") + local input = require("nvim-surround.input") local ins_char = input.get_char() if vim.fn.visualmode() == "V" then @@ -153,6 +156,10 @@ end ---@param args { del_char: string, curpos: position }|nil ---@return "g@l"|nil M.delete_surround = function(args) + local config = require("nvim-surround.config") + local buffer = require("nvim-surround.buffer") + local cache = require("nvim-surround.cache") + local utils = require("nvim-surround.utils") -- Call the operatorfunc if it has not been called yet if not args then -- Clear the delete cache (since it was user-called) @@ -186,6 +193,10 @@ end ---@param args { curpos: position, del_char: string, add_delimiters: add_func, line_mode: boolean } ---@return "g@l"|nil M.change_surround = function(args) + local config = require("nvim-surround.config") + local buffer = require("nvim-surround.buffer") + local cache = require("nvim-surround.cache") + local utils = require("nvim-surround.utils") -- Call the operatorfunc if it has not been called yet if not args.del_char or not args.add_delimiters then -- Clear the change cache (since it was user-called) @@ -248,6 +259,10 @@ end ---@param mode "char"|"line"|"block" M.normal_callback = function(mode) + local config = require("nvim-surround.config") + local buffer = require("nvim-surround.buffer") + local cache = require("nvim-surround.cache") + local input = require("nvim-surround.input") buffer.restore_curpos({ old_pos = M.normal_curpos }) -- Adjust the ] mark if the operator was in line-mode, e.g. `ip` or `3j` if mode == "line" then @@ -307,6 +322,9 @@ M.normal_callback = function(mode) end M.delete_callback = function() + local buffer = require("nvim-surround.buffer") + local cache = require("nvim-surround.cache") + local input = require("nvim-surround.input") -- Save the current position of the cursor local curpos = buffer.get_curpos() -- Get a character input if not cached @@ -322,6 +340,11 @@ M.delete_callback = function() end M.change_callback = function() + local config = require("nvim-surround.config") + local buffer = require("nvim-surround.buffer") + local cache = require("nvim-surround.cache") + local input = require("nvim-surround.input") + local utils = require("nvim-surround.utils") -- Save the current position of the cursor local curpos = buffer.get_curpos() if not cache.change.del_char or not cache.change.add_delimiters then