Skip to content

Commit

Permalink
refactor: use plugin name
Browse files Browse the repository at this point in the history
  • Loading branch information
chenasraf committed May 6, 2024
1 parent 701d373 commit 33eecff
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 164 deletions.
48 changes: 24 additions & 24 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
commands.init_commands() text-transform.txt /*commands.init_commands()*
commands.init_keymaps() text-transform.txt /*commands.init_keymaps()*
config.config text-transform.txt /*config.config*
config.setup() text-transform.txt /*config.setup()*
TextTransform.config text-transform.txt /*TextTransform.config*
TextTransform.get_visual_selection_details() text-transform.txt /*TextTransform.get_visual_selection_details()*
TextTransform.init_commands() text-transform.txt /*TextTransform.init_commands()*
TextTransform.init_keymaps() text-transform.txt /*TextTransform.init_keymaps()*
TextTransform.merge() text-transform.txt /*TextTransform.merge()*
TextTransform.replace_columns() text-transform.txt /*TextTransform.replace_columns()*
TextTransform.replace_range() text-transform.txt /*TextTransform.replace_range()*
TextTransform.replace_selection() text-transform.txt /*TextTransform.replace_selection()*
TextTransform.replace_word() text-transform.txt /*TextTransform.replace_word()*
TextTransform.restore_positions() text-transform.txt /*TextTransform.restore_positions()*
TextTransform.save_positions() text-transform.txt /*TextTransform.save_positions()*
TextTransform.select_popup() text-transform.txt /*TextTransform.select_popup()*
TextTransform.setup() text-transform.txt /*TextTransform.setup()*
TextTransform.show_popup() text-transform.txt /*TextTransform.show_popup()*
TextTransform.telescope_popup() text-transform.txt /*TextTransform.telescope_popup()*
TextTransform.to_camel_case() text-transform.txt /*TextTransform.to_camel_case()*
TextTransform.to_const_case() text-transform.txt /*TextTransform.to_const_case()*
TextTransform.to_dot_case() text-transform.txt /*TextTransform.to_dot_case()*
TextTransform.to_kebab_case() text-transform.txt /*TextTransform.to_kebab_case()*
TextTransform.to_pascal_case() text-transform.txt /*TextTransform.to_pascal_case()*
TextTransform.to_snake_case() text-transform.txt /*TextTransform.to_snake_case()*
TextTransform.to_title_case() text-transform.txt /*TextTransform.to_title_case()*
TextTransform.to_words() text-transform.txt /*TextTransform.to_words()*
TextTransform.transform_words() text-transform.txt /*TextTransform.transform_words()*
find_word_boundaries() text-transform.txt /*find_word_boundaries()*
popup.show_popup() text-transform.txt /*popup.show_popup()*
replacers.get_visual_selection_details() text-transform.txt /*replacers.get_visual_selection_details()*
replacers.replace_columns() text-transform.txt /*replacers.replace_columns()*
replacers.replace_range() text-transform.txt /*replacers.replace_range()*
replacers.replace_selection() text-transform.txt /*replacers.replace_selection()*
replacers.replace_word() text-transform.txt /*replacers.replace_word()*
select.select_popup() text-transform.txt /*select.select_popup()*
state.restore_positions() text-transform.txt /*state.restore_positions()*
state.save_positions() text-transform.txt /*state.save_positions()*
telescope.telescope_popup() text-transform.txt /*telescope.telescope_popup()*
transformers.to_camel_case() text-transform.txt /*transformers.to_camel_case()*
transformers.to_const_case() text-transform.txt /*transformers.to_const_case()*
transformers.to_dot_case() text-transform.txt /*transformers.to_dot_case()*
transformers.to_kebab_case() text-transform.txt /*transformers.to_kebab_case()*
transformers.to_pascal_case() text-transform.txt /*transformers.to_pascal_case()*
transformers.to_snake_case() text-transform.txt /*transformers.to_snake_case()*
transformers.to_title_case() text-transform.txt /*transformers.to_title_case()*
transformers.to_words() text-transform.txt /*transformers.to_words()*
transformers.transform_words() text-transform.txt /*transformers.transform_words()*
utils.merge() text-transform.txt /*utils.merge()*
98 changes: 49 additions & 49 deletions doc/text-transform.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
==============================================================================
------------------------------------------------------------------------------
*commands.init_commands()*
`commands.init_commands`()
*TextTransform.init_commands()*
`TextTransform.init_commands`()
Initializes user commands
@private

------------------------------------------------------------------------------
*commands.init_keymaps()*
`commands.init_keymaps`()
*TextTransform.init_keymaps()*
`TextTransform.init_keymaps`()
Initializes user keymaps
@private


==============================================================================
------------------------------------------------------------------------------
*config.config*
`config.config`
*TextTransform.config*
`TextTransform.config`
Your plugin configuration with its default values.

Default values:
>
config.config = {
TextTransform.config = {
--- Prints information about internals of the plugin. Very verbose, only useful for debugging.
debug = false,
--- Keymap configurations
Expand Down Expand Up @@ -61,8 +61,8 @@ Default values:
<

------------------------------------------------------------------------------
*config.setup()*
`config.setup`({options})
*TextTransform.setup()*
`TextTransform.setup`({options})
Define your text-transform setup.

Parameters ~
Expand All @@ -82,8 +82,8 @@ Finds the boundaries of the surrounding word around `start_col` within `line`.
@return number start_col, number end_col

------------------------------------------------------------------------------
*replacers.replace_range()*
`replacers.replace_range`({start_line}, {start_col}, {end_line}, {end_col}, {transform_name})
*TextTransform.replace_range()*
`TextTransform.replace_range`({start_line}, {start_col}, {end_line}, {end_col}, {transform_name})
Replace the range between the given positions with the given transform.
Acts on the lines between the given positions, replacing the text between the given columns.

Expand All @@ -94,8 +94,8 @@ Acts on the lines between the given positions, replacing the text between the gi
@param transform_name string The transformer name

------------------------------------------------------------------------------
*replacers.replace_word()*
`replacers.replace_word`({transform_name}, {position})
*TextTransform.replace_word()*
`TextTransform.replace_word`({transform_name}, {position})
Replace the word under the cursor with the given transform.
If `position` is provided, replace the word under the given position.
Otherwise, attempts to find the word under the cursor.
Expand All @@ -104,25 +104,25 @@ Otherwise, attempts to find the word under the cursor.
@param position table|nil A table containing the position of the word to replace

------------------------------------------------------------------------------
*replacers.replace_columns()*
`replacers.replace_columns`({transform_name})
*TextTransform.replace_columns()*
`TextTransform.replace_columns`({transform_name})
Replaces each column in visual block mode selection with the given transform.
Assumes that the each selection is 1 character and operates on the whole word under each cursor.

@param transform_name string The transformer name

------------------------------------------------------------------------------
*replacers.replace_selection()*
`replacers.replace_selection`({transform_name})
*TextTransform.replace_selection()*
`TextTransform.replace_selection`({transform_name})
Replaces a selection with the given transform. This function attempts to infer the replacement
type based on the cursor positiono and visual selections, and passes information to relevant
range replacement functions.

@param transform_name string The transformer name

------------------------------------------------------------------------------
*replacers.get_visual_selection_details()*
`replacers.get_visual_selection_details`()
*TextTransform.get_visual_selection_details()*
`TextTransform.get_visual_selection_details`()
Takes the saved positions and translates them into individual visual ranges, regardless of how
the original selection was performed.

Expand All @@ -132,28 +132,28 @@ the full information around the selection logic.

==============================================================================
------------------------------------------------------------------------------
*state.save_positions()*
`state.save_positions`()
*TextTransform.save_positions()*
`TextTransform.save_positions`()
Save the current cursor position, mode, and visual selection ranges

------------------------------------------------------------------------------
*state.restore_positions()*
`state.restore_positions`({new_state})
*TextTransform.restore_positions()*
`TextTransform.restore_positions`({positions})
Restore the cursor position, mode, and visual selection ranges saved using `save_position()`,
or a given modified state, if passed as the first argument


==============================================================================
------------------------------------------------------------------------------
*transformers.to_words()*
`transformers.to_words`({string})
*TextTransform.to_words()*
`TextTransform.to_words`({string})
Splits a string into words.
@param string string
@return table

------------------------------------------------------------------------------
*transformers.transform_words()*
`transformers.transform_words`({words}, {with_word_cb}, {separator})
*TextTransform.transform_words()*
`TextTransform.transform_words`({words}, {with_word_cb}, {separator})
Transforms a table of strings into a string using a callback and separator.
The callback is called with the word, the index, and the table of words.
The separator is added between each word.
Expand All @@ -164,59 +164,59 @@ The separator is added between each word.
@return string

------------------------------------------------------------------------------
*transformers.to_camel_case()*
`transformers.to_camel_case`({string})
*TextTransform.to_camel_case()*
`TextTransform.to_camel_case`({string})
Transforms a string into camelCase.
@param string string
@return string

------------------------------------------------------------------------------
*transformers.to_snake_case()*
`transformers.to_snake_case`({string})
*TextTransform.to_snake_case()*
`TextTransform.to_snake_case`({string})
Transfroms a string into snake_case.
@param string any
@return string

------------------------------------------------------------------------------
*transformers.to_pascal_case()*
`transformers.to_pascal_case`({string})
*TextTransform.to_pascal_case()*
`TextTransform.to_pascal_case`({string})
Transforms a string into PascalCase.
@param string string
@return string

------------------------------------------------------------------------------
*transformers.to_title_case()*
`transformers.to_title_case`({string})
*TextTransform.to_title_case()*
`TextTransform.to_title_case`({string})
Transforms a string into Title Case.
@param string string
@return string

------------------------------------------------------------------------------
*transformers.to_kebab_case()*
`transformers.to_kebab_case`({string})
*TextTransform.to_kebab_case()*
`TextTransform.to_kebab_case`({string})
Transforms a string into kebab-case.
@param string string
@return string

------------------------------------------------------------------------------
*transformers.to_dot_case()*
`transformers.to_dot_case`({string})
*TextTransform.to_dot_case()*
`TextTransform.to_dot_case`({string})
Transforms a string into dot.case.
@param string string
@return string

------------------------------------------------------------------------------
*transformers.to_const_case()*
`transformers.to_const_case`({string})
*TextTransform.to_const_case()*
`TextTransform.to_const_case`({string})
Transforms a string into CONSTANT_CASE.
@param string string
@return string


==============================================================================
------------------------------------------------------------------------------
*popup.show_popup()*
`popup.show_popup`()
*TextTransform.show_popup()*
`TextTransform.show_popup`()
Pops up a selection menu, containing the available case transformers.
When a transformer is selected, the cursor position/range/columns will be used to replace the
words around the cursor or inside the selection.
Expand All @@ -227,8 +227,8 @@ made.

==============================================================================
------------------------------------------------------------------------------
*select.select_popup()*
`select.select_popup`()
*TextTransform.select_popup()*
`TextTransform.select_popup`()
Pops up a selection menu, containing the available case transformers.
When a transformer is selected, the cursor position/range/columns will be used to replace the
words around the cursor or inside the selection.
Expand All @@ -239,8 +239,8 @@ made.

==============================================================================
------------------------------------------------------------------------------
*telescope.telescope_popup()*
`telescope.telescope_popup`()
*TextTransform.telescope_popup()*
`TextTransform.telescope_popup`()
Pops up a telescope menu, containing the available case transformers.
When a transformer is selected, the cursor position/range/columns will be used to replace the
words around the cursor or inside the selection.
Expand All @@ -251,8 +251,8 @@ made.

==============================================================================
------------------------------------------------------------------------------
*utils.merge()*
`utils.merge`({t1}, {t2})
*TextTransform.merge()*
`TextTransform.merge`({t1}, {t2})
Merges two tables into one. Same as `vim.tbl_extend("keep", t1, t2)`.
Mutates the first table.

Expand Down
11 changes: 7 additions & 4 deletions lua/text-transform/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ local replacers = require("text-transform.replacers")
local popup = require("text-transform.popup")
local common = require("text-transform.popup.common")

local commands = {}
local TextTransform = {}

--- Initializes user commands
--- @private
function commands.init_commands()
function TextTransform.init_commands()
local map = {
TtCamel = "camel_case",
TtConst = "const_case",
Expand All @@ -36,6 +36,9 @@ function commands.init_commands()
vim.api.nvim_create_user_command(cmd, function()
state.save_positions()
replacers.replace_selection(transformer_name)
vim.schedule(function()
state.restore_positions()
end)
end, opts("Change to " .. item))
end

Expand All @@ -55,7 +58,7 @@ end

--- Initializes user keymaps
--- @private
function commands.init_keymaps()
function TextTransform.init_keymaps()
local keymaps = _G.TextTransform.config.keymap
D.log("init_keymaps", "Initializing keymaps, config %s", vim.inspect(_G.TextTransform))
if keymaps.telescope_popup then
Expand All @@ -69,4 +72,4 @@ function commands.init_keymaps()
end
end

return commands
return TextTransform
16 changes: 8 additions & 8 deletions lua/text-transform/config.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
local commands = require("text-transform.commands")
local D = require("text-transform.utils.debug")
local utils = require("text-transform.utils")
local config = {}
local TextTransform = {}

local function ensure_config()
-- when the config is not set to the global object, we set it
if _G.TextTransform.config == nil then
_G.TextTransform.config = config.config
_G.TextTransform.config = TextTransform.config
end
end

local function init()
ensure_config()
local o = config.config
local o = TextTransform.config
D.log("config", "Initializing TextTransform with %s", vim.inspect(o))
commands.init_commands()
commands.init_keymaps()
Expand All @@ -22,7 +22,7 @@ end
---
--- Default values:
---@eval return MiniDoc.afterlines_to_code(MiniDoc.current.eval_section)
config.config = {
TextTransform.config = {
--- Prints information about internals of the plugin. Very verbose, only useful for debugging.
debug = false,
--- Keymap configurations
Expand Down Expand Up @@ -65,10 +65,10 @@ config.config = {
---@param options table Module config table. See |TextTransform.options|.
---
---@usage `require("text-transform").setup()` (add `{}` with your |TextTransform.options| table)
function config.setup(options)
function TextTransform.setup(options)
options = options or {}

config.config = utils.merge(config.config, options)
TextTransform.config = utils.merge(TextTransform.config, options)

if vim.api.nvim_get_vvar("vim_did_enter") == 0 then
vim.defer_fn(function()
Expand All @@ -78,7 +78,7 @@ function config.setup(options)
init()
end

return config.config
return TextTransform.config
end

return config
return TextTransform
Loading

0 comments on commit 33eecff

Please sign in to comment.