Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer loading some modules #355

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lua/nvim-surround/config.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
local input = require("nvim-surround.input")
local functional = require("nvim-surround.functional")

local M = {}

---@type user_options
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
39 changes: 31 additions & 8 deletions lua/nvim-surround/init.lua
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading