Skip to content

Commit

Permalink
perf: inline imports in main module for lazy-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Dec 31, 2023
1 parent f68df17 commit 6c81be9
Showing 1 changed file with 104 additions and 37 deletions.
141 changes: 104 additions & 37 deletions lua/various-textobjs/init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
local M = {}

local blockwise = require("various-textobjs.blockwise-textobjs")
local charwise = require("various-textobjs.charwise-textobjs")
local linewise = require("various-textobjs.linewise-textobjs")
local u = require("various-textobjs.utils")
-- PERF do not import submodules here, since it results in them all being loaded
-- on initialization instead of lazy-loading them when needed.
--------------------------------------------------------------------------------

---INFO this function ensures backwards compatibility with earlier versions,
Expand All @@ -15,7 +13,7 @@ local function argConvert(arg)
if arg == false then return "outer" end
if arg == true then return "inner" end
if arg == "outer" or arg == "inner" then return arg end
u.notify(
require("various-textobjs.utils").notify(
"Invalid argument for textobject, only 'outer' and 'inner' accepted. Falling back to outer textobject.",
"warn"
)
Expand Down Expand Up @@ -55,91 +53,160 @@ end
---@param endBorder "inner"|"outer" exclude the endline
---@param blankLines? "withBlanks"|"noBlanks"
function M.indentation(startBorder, endBorder, blankLines)
linewise.indentation(argConvert(startBorder), argConvert(endBorder), blankLines)
require("various-textobjs.linewise-textobjs").indentation(
argConvert(startBorder),
argConvert(endBorder),
blankLines
)
end

function M.restOfIndentation() linewise.restOfIndentation() end
function M.restOfIndentation() require("various-textobjs.linewise-textobjs").restOfIndentation() end

---@param scope "inner"|"outer" outer adds a blank, like ip/ap textobjs
function M.greedyOuterIndentation(scope) linewise.greedyOuterIndentation(argConvert(scope)) end
function M.greedyOuterIndentation(scope)
require("various-textobjs.linewise-textobjs").greedyOuterIndentation(argConvert(scope))
end

---@param scope "inner"|"outer" outer adds one line after the fold
function M.closedFold(scope) linewise.closedFold(argConvert(scope), config.lookForwardBig) end
function M.closedFold(scope)
require("various-textobjs.linewise-textobjs").closedFold(
argConvert(scope),
config.lookForwardBig
)
end

---@param scope "inner"|"outer" inner excludes the backticks
function M.mdFencedCodeBlock(scope)
linewise.mdFencedCodeBlock(argConvert(scope), config.lookForwardBig)
require("various-textobjs.linewise-textobjs").mdFencedCodeBlock(
argConvert(scope),
config.lookForwardBig
)
end

---@param scope "inner"|"outer" inner excludes the `"""`
function M.pyTripleQuotes(scope) charwise.pyTripleQuotes(argConvert(scope)) end
function M.pyTripleQuotes(scope)
require("various-textobjs.charwise-textobjs").pyTripleQuotes(argConvert(scope))
end

---@param scope "inner"|"outer" outer includes bottom cell border
function M.notebookCell(scope) linewise.notebookCell(argConvert(scope)) end
function M.notebookCell(scope)
require("various-textobjs.linewise-textobjs").notebookCell(argConvert(scope))
end

function M.restOfParagraph() linewise.restOfParagraph() end
function M.visibleInWindow() linewise.visibleInWindow() end
function M.restOfWindow() linewise.restOfWindow() end
function M.multiCommentedLines() linewise.multiCommentedLines(config.lookForwardBig) end
function M.entireBuffer() linewise.entireBuffer() end
function M.restOfParagraph() require("various-textobjs.linewise-textobjs").restOfParagraph() end
function M.visibleInWindow() require("various-textobjs.linewise-textobjs").visibleInWindow() end
function M.restOfWindow() require("various-textobjs.linewise-textobjs").restOfWindow() end
function M.multiCommentedLines()
require("various-textobjs.linewise-textobjs").multiCommentedLines(config.lookForwardBig)
end
function M.entireBuffer() require("various-textobjs.linewise-textobjs").entireBuffer() end

--------------------------------------------------------------------------------
-- BLOCKWISE

function M.column() blockwise.column() end
function M.column() require("various-textobjs.blockwise-textobjs").column() end

--------------------------------------------------------------------------------
-- CHARWISE

function M.nearEoL() charwise.nearEoL() end
function M.lineCharacterwise(scope) charwise.lineCharacterwise(argConvert(scope)) end
function M.toNextClosingBracket() charwise.toNextClosingBracket(config.lookForwardSmall) end
function M.toNextQuotationMark() charwise.toNextQuotationMark(config.lookForwardSmall) end
function M.url() charwise.url(config.lookForwardBig) end
function M.diagnostic() charwise.diagnostic(config.lookForwardBig) end
function M.lastChange() charwise.lastChange() end
function M.nearEoL() require("various-textobjs.charwise-textobjs").nearEoL() end
function M.lineCharacterwise(scope)
require("various-textobjs.charwise-textobjs").lineCharacterwise(argConvert(scope))
end
function M.toNextClosingBracket()
require("various-textobjs.charwise-textobjs").toNextClosingBracket(config.lookForwardSmall)
end
function M.toNextQuotationMark()
require("various-textobjs.charwise-textobjs").toNextQuotationMark(config.lookForwardSmall)
end
function M.url() require("various-textobjs.charwise-textobjs").url(config.lookForwardBig) end
function M.diagnostic()
require("various-textobjs.charwise-textobjs").diagnostic(config.lookForwardBig)
end
function M.lastChange() require("various-textobjs.charwise-textobjs").lastChange() end

---@param scope "inner"|"outer"
function M.anyQuote(scope) charwise.anyQuote(argConvert(scope), config.lookForwardSmall) end
function M.anyQuote(scope)
require("various-textobjs.charwise-textobjs").anyQuote(
argConvert(scope),
config.lookForwardSmall
)
end

---@param scope "inner"|"outer"
function M.anyBracket(scope) charwise.anyBracket(argConvert(scope), config.lookForwardSmall) end
function M.anyBracket(scope)
require("various-textobjs.charwise-textobjs").anyBracket(
argConvert(scope),
config.lookForwardSmall
)
end

---@param scope "inner"|"outer" inner value excludes trailing commas or semicolons, outer includes them. Both exclude trailing comments.
function M.value(scope) charwise.value(argConvert(scope), config.lookForwardSmall) end
function M.value(scope)
require("various-textobjs.charwise-textobjs").value(argConvert(scope), config.lookForwardSmall)
end

---@param scope "inner"|"outer" outer key includes the `:` or `=` after the key
function M.key(scope) charwise.key(argConvert(scope), config.lookForwardSmall) end
function M.key(scope)
require("various-textobjs.charwise-textobjs").key(argConvert(scope), config.lookForwardSmall)
end

---@param scope "inner"|"outer" inner number consists purely of digits, outer number factors in decimal points and includes minus sign
function M.number(scope) charwise.number(argConvert(scope), config.lookForwardSmall) end
function M.number(scope)
require("various-textobjs.charwise-textobjs").number(argConvert(scope), config.lookForwardSmall)
end

---@param scope "inner"|"outer" outer includes trailing -_
function M.subword(scope) charwise.subword(argConvert(scope)) end
function M.subword(scope) require("various-textobjs.charwise-textobjs").subword(argConvert(scope)) end

---see #26
---@param scope "inner"|"outer" inner excludes the leading dot
function M.chainMember(scope) charwise.chainMember(argConvert(scope), config.lookForwardSmall) end
function M.chainMember(scope)
require("various-textobjs.charwise-textobjs").chainMember(
argConvert(scope),
config.lookForwardSmall
)
end

--------------------------------------------------------------------------------
-- FILETYPE SPECIFIC TEXTOBJS

---@param scope "inner"|"outer" inner link only includes the link title, outer link includes link, url, and the four brackets.
function M.mdlink(scope) charwise.mdlink(argConvert(scope), config.lookForwardSmall) end
function M.mdlink(scope)
require("various-textobjs.charwise-textobjs").mdlink(argConvert(scope), config.lookForwardSmall)
end

---@param scope "inner"|"outer" inner double square brackets exclude the brackets themselves
function M.doubleSquareBrackets(scope)
charwise.doubleSquareBrackets(argConvert(scope), config.lookForwardSmall)
require("various-textobjs.charwise-textobjs").doubleSquareBrackets(
argConvert(scope),
config.lookForwardSmall
)
end

---@param scope "inner"|"outer" outer selector includes trailing comma and whitespace
function M.cssSelector(scope) charwise.cssSelector(argConvert(scope), config.lookForwardSmall) end
function M.cssSelector(scope)
require("various-textobjs.charwise-textobjs").cssSelector(
argConvert(scope),
config.lookForwardSmall
)
end

---@param scope "inner"|"outer" inner selector is only the value of the attribute inside the quotation marks.
function M.htmlAttribute(scope) charwise.htmlAttribute(argConvert(scope), config.lookForwardSmall) end
function M.htmlAttribute(scope)
require("various-textobjs.charwise-textobjs").htmlAttribute(
argConvert(scope),
config.lookForwardSmall
)
end

---@param scope "inner"|"outer" outer selector includes the front pipe
function M.shellPipe(scope) charwise.shellPipe(argConvert(scope), config.lookForwardSmall) end
function M.shellPipe(scope)
require("various-textobjs.charwise-textobjs").shellPipe(
argConvert(scope),
config.lookForwardSmall
)
end

--------------------------------------------------------------------------------
return M

0 comments on commit 6c81be9

Please sign in to comment.