Skip to content

Commit

Permalink
refactor: file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
chenasraf committed May 5, 2024
1 parent 1c39528 commit d25f584
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 264 deletions.
40 changes: 20 additions & 20 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
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.replace_columns() text-transform.txt /*TextTransform.replace_columns()*
TextTransform.replace_selection() text-transform.txt /*TextTransform.replace_selection()*
TextTransform.replace_word() text-transform.txt /*TextTransform.replace_word()*
TextTransform.setup() text-transform.txt /*TextTransform.setup()*
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()*
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()*
find_word_boundaries() text-transform.txt /*find_word_boundaries()*
init() text-transform.txt /*init()*
state.enable() text-transform.txt /*state.enable()*
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()*
state.toggle() text-transform.txt /*state.toggle()*
telescope.telescope_popup() text-transform.txt /*telescope.telescope_popup()*
utils.dump() text-transform.txt /*utils.dump()*
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()*
159 changes: 89 additions & 70 deletions doc/text-transform.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
==============================================================================
------------------------------------------------------------------------------
*TextTransform.init_commands()*
`TextTransform.init_commands`()
*commands.init_commands()*
`commands.init_commands`()
Initializes user commands
@private

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


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

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

------------------------------------------------------------------------------
*init()*
`init`()
@internal

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

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

------------------------------------------------------------------------------
*TextTransform.replace_word()*
`TextTransform.replace_word`({transform_name}, {position})
*replacers.replace_range()*
`replacers.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.

@param start_line number The starting line
@param start_col number The starting column
@param end_line number The ending line
@param end_col number The ending column
@param transform_name string The transformer name

------------------------------------------------------------------------------
*replacers.replace_word()*
`replacers.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 @@ -91,23 +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

------------------------------------------------------------------------------
*TextTransform.replace_columns()*
`TextTransform.replace_columns`({transform_name})
*replacers.replace_columns()*
`replacers.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

------------------------------------------------------------------------------
*TextTransform.replace_selection()*
`TextTransform.replace_selection`({transform_name})
*replacers.replace_selection()*
`replacers.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

------------------------------------------------------------------------------
*TextTransform.get_visual_selection_details()*
`TextTransform.get_visual_selection_details`()
*replacers.get_visual_selection_details()*
`replacers.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 @@ -116,23 +131,10 @@ the full information around the selection logic.


==============================================================================
------------------------------------------------------------------------------
*state.toggle()*
`state.toggle`()
Toggle the plugin by calling the `enable`/`disable` methods respectively.
@private

------------------------------------------------------------------------------
*state.enable()*
`state.enable`()
Enables the plugin
@private

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

------------------------------------------------------------------------------
*state.restore_positions()*
Expand All @@ -143,27 +145,15 @@ or a given modified state, if passed as the first argument

==============================================================================
------------------------------------------------------------------------------
*telescope.telescope_popup()*
`telescope.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.

The cursor positions/ranges are saved before opening the menu and restored once a selection is
made.


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

------------------------------------------------------------------------------
*TextTransform.transform_words()*
`TextTransform.transform_words`({words}, {with_word_cb}, {separator})
*transformers.transform_words()*
`transformers.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 @@ -174,55 +164,91 @@ The separator is added between each word.
@return string

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

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

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

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

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

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

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


==============================================================================
------------------------------------------------------------------------------
*popup.show_popup()*
`popup.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.

The cursor positions/ranges are saved before opening the menu and restored once a selection is
made.


==============================================================================
------------------------------------------------------------------------------
*select.select_popup()*
`select.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.

The cursor positions/ranges are saved before opening the menu and restored once a selection is
made.


==============================================================================
------------------------------------------------------------------------------
*telescope.telescope_popup()*
`telescope.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.

The cursor positions/ranges are saved before opening the menu and restored once a selection is
made.


==============================================================================
------------------------------------------------------------------------------
*utils.merge()*
Expand All @@ -236,12 +262,5 @@ TODO accept multiple tables to merge
@param t2 table
@return table

------------------------------------------------------------------------------
*utils.dump()*
`utils.dump`({obj})
Dumps the object into a string.
@param obj any
@return string


vim:tw=78:ts=8:noet:ft=help:norl:
33 changes: 25 additions & 8 deletions lua/text-transform/commands.lua
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
-- local D = require("text-transform.util.debug")
local util = require("text-transform.util")
local D = require("text-transform.utils.debug")
local util = require("text-transform.utils")
local state = require("text-transform.state")
local replacers = require("text-transform.replacers")
local popup = require("text-transform.popup")
local common = require("text-transform.popup_common")
local TextTransform = {}
local common = require("text-transform.popup.common")

local commands = {}

--- Initializes user commands
--- @private
function TextTransform.init_commands()
function commands.init_commands()
local map = {
TtCamel = "camel_case",
TtConst = "const_case",
Expand Down Expand Up @@ -40,16 +41,32 @@ function TextTransform.init_commands()

-- specific popups
vim.api.nvim_create_user_command("TtTelescope", function()
local telescope = require("text-transform.telescope")
local telescope = require("text-transform.popup.telescope")
telescope.telescope_popup()
end, opts("Change Case with Telescope"))
vim.api.nvim_create_user_command("TtSelect", function()
local select = require("text-transform.select")
local select = require("text-transform.popup.select")
select.select_popup()
end, opts("Change Case with Select"))

-- auto popup by config
vim.api.nvim_create_user_command("TextTransform", popup.show_popup, opts("Change Case"))
end

return TextTransform
--- Initializes user keymaps
--- @private
function commands.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
local keys = keymaps.telescope_popup
if keys.n then
vim.keymap.set("n", keys.n, popup.show_popup, { silent = true, desc = "Change Case" })
end
if keys.v then
vim.keymap.set("v", keys.v, popup.show_popup, { silent = true, desc = "Change Case" })
end
end
end

return commands
Loading

0 comments on commit d25f584

Please sign in to comment.