mirror of
https://github.com/chenasraf/text-transform.nvim.git
synced 2026-05-18 01:48:57 +00:00
docs: update doc file
This commit is contained in:
2
doc/tags
2
doc/tags
@@ -1,7 +1,5 @@
|
||||
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()*
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
==============================================================================
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.init_commands()*
|
||||
`TextTransform.init_commands`()
|
||||
Initializes user commands
|
||||
@private
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.init_keymaps()*
|
||||
`TextTransform.init_keymaps`()
|
||||
Initializes user keymaps
|
||||
@private
|
||||
|
||||
|
||||
==============================================================================
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.config*
|
||||
@@ -77,9 +63,11 @@ Usage ~
|
||||
*find_word_boundaries()*
|
||||
`find_word_boundaries`({line}, {start_col})
|
||||
Finds the boundaries of the surrounding word around `start_col` within `line`.
|
||||
@param line number
|
||||
@param start_col number
|
||||
@return number start_col, number end_col
|
||||
Parameters ~
|
||||
{line} `(number)`
|
||||
{start_col} `(number)`
|
||||
Return ~
|
||||
`(number)` start_col, number end_col
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.replace_range()*
|
||||
@@ -87,11 +75,12 @@ Finds the boundaries of the surrounding word around `start_col` within `line`.
|
||||
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
|
||||
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()*
|
||||
@@ -100,8 +89,9 @@ 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.
|
||||
|
||||
@param transform_name string The transformer name
|
||||
@param position table|nil A table containing the position of the word to replace
|
||||
Parameters ~
|
||||
{transform_name} `(string)` The transformer name
|
||||
{position} `(table|nil)` A table containing the position of the word to replace
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.replace_columns()*
|
||||
@@ -109,7 +99,8 @@ Otherwise, attempts to find the word under the cursor.
|
||||
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
|
||||
Parameters ~
|
||||
{transform_name} `(string)` The transformer name
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.replace_selection()*
|
||||
@@ -118,7 +109,8 @@ Replaces a selection with the given transform. This function attempts to infer t
|
||||
type based on the cursor positiono and visual selections, and passes information to relevant
|
||||
range replacement functions.
|
||||
|
||||
@param transform_name string The transformer name
|
||||
Parameters ~
|
||||
{transform_name} `(string)` The transformer name
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.get_visual_selection_details()*
|
||||
@@ -148,8 +140,10 @@ or a given modified state, if passed as the first argument
|
||||
*TextTransform.to_words()*
|
||||
`TextTransform.to_words`({string})
|
||||
Splits a string into words.
|
||||
@param string string
|
||||
@return table
|
||||
Parameters ~
|
||||
{string} `(string)`
|
||||
Return ~
|
||||
`(table)`
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.transform_words()*
|
||||
@@ -158,59 +152,75 @@ 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.
|
||||
|
||||
@param words string|table string or table of strings
|
||||
@param with_word_cb function (word: string, index: number, words: table) -> string
|
||||
@param separator string|nil (optional)
|
||||
@return string
|
||||
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.
|
||||
@param string string
|
||||
@return string
|
||||
Parameters ~
|
||||
{string} `(string)`
|
||||
Return ~
|
||||
`(string)`
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.to_snake_case()*
|
||||
`TextTransform.to_snake_case`({string})
|
||||
Transfroms a string into snake_case.
|
||||
@param string any
|
||||
@return string
|
||||
Parameters ~
|
||||
{string} `(any)`
|
||||
Return ~
|
||||
`(string)`
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.to_pascal_case()*
|
||||
`TextTransform.to_pascal_case`({string})
|
||||
Transforms a string into PascalCase.
|
||||
@param string string
|
||||
@return string
|
||||
Parameters ~
|
||||
{string} `(string)`
|
||||
Return ~
|
||||
`(string)`
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.to_title_case()*
|
||||
`TextTransform.to_title_case`({string})
|
||||
Transforms a string into Title Case.
|
||||
@param string string
|
||||
@return string
|
||||
Parameters ~
|
||||
{string} `(string)`
|
||||
Return ~
|
||||
`(string)`
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.to_kebab_case()*
|
||||
`TextTransform.to_kebab_case`({string})
|
||||
Transforms a string into kebab-case.
|
||||
@param string string
|
||||
@return string
|
||||
Parameters ~
|
||||
{string} `(string)`
|
||||
Return ~
|
||||
`(string)`
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.to_dot_case()*
|
||||
`TextTransform.to_dot_case`({string})
|
||||
Transforms a string into dot.case.
|
||||
@param string string
|
||||
@return string
|
||||
Parameters ~
|
||||
{string} `(string)`
|
||||
Return ~
|
||||
`(string)`
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*TextTransform.to_const_case()*
|
||||
`TextTransform.to_const_case`({string})
|
||||
Transforms a string into CONSTANT_CASE.
|
||||
@param string string
|
||||
@return string
|
||||
Parameters ~
|
||||
{string} `(string)`
|
||||
Return ~
|
||||
`(string)`
|
||||
|
||||
|
||||
==============================================================================
|
||||
@@ -258,9 +268,11 @@ Mutates the first table.
|
||||
|
||||
TODO accept multiple tables to merge
|
||||
|
||||
@param t1 table
|
||||
@param t2 table
|
||||
@return table
|
||||
Parameters ~
|
||||
{t1} `(table)`
|
||||
{t2} `(table)`
|
||||
Return ~
|
||||
`(table)`
|
||||
|
||||
|
||||
vim:tw=78:ts=8:noet:ft=help:norl:
|
||||
@@ -7,8 +7,6 @@ local common = require("text-transform.popup.common")
|
||||
|
||||
local TextTransform = {}
|
||||
|
||||
--- Initializes user commands
|
||||
--- @private
|
||||
function TextTransform.init_commands()
|
||||
local map = {
|
||||
TtCamel = "camel_case",
|
||||
@@ -56,8 +54,6 @@ function TextTransform.init_commands()
|
||||
vim.api.nvim_create_user_command("TextTransform", popup.show_popup, opts("Change Case"))
|
||||
end
|
||||
|
||||
--- Initializes user keymaps
|
||||
--- @private
|
||||
function TextTransform.init_keymaps()
|
||||
local keymaps = _G.TextTransform.config.keymap
|
||||
D.log("init_keymaps", "Initializing keymaps, config %s", vim.inspect(_G.TextTransform))
|
||||
|
||||
@@ -5,9 +5,9 @@ local t = require("text-transform.transformers")
|
||||
local TextTransform = {}
|
||||
|
||||
--- Finds the boundaries of the surrounding word around `start_col` within `line`.
|
||||
--- @param line number
|
||||
--- @param start_col number
|
||||
--- @return number start_col, number end_col
|
||||
---@param line number
|
||||
---@param start_col number
|
||||
---@return number start_col, number end_col
|
||||
local function find_word_boundaries(line, start_col)
|
||||
local line_text = vim.fn.getline(line)
|
||||
-- dashes, underscores, and periods are considered part of a word
|
||||
@@ -31,15 +31,15 @@ end
|
||||
--- 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
|
||||
---@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
|
||||
function TextTransform.replace_range(start_line, start_col, end_line, end_col, transform_name)
|
||||
D.log("replace_range", "Replacing range with %s", transform_name)
|
||||
local transform = t["to_" .. transform_name]
|
||||
local lines = vim.fn.getline(start_line, end_line) --- @type any
|
||||
local lines = vim.fn.getline(start_line, end_line) ---@type any
|
||||
local transformed = {}
|
||||
if #lines == 1 then
|
||||
local line = lines[1]
|
||||
@@ -66,8 +66,8 @@ end
|
||||
--- If `position` is provided, replace the word under the given position.
|
||||
--- Otherwise, attempts to find the word under the cursor.
|
||||
---
|
||||
--- @param transform_name string The transformer name
|
||||
--- @param position table|nil A table containing the position of the word to replace
|
||||
---@param transform_name string The transformer name
|
||||
---@param position table|nil A table containing the position of the word to replace
|
||||
function TextTransform.replace_word(transform_name, position)
|
||||
D.log("replace_word", "Replacing word with %s", transform_name)
|
||||
local word, line, col, start_col, end_col
|
||||
@@ -93,7 +93,7 @@ end
|
||||
--- 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
|
||||
---@param transform_name string The transformer name
|
||||
function TextTransform.replace_columns(transform_name)
|
||||
local selections = TextTransform.get_visual_selection_details()
|
||||
D.log("replace_columns", "Replacing columns with %s", transform_name)
|
||||
@@ -106,7 +106,7 @@ end
|
||||
--- type based on the cursor positiono and visual selections, and passes information to relevant
|
||||
--- range replacement functions.
|
||||
---
|
||||
--- @param transform_name string The transformer name
|
||||
---@param transform_name string The transformer name
|
||||
function TextTransform.replace_selection(transform_name)
|
||||
D.log("replace_selection", "Replacing selection with %s", transform_name)
|
||||
-- determine if cursor is a 1-width column across multiple lines or a normal selection
|
||||
|
||||
@@ -6,8 +6,8 @@ local TextTransform = {}
|
||||
TextTransform.WORD_BOUNDRY = "[%_%-%s%.]"
|
||||
|
||||
--- Splits a string into words.
|
||||
--- @param string string
|
||||
--- @return table
|
||||
---@param string string
|
||||
---@return table
|
||||
function TextTransform.to_words(string)
|
||||
local words = {}
|
||||
local word = ""
|
||||
@@ -60,10 +60,10 @@ end
|
||||
--- The callback is called with the word, the index, and the table of words.
|
||||
--- The separator is added between each word.
|
||||
---
|
||||
--- @param words string|table string or table of strings
|
||||
--- @param with_word_cb function (word: string, index: number, words: table) -> string
|
||||
--- @param separator string|nil (optional)
|
||||
--- @return string
|
||||
---@param words string|table string or table of strings
|
||||
---@param with_word_cb function (word: string, index: number, words: table) -> string
|
||||
---@param separator string|nil (optional)
|
||||
---@return string
|
||||
function TextTransform.transform_words(words, with_word_cb, separator)
|
||||
if type(words) ~= "table" then
|
||||
words = TextTransform.to_words(words)
|
||||
@@ -81,8 +81,8 @@ function TextTransform.transform_words(words, with_word_cb, separator)
|
||||
end
|
||||
|
||||
--- Transforms a string into camelCase.
|
||||
--- @param string string
|
||||
--- @return string
|
||||
---@param string string
|
||||
---@return string
|
||||
function TextTransform.to_camel_case(string)
|
||||
return TextTransform.transform_words(string, function(word, i)
|
||||
if i == 1 then
|
||||
@@ -93,8 +93,8 @@ function TextTransform.to_camel_case(string)
|
||||
end
|
||||
|
||||
--- Transfroms a string into snake_case.
|
||||
--- @param string any
|
||||
--- @return string
|
||||
---@param string any
|
||||
---@return string
|
||||
function TextTransform.to_snake_case(string)
|
||||
return TextTransform.transform_words(string, function(word, i)
|
||||
if i == 1 then
|
||||
@@ -105,16 +105,16 @@ function TextTransform.to_snake_case(string)
|
||||
end
|
||||
|
||||
--- Transforms a string into PascalCase.
|
||||
--- @param string string
|
||||
--- @return string
|
||||
---@param string string
|
||||
---@return string
|
||||
function TextTransform.to_pascal_case(string)
|
||||
local cc = TextTransform.to_camel_case(string)
|
||||
return cc:sub(1, 1):upper() .. cc:sub(2)
|
||||
end
|
||||
|
||||
--- Transforms a string into Title Case.
|
||||
--- @param string string
|
||||
--- @return string
|
||||
---@param string string
|
||||
---@return string
|
||||
function TextTransform.to_title_case(string)
|
||||
return TextTransform.transform_words(string, function(word)
|
||||
return word:sub(1, 1):upper() .. word:sub(2):lower()
|
||||
@@ -122,8 +122,8 @@ function TextTransform.to_title_case(string)
|
||||
end
|
||||
|
||||
--- Transforms a string into kebab-case.
|
||||
--- @param string string
|
||||
--- @return string
|
||||
---@param string string
|
||||
---@return string
|
||||
function TextTransform.to_kebab_case(string)
|
||||
return TextTransform.transform_words(string, function(word)
|
||||
return word:lower()
|
||||
@@ -131,8 +131,8 @@ function TextTransform.to_kebab_case(string)
|
||||
end
|
||||
|
||||
--- Transforms a string into dot.case.
|
||||
--- @param string string
|
||||
--- @return string
|
||||
---@param string string
|
||||
---@return string
|
||||
function TextTransform.to_dot_case(string)
|
||||
return TextTransform.transform_words(string, function(word)
|
||||
return word:lower()
|
||||
@@ -140,8 +140,8 @@ function TextTransform.to_dot_case(string)
|
||||
end
|
||||
|
||||
--- Transforms a string into CONSTANT_CASE.
|
||||
--- @param string string
|
||||
--- @return string
|
||||
---@param string string
|
||||
---@return string
|
||||
function TextTransform.to_const_case(string)
|
||||
return TextTransform.transform_words(string, function(word)
|
||||
return word:upper()
|
||||
|
||||
@@ -6,12 +6,6 @@ local function is_debug()
|
||||
and _G.TextTransform.config.debug
|
||||
end
|
||||
|
||||
---prints only if debug is true.
|
||||
---
|
||||
---@param scope string: the scope from where this function is called.
|
||||
---@param str string: the formatted string.
|
||||
---@param ... any: the arguments of the formatted string.
|
||||
---@private
|
||||
function D.log(scope, str, ...)
|
||||
if not is_debug() then
|
||||
return
|
||||
@@ -35,11 +29,6 @@ function D.log(scope, str, ...)
|
||||
)
|
||||
end
|
||||
|
||||
---prints the table if debug is true.
|
||||
---
|
||||
---@param table table: the table to print.
|
||||
---@param indent number?: the default indent value, starts at 0.
|
||||
---@private
|
||||
function D.tprint(table, indent)
|
||||
if not is_debug() then
|
||||
return
|
||||
|
||||
@@ -5,9 +5,9 @@ local TextTransform = {}
|
||||
---
|
||||
--- TODO accept multiple tables to merge
|
||||
---
|
||||
--- @param t1 table
|
||||
--- @param t2 table
|
||||
--- @return table
|
||||
---@param t1 table
|
||||
---@param t2 table
|
||||
---@return table
|
||||
function TextTransform.merge(t1, t2)
|
||||
return vim.tbl_extend("force", t1, t2)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user