Skip to content

Commit 1c8fa21

Browse files
committed
refactor: file structure
1 parent 1c39528 commit 1c8fa21

19 files changed

+259
-264
lines changed

doc/tags

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
TextTransform.config text-transform.txt /*TextTransform.config*
2-
TextTransform.get_visual_selection_details() text-transform.txt /*TextTransform.get_visual_selection_details()*
3-
TextTransform.init_commands() text-transform.txt /*TextTransform.init_commands()*
4-
TextTransform.replace_columns() text-transform.txt /*TextTransform.replace_columns()*
5-
TextTransform.replace_selection() text-transform.txt /*TextTransform.replace_selection()*
6-
TextTransform.replace_word() text-transform.txt /*TextTransform.replace_word()*
7-
TextTransform.setup() text-transform.txt /*TextTransform.setup()*
8-
TextTransform.to_camel_case() text-transform.txt /*TextTransform.to_camel_case()*
9-
TextTransform.to_const_case() text-transform.txt /*TextTransform.to_const_case()*
10-
TextTransform.to_dot_case() text-transform.txt /*TextTransform.to_dot_case()*
11-
TextTransform.to_kebab_case() text-transform.txt /*TextTransform.to_kebab_case()*
12-
TextTransform.to_pascal_case() text-transform.txt /*TextTransform.to_pascal_case()*
13-
TextTransform.to_snake_case() text-transform.txt /*TextTransform.to_snake_case()*
14-
TextTransform.to_title_case() text-transform.txt /*TextTransform.to_title_case()*
15-
TextTransform.to_words() text-transform.txt /*TextTransform.to_words()*
16-
TextTransform.transform_words() text-transform.txt /*TextTransform.transform_words()*
1+
commands.init_commands() text-transform.txt /*commands.init_commands()*
2+
commands.init_keymaps() text-transform.txt /*commands.init_keymaps()*
3+
config.config text-transform.txt /*config.config*
4+
config.setup() text-transform.txt /*config.setup()*
175
find_word_boundaries() text-transform.txt /*find_word_boundaries()*
18-
init() text-transform.txt /*init()*
19-
state.enable() text-transform.txt /*state.enable()*
6+
popup.show_popup() text-transform.txt /*popup.show_popup()*
7+
replacers.get_visual_selection_details() text-transform.txt /*replacers.get_visual_selection_details()*
8+
replacers.replace_columns() text-transform.txt /*replacers.replace_columns()*
9+
replacers.replace_range() text-transform.txt /*replacers.replace_range()*
10+
replacers.replace_selection() text-transform.txt /*replacers.replace_selection()*
11+
replacers.replace_word() text-transform.txt /*replacers.replace_word()*
12+
select.select_popup() text-transform.txt /*select.select_popup()*
2013
state.restore_positions() text-transform.txt /*state.restore_positions()*
2114
state.save_positions() text-transform.txt /*state.save_positions()*
22-
state.toggle() text-transform.txt /*state.toggle()*
2315
telescope.telescope_popup() text-transform.txt /*telescope.telescope_popup()*
24-
utils.dump() text-transform.txt /*utils.dump()*
16+
transformers.to_camel_case() text-transform.txt /*transformers.to_camel_case()*
17+
transformers.to_const_case() text-transform.txt /*transformers.to_const_case()*
18+
transformers.to_dot_case() text-transform.txt /*transformers.to_dot_case()*
19+
transformers.to_kebab_case() text-transform.txt /*transformers.to_kebab_case()*
20+
transformers.to_pascal_case() text-transform.txt /*transformers.to_pascal_case()*
21+
transformers.to_snake_case() text-transform.txt /*transformers.to_snake_case()*
22+
transformers.to_title_case() text-transform.txt /*transformers.to_title_case()*
23+
transformers.to_words() text-transform.txt /*transformers.to_words()*
24+
transformers.transform_words() text-transform.txt /*transformers.transform_words()*
2525
utils.merge() text-transform.txt /*utils.merge()*

doc/text-transform.txt

+89-70
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
==============================================================================
22
------------------------------------------------------------------------------
3-
*TextTransform.init_commands()*
4-
`TextTransform.init_commands`()
3+
*commands.init_commands()*
4+
`commands.init_commands`()
55
Initializes user commands
66
@private
77

8+
------------------------------------------------------------------------------
9+
*commands.init_keymaps()*
10+
`commands.init_keymaps`()
11+
Initializes user keymaps
12+
@private
13+
814

915
==============================================================================
1016
------------------------------------------------------------------------------
11-
*TextTransform.config*
12-
`TextTransform.config`
17+
*config.config*
18+
`config.config`
1319
Your plugin configuration with its default values.
1420

1521
Default values:
1622
>
17-
TextTransform.config = {
23+
config.config = {
1824
--- Prints information about internals of the plugin. Very verbose, only useful for debugging.
1925
debug = false,
2026
--- Keymap configurations
@@ -55,13 +61,8 @@ Default values:
5561
<
5662

5763
------------------------------------------------------------------------------
58-
*init()*
59-
`init`()
60-
@internal
61-
62-
------------------------------------------------------------------------------
63-
*TextTransform.setup()*
64-
`TextTransform.setup`({options})
64+
*config.setup()*
65+
`config.setup`({options})
6566
Define your text-transform setup.
6667

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

8384
------------------------------------------------------------------------------
84-
*TextTransform.replace_word()*
85-
`TextTransform.replace_word`({transform_name}, {position})
85+
*replacers.replace_range()*
86+
`replacers.replace_range`({start_line}, {start_col}, {end_line}, {end_col}, {transform_name})
87+
Replace the range between the given positions with the given transform.
88+
Acts on the lines between the given positions, replacing the text between the given columns.
89+
90+
@param start_line number The starting line
91+
@param start_col number The starting column
92+
@param end_line number The ending line
93+
@param end_col number The ending column
94+
@param transform_name string The transformer name
95+
96+
------------------------------------------------------------------------------
97+
*replacers.replace_word()*
98+
`replacers.replace_word`({transform_name}, {position})
8699
Replace the word under the cursor with the given transform.
87100
If `position` is provided, replace the word under the given position.
88101
Otherwise, attempts to find the word under the cursor.
@@ -91,23 +104,25 @@ Otherwise, attempts to find the word under the cursor.
91104
@param position table|nil A table containing the position of the word to replace
92105

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

112+
@param transform_name string The transformer name
113+
99114
------------------------------------------------------------------------------
100-
*TextTransform.replace_selection()*
101-
`TextTransform.replace_selection`({transform_name})
115+
*replacers.replace_selection()*
116+
`replacers.replace_selection`({transform_name})
102117
Replaces a selection with the given transform. This function attempts to infer the replacement
103118
type based on the cursor positiono and visual selections, and passes information to relevant
104119
range replacement functions.
105120

106121
@param transform_name string The transformer name
107122

108123
------------------------------------------------------------------------------
109-
*TextTransform.get_visual_selection_details()*
110-
`TextTransform.get_visual_selection_details`()
124+
*replacers.get_visual_selection_details()*
125+
`replacers.get_visual_selection_details`()
111126
Takes the saved positions and translates them into individual visual ranges, regardless of how
112127
the original selection was performed.
113128

@@ -116,23 +131,10 @@ the full information around the selection logic.
116131

117132

118133
==============================================================================
119-
------------------------------------------------------------------------------
120-
*state.toggle()*
121-
`state.toggle`()
122-
Toggle the plugin by calling the `enable`/`disable` methods respectively.
123-
@private
124-
125-
------------------------------------------------------------------------------
126-
*state.enable()*
127-
`state.enable`()
128-
Enables the plugin
129-
@private
130-
131134
------------------------------------------------------------------------------
132135
*state.save_positions()*
133136
`state.save_positions`()
134137
Save the current cursor position, mode, and visual selection ranges
135-
@private
136138

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

144146
==============================================================================
145147
------------------------------------------------------------------------------
146-
*telescope.telescope_popup()*
147-
`telescope.telescope_popup`()
148-
Pops up a telescope menu, containing the available case transformers.
149-
When a transformer is selected, the cursor position/range/columns will be used to replace the
150-
words around the cursor or inside the selection.
151-
152-
The cursor positions/ranges are saved before opening the menu and restored once a selection is
153-
made.
154-
155-
156-
==============================================================================
157-
------------------------------------------------------------------------------
158-
*TextTransform.to_words()*
159-
`TextTransform.to_words`({string})
148+
*transformers.to_words()*
149+
`transformers.to_words`({string})
160150
Splits a string into words.
161151
@param string string
162152
@return table
163153

164154
------------------------------------------------------------------------------
165-
*TextTransform.transform_words()*
166-
`TextTransform.transform_words`({words}, {with_word_cb}, {separator})
155+
*transformers.transform_words()*
156+
`transformers.transform_words`({words}, {with_word_cb}, {separator})
167157
Transforms a table of strings into a string using a callback and separator.
168158
The callback is called with the word, the index, and the table of words.
169159
The separator is added between each word.
@@ -174,55 +164,91 @@ The separator is added between each word.
174164
@return string
175165

176166
------------------------------------------------------------------------------
177-
*TextTransform.to_camel_case()*
178-
`TextTransform.to_camel_case`({string})
167+
*transformers.to_camel_case()*
168+
`transformers.to_camel_case`({string})
179169
Transforms a string into camelCase.
180170
@param string string
181171
@return string
182172

183173
------------------------------------------------------------------------------
184-
*TextTransform.to_snake_case()*
185-
`TextTransform.to_snake_case`({string})
174+
*transformers.to_snake_case()*
175+
`transformers.to_snake_case`({string})
186176
Transfroms a string into snake_case.
187177
@param string any
188178
@return string
189179

190180
------------------------------------------------------------------------------
191-
*TextTransform.to_pascal_case()*
192-
`TextTransform.to_pascal_case`({string})
181+
*transformers.to_pascal_case()*
182+
`transformers.to_pascal_case`({string})
193183
Transforms a string into PascalCase.
194184
@param string string
195185
@return string
196186

197187
------------------------------------------------------------------------------
198-
*TextTransform.to_title_case()*
199-
`TextTransform.to_title_case`({string})
188+
*transformers.to_title_case()*
189+
`transformers.to_title_case`({string})
200190
Transforms a string into Title Case.
201191
@param string string
202192
@return string
203193

204194
------------------------------------------------------------------------------
205-
*TextTransform.to_kebab_case()*
206-
`TextTransform.to_kebab_case`({string})
195+
*transformers.to_kebab_case()*
196+
`transformers.to_kebab_case`({string})
207197
Transforms a string into kebab-case.
208198
@param string string
209199
@return string
210200

211201
------------------------------------------------------------------------------
212-
*TextTransform.to_dot_case()*
213-
`TextTransform.to_dot_case`({string})
202+
*transformers.to_dot_case()*
203+
`transformers.to_dot_case`({string})
214204
Transforms a string into dot.case.
215205
@param string string
216206
@return string
217207

218208
------------------------------------------------------------------------------
219-
*TextTransform.to_const_case()*
220-
`TextTransform.to_const_case`({string})
209+
*transformers.to_const_case()*
210+
`transformers.to_const_case`({string})
221211
Transforms a string into CONSTANT_CASE.
222212
@param string string
223213
@return string
224214

225215

216+
==============================================================================
217+
------------------------------------------------------------------------------
218+
*popup.show_popup()*
219+
`popup.show_popup`()
220+
Pops up a selection menu, containing the available case transformers.
221+
When a transformer is selected, the cursor position/range/columns will be used to replace the
222+
words around the cursor or inside the selection.
223+
224+
The cursor positions/ranges are saved before opening the menu and restored once a selection is
225+
made.
226+
227+
228+
==============================================================================
229+
------------------------------------------------------------------------------
230+
*select.select_popup()*
231+
`select.select_popup`()
232+
Pops up a selection menu, containing the available case transformers.
233+
When a transformer is selected, the cursor position/range/columns will be used to replace the
234+
words around the cursor or inside the selection.
235+
236+
The cursor positions/ranges are saved before opening the menu and restored once a selection is
237+
made.
238+
239+
240+
==============================================================================
241+
------------------------------------------------------------------------------
242+
*telescope.telescope_popup()*
243+
`telescope.telescope_popup`()
244+
Pops up a telescope menu, containing the available case transformers.
245+
When a transformer is selected, the cursor position/range/columns will be used to replace the
246+
words around the cursor or inside the selection.
247+
248+
The cursor positions/ranges are saved before opening the menu and restored once a selection is
249+
made.
250+
251+
226252
==============================================================================
227253
------------------------------------------------------------------------------
228254
*utils.merge()*
@@ -236,12 +262,5 @@ TODO accept multiple tables to merge
236262
@param t2 table
237263
@return table
238264

239-
------------------------------------------------------------------------------
240-
*utils.dump()*
241-
`utils.dump`({obj})
242-
Dumps the object into a string.
243-
@param obj any
244-
@return string
245-
246265

247266
vim:tw=78:ts=8:noet:ft=help:norl:

lua/text-transform/commands.lua

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
-- local D = require("text-transform.util.debug")
2-
local util = require("text-transform.util")
1+
local D = require("text-transform.utils.debug")
2+
local util = require("text-transform.utils")
33
local state = require("text-transform.state")
44
local replacers = require("text-transform.replacers")
55
local popup = require("text-transform.popup")
6-
local common = require("text-transform.popup_common")
7-
local TextTransform = {}
6+
local common = require("text-transform.popup.common")
7+
8+
local commands = {}
89

910
--- Initializes user commands
1011
--- @private
11-
function TextTransform.init_commands()
12+
function commands.init_commands()
1213
local map = {
1314
TtCamel = "camel_case",
1415
TtConst = "const_case",
@@ -40,16 +41,32 @@ function TextTransform.init_commands()
4041

4142
-- specific popups
4243
vim.api.nvim_create_user_command("TtTelescope", function()
43-
local telescope = require("text-transform.telescope")
44+
local telescope = require("text-transform.popup.telescope")
4445
telescope.telescope_popup()
4546
end, opts("Change Case with Telescope"))
4647
vim.api.nvim_create_user_command("TtSelect", function()
47-
local select = require("text-transform.select")
48+
local select = require("text-transform.popup.select")
4849
select.select_popup()
4950
end, opts("Change Case with Select"))
5051

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

55-
return TextTransform
56+
--- Initializes user keymaps
57+
--- @private
58+
function commands.init_keymaps()
59+
local keymaps = _G.TextTransform.config.keymap
60+
D.log("init_keymaps", "Initializing keymaps, config %s", vim.inspect(_G.TextTransform))
61+
if keymaps.telescope_popup then
62+
local keys = keymaps.telescope_popup
63+
if keys.n then
64+
vim.keymap.set("n", keys.n, popup.show_popup, { silent = true, desc = "Change Case" })
65+
end
66+
if keys.v then
67+
vim.keymap.set("v", keys.v, popup.show_popup, { silent = true, desc = "Change Case" })
68+
end
69+
end
70+
end
71+
72+
return commands

0 commit comments

Comments
 (0)