Skip to content

Commit 1381bd0

Browse files
authored
refactor: Remove top-level modules. (#445)
Moving all of the module loads into their respective functions.
1 parent b2f3098 commit 1381bd0

4 files changed

Lines changed: 10 additions & 11 deletions

File tree

lua/nvim-surround/buffer.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local config = require("nvim-surround.config")
2-
31
local M = {}
42

53
M.namespace = {
@@ -34,6 +32,7 @@ end
3432
-- Move the cursor to a location in the buffer, depending on the `move_cursor` setting.
3533
---@param pos { first_pos: position, sticky_pos: position, old_pos: position } Various positions in the buffer.
3634
M.restore_curpos = function(pos)
35+
local config = require("nvim-surround.config")
3736
if config.get_opts().move_cursor == "begin" then
3837
M.set_curpos(pos.first_pos)
3938
elseif config.get_opts().move_cursor == "sticky" then

lua/nvim-surround/motions.lua

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

63
-- Determines whether the input character is a quote character.
@@ -16,6 +13,8 @@ end
1613
---@return selection|nil @The selection that represents the text-object.
1714
---@nodiscard
1815
M.get_selection = function(motion)
16+
local buffer = require("nvim-surround.buffer")
17+
local config = require("nvim-surround.config")
1918
local char = config.get_alias(motion:sub(2, 2))
2019
local curpos = buffer.get_curpos()
2120

lua/nvim-surround/patterns.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
local buffer = require("nvim-surround.buffer")
2-
31
local M = {}
42

53
-- Gets the EOL character for the current buffer, based on the file format.
@@ -45,6 +43,7 @@ end
4543
---@return selection @The adjusted selection, handling multi-byte characters.
4644
---@nodiscard
4745
M.adjust_selection = function(selection)
46+
local buffer = require("nvim-surround.buffer")
4847
selection.first_pos = buffer.get_first_byte(selection.first_pos)
4948
selection.last_pos = buffer.get_last_byte(selection.last_pos)
5049
return selection
@@ -55,6 +54,7 @@ end
5554
---@return selection|nil @The closest selection matching the pattern, if any.
5655
---@nodiscard
5756
M.get_selection = function(find)
57+
local buffer = require("nvim-surround.buffer")
5858
-- Get the current cursor position, buffer contents
5959
local curpos = buffer.get_curpos()
6060
local buffer_text = table.concat(buffer.get_lines(1, -1), end_of_line())
@@ -130,6 +130,7 @@ end
130130
---@return selections|nil @The selections for the left and right delimiters.
131131
---@nodiscard
132132
M.get_selections = function(selection, pattern)
133+
local buffer = require("nvim-surround.buffer")
133134
local offset = M.pos_to_index(selection.first_pos)
134135
local str = table.concat(buffer.get_text(selection), end_of_line())
135136
-- Get the surrounding pair, and the start/end indices

lua/nvim-surround/utils.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
local buffer = require("nvim-surround.buffer")
2-
local config = require("nvim-surround.config")
3-
local functional = require("nvim-surround.functional")
4-
51
local M = {}
62

73
-- Do nothing.
@@ -42,12 +38,15 @@ end
4238
---@return selections|nil @A table containing the start and end positions of the delimiters.
4339
---@nodiscard
4440
M.get_nearest_selections = function(char, action)
41+
local config = require("nvim-surround.config")
42+
local functional = require("nvim-surround.functional")
4543
char = config.get_alias(char)
4644
local chars = functional.to_list(config.get_opts().aliases[char] or char)
4745
if not chars then
4846
return nil
4947
end
5048

49+
local buffer = require("nvim-surround.buffer")
5150
local curpos = buffer.get_curpos()
5251
local winview = vim.fn.winsaveview()
5352
local selections_list = {}
@@ -79,6 +78,7 @@ end
7978
---@return selections|nil @The best selections from the list.
8079
---@nodiscard
8180
M.filter_selections_list = function(selections_list)
81+
local buffer = require("nvim-surround.buffer")
8282
local curpos = buffer.get_curpos()
8383
local best_selections
8484
for _, cur_selections in ipairs(selections_list) do

0 commit comments

Comments
 (0)