mirror of
https://github.com/chenasraf/text-transform.nvim.git
synced 2026-05-18 01:48:57 +00:00
277 lines
11 KiB
Plaintext
277 lines
11 KiB
Plaintext
==============================================================================
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.config*
|
|
`TextTransform.config`
|
|
Your plugin configuration with its default values.
|
|
|
|
Default values:
|
|
>lua
|
|
TextTransform.config = {
|
|
--- Prints information about internals of the plugin. Very verbose, only useful for debugging.
|
|
debug = false,
|
|
--- Keymap configurations
|
|
keymap = {
|
|
--- Keymap to open the telescope popup. Set to `false` or `nil` to disable keymapping
|
|
--- You can always customize your own keymapping manually.
|
|
telescope_popup = {
|
|
--- Opens the popup in normal mode
|
|
["n"] = "<Leader>~",
|
|
--- Opens the popup in visual/visual block modes
|
|
["v"] = "<Leader>~",
|
|
},
|
|
},
|
|
---
|
|
--- Configurations for the text-transform replacers
|
|
--- Keys indicate the replacer name, and the value is a table with the following options:
|
|
---
|
|
--- - `enabled` (boolean): Enable or disable the replacer - disabled replacers do not show up in the popup.
|
|
replacers = {
|
|
camel_case = { enabled = true },
|
|
const_case = { enabled = true },
|
|
dot_case = { enabled = true },
|
|
kebab_case = { enabled = true },
|
|
pascal_case = { enabled = true },
|
|
snake_case = { enabled = true },
|
|
title_case = { enabled = true },
|
|
},
|
|
|
|
--- Sort the replacers in the popup.
|
|
--- Possible values: 'frequency', 'name'
|
|
sort_by = "frequency",
|
|
|
|
--- The popup type to show.
|
|
--- Possible values: 'telescope', 'select'
|
|
popup_type = "telescope",
|
|
}
|
|
|
|
<
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.setup()*
|
|
`TextTransform.setup`({options})
|
|
Define your text-transform setup.
|
|
|
|
Parameters ~
|
|
{options} `(table)` Module config table. See |TextTransform.options|.
|
|
|
|
Usage ~
|
|
`require("text-transform").setup()` (add `{}` with your |TextTransform.options| table)
|
|
|
|
|
|
==============================================================================
|
|
------------------------------------------------------------------------------
|
|
*find_word_boundaries()*
|
|
`find_word_boundaries`({line}, {start_col})
|
|
Finds the boundaries of the surrounding word around `start_col` within `line`.
|
|
Parameters ~
|
|
{line} `(number)`
|
|
{start_col} `(number)`
|
|
Return ~
|
|
`(number)` start_col, number end_col
|
|
|
|
------------------------------------------------------------------------------
|
|
*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.
|
|
|
|
Parameters ~
|
|
{start_line} `(number)` The starting line
|
|
{start_col} `(number)` The starting column
|
|
{end_line} `(number)` The ending line
|
|
{end_col} `(number)` The ending column
|
|
{transform_name} `(string)` The transformer name
|
|
|
|
------------------------------------------------------------------------------
|
|
*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.
|
|
|
|
Parameters ~
|
|
{transform_name} `(string)` The transformer name
|
|
{position} `(table|nil)` A table containing the position of the word to replace
|
|
|
|
------------------------------------------------------------------------------
|
|
*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.
|
|
|
|
Parameters ~
|
|
{transform_name} `(string)` The transformer 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.
|
|
|
|
Parameters ~
|
|
{transform_name} `(string)` The transformer name
|
|
|
|
------------------------------------------------------------------------------
|
|
*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.
|
|
|
|
This allows to treat all ranges equally and allows to work on each selection without knowing
|
|
the full information around the selection logic.
|
|
|
|
|
|
==============================================================================
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.save_positions()*
|
|
`TextTransform.save_positions`()
|
|
Save the current cursor position, mode, and visual selection ranges
|
|
|
|
------------------------------------------------------------------------------
|
|
*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
|
|
|
|
|
|
==============================================================================
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.to_words()*
|
|
`TextTransform.to_words`({string})
|
|
Splits a string into words.
|
|
Parameters ~
|
|
{string} `(string)`
|
|
Return ~
|
|
`(table)`
|
|
|
|
------------------------------------------------------------------------------
|
|
*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.
|
|
|
|
Parameters ~
|
|
{words} `(string|table)` string or table of strings
|
|
{with_word_cb} `(function)` (word: string, index: number, words: table) -> string
|
|
{separator} `(string|nil)` (optional)
|
|
Return ~
|
|
`(string)`
|
|
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.to_camel_case()*
|
|
`TextTransform.to_camel_case`({string})
|
|
Transforms a string into camelCase.
|
|
Parameters ~
|
|
{string} `(string)`
|
|
Return ~
|
|
`(string)`
|
|
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.to_snake_case()*
|
|
`TextTransform.to_snake_case`({string})
|
|
Transfroms a string into snake_case.
|
|
Parameters ~
|
|
{string} `(any)`
|
|
Return ~
|
|
`(string)`
|
|
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.to_pascal_case()*
|
|
`TextTransform.to_pascal_case`({string})
|
|
Transforms a string into PascalCase.
|
|
Parameters ~
|
|
{string} `(string)`
|
|
Return ~
|
|
`(string)`
|
|
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.to_title_case()*
|
|
`TextTransform.to_title_case`({string})
|
|
Transforms a string into Title Case.
|
|
Parameters ~
|
|
{string} `(string)`
|
|
Return ~
|
|
`(string)`
|
|
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.to_kebab_case()*
|
|
`TextTransform.to_kebab_case`({string})
|
|
Transforms a string into kebab-case.
|
|
Parameters ~
|
|
{string} `(string)`
|
|
Return ~
|
|
`(string)`
|
|
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.to_dot_case()*
|
|
`TextTransform.to_dot_case`({string})
|
|
Transforms a string into dot.case.
|
|
Parameters ~
|
|
{string} `(string)`
|
|
Return ~
|
|
`(string)`
|
|
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.to_const_case()*
|
|
`TextTransform.to_const_case`({string})
|
|
Transforms a string into CONSTANT_CASE.
|
|
Parameters ~
|
|
{string} `(string)`
|
|
Return ~
|
|
`(string)`
|
|
|
|
|
|
==============================================================================
|
|
------------------------------------------------------------------------------
|
|
*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.
|
|
|
|
The cursor positions/ranges are saved before opening the menu and restored once a selection is
|
|
made.
|
|
|
|
|
|
==============================================================================
|
|
------------------------------------------------------------------------------
|
|
*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.
|
|
|
|
The cursor positions/ranges are saved before opening the menu and restored once a selection is
|
|
made.
|
|
|
|
|
|
==============================================================================
|
|
------------------------------------------------------------------------------
|
|
*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.
|
|
|
|
The cursor positions/ranges are saved before opening the menu and restored once a selection is
|
|
made.
|
|
|
|
|
|
==============================================================================
|
|
------------------------------------------------------------------------------
|
|
*TextTransform.merge()*
|
|
`TextTransform.merge`({t1}, {t2})
|
|
Merges two tables into one. Same as `vim.tbl_extend("keep", t1, t2)`.
|
|
Mutates the first table.
|
|
|
|
TODO accept multiple tables to merge
|
|
|
|
Parameters ~
|
|
{t1} `(table)`
|
|
{t2} `(table)`
|
|
Return ~
|
|
`(table)`
|
|
|
|
|
|
vim:tw=78:ts=8:noet:ft=help:norl: |