refactor: new logic, file splitting

BREAKING CHANGES: functions, configs have been renamed
This commit is contained in:
2024-04-28 13:15:29 +03:00
parent ded86d9b0f
commit b4257a50fe
13 changed files with 669 additions and 424 deletions

View File

@@ -1,10 +1,13 @@
local TextTransform = {}
local telescope_popup = require("text-transform.telescope")
local D = require("text-transform.util.debug")
local utils = require("text-transform.util")
local config = {}
--- Your plugin configuration with its default values.
---
--- Default values:
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
TextTransform.options = {
config.options = {
-- Prints useful logs about what event are triggered, and reasons actions are executed.
debug = false,
-- Keymap to trigger the transform.
@@ -16,71 +19,33 @@ TextTransform.options = {
},
}
local function init()
local o = config.options
D.log("config", "Initializing TextTransform with %s", utils.dump(o))
vim.keymap.set("n", o.keymap.n, telescope_popup, { silent = true })
vim.keymap.set("v", o.keymap.v, telescope_popup, { silent = true })
end
--- Define your text-transform setup.
---
---@param options table Module config table. See |TextTransform.options|.
---
---@usage `require("text-transform").setup()` (add `{}` with your |TextTransform.options| table)
function TextTransform.setup(options)
function config.setup(options)
options = options or {}
TextTransform.options = vim.tbl_deep_extend("keep", options, TextTransform.options)
config.options = utils.merge(config.options, options)
if vim.api.nvim_get_vvar("vim_did_enter") == 0 then
vim.defer_fn(function()
TextTransform._setup()
init()
end, 0)
else
TextTransform._setup()
init()
end
return TextTransform.options
return config.options
end
local CAMEL_CASE = "&camelCase"
local SNAKE_CASE = "&snake_case"
local PASCAL_CASE = "&PascalCase"
local KEBAB_CASE = "&kebab-case"
local DOT_CASE = "&dot\\.case"
local TITLE_CASE = "&Title\\ Case"
local CONST_CASE = "C&ONST_CASE"
-- TODO save frequency of use and order by frequency
local default_ordered_keys =
{ CAMEL_CASE, SNAKE_CASE, PASCAL_CASE, CONST_CASE, KEBAB_CASE, DOT_CASE, TITLE_CASE }
function TextTransform._setup()
local map = {
[CAMEL_CASE] = "camel_case",
[SNAKE_CASE] = "snake_case",
[PASCAL_CASE] = "pascal_case",
[KEBAB_CASE] = "kebab_case",
[DOT_CASE] = "dot_case",
[TITLE_CASE] = "title_case",
[CONST_CASE] = "const_case",
}
---@diagnostic disable-next-line: unused-local
for _i, k in pairs(default_ordered_keys) do
local v = map[k]
vim.cmd("amenu TransformsWord." .. k .. " :lua TextTransform.replace_word('" .. v .. "')<CR>")
vim.cmd(
"amenu TransformsSelection." .. k .. " :lua TextTransform.replace_columns('" .. v .. "')<CR>"
)
end
vim.keymap.set(
"n",
TextTransform.options.keymap.n,
"<cmd>popup TransformsWord<CR>",
{ silent = true }
)
vim.keymap.set(
"v",
TextTransform.options.keymap.v,
"<cmd>popup TransformsSelection<CR>",
{ silent = true }
)
end
return TextTransform
return config