forked from chrisgrieser/nvim-various-textobjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
66 lines (55 loc) · 2.39 KB
/
init.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local M = {}
-- PERF do not import submodules here, since it results in them all being loaded
-- on initialization instead of lazy-loading them when needed.
--------------------------------------------------------------------------------
local notifiedOnce = false -- only notify once
---INFO this function ensures backwards compatibility with earlier versions,
---where the input arg for selecting the inner or outer textobj was a boolean.
---For verbosity reasons, this is now a string.
---@param arg any
---@return "outer"|"inner"
local function argConvert(arg)
if arg == "outer" or arg == "inner" then return arg end
local u = require("various-textobjs.utils")
if not notifiedOnce and (arg == false or arg == true) then
local msg = "`true` and `false` are deprecated as textobject arguments. "
.. 'Use `"inner"` or `"outer"` instead.'
u.notify(msg, "warn")
notifiedOnce = true
end
if arg == true then return "inner" end
return "outer"
end
---TODO This is the only function that takes more than one argument, thus
---prevent the simple use of `__index`. When `argConvert` is removed, `__index`
---can use `...` to pass all arguments, making this function unnecessary.
---@param startBorder "inner"|"outer" exclude the startline
---@param endBorder "inner"|"outer" exclude the endline
---@param blankLines? "withBlanks"|"noBlanks"
function M.indentation(startBorder, endBorder, blankLines)
require("various-textobjs.linewise-textobjs").indentation(
argConvert(startBorder),
argConvert(endBorder),
blankLines
)
end
--------------------------------------------------------------------------------
---optional setup function
---@param userConfig? config
function M.setup(userConfig) require("various-textobjs.config").setup(userConfig) end
--------------------------------------------------------------------------------
-- redirect calls to this module to the charwise-textobjs submodule
setmetatable(M, {
__index = function(_, key)
return function(scope)
local _scope = argConvert(scope)
local linewiseObjs = vim.tbl_keys(require("various-textobjs.linewise-textobjs"))
local module = "charwise-textobjs"
if vim.tbl_contains(linewiseObjs, key) then module = "linewise-textobjs" end
if key == "column" then module = "blockwise-textobjs" end
require("various-textobjs." .. module)[key](_scope)
end
end,
})
--------------------------------------------------------------------------------
return M