Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare Release v0.9.0 #26

Merged
merged 13 commits into from
May 5, 2024
158 changes: 50 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,114 +38,51 @@ with `my_var` or vice versa? This plugin is for you!

## 🔽 Installation

<div>
<table>
<thead>
<tr>
<th>
<img width="221" height="1"/>
Package manager
</th>
<th>
<img width="661" height="1"/>
Snippet
</th>
</tr>
</thead>
<tbody>
<tr>
<td>

[folke/lazy.nvim](https://github.com/folke/lazy.nvim)

</td>
<td>
### [Lazy](https://github.com/folke/lazy.nvim)

```lua
-- stable version
require("lazy").setup({
"chenasraf/text-transform.nvim",
-- stable version
version = "*", -- or: tag = "stable"
dependencies = {
-- for Telescope popup
'nvim-telescope/telescope.nvim',
'nvim-lua/plenary.nvim',
},
})
-- dev version
require("lazy").setup({
"chenasraf/text-transform.nvim",
branch = "develop",
dependencies = {
-- for Telescope popup
'nvim-telescope/telescope.nvim',
'nvim-lua/plenary.nvim',
},
-- dev version
-- branch = "develop",
-- Optional - for Telescope popup
dependencies = { 'nvim-telescope/telescope.nvim', 'nvim-lua/plenary.nvim' }
})
```

</td>
</tr>
<tr>
<td>

[wbthomason/packer.nvim](https://github.com/wbthomason/packer.nvim)

</td>
<td>
### [Packer](https://github.com/wbthomason/packer.nvim)

```lua
-- stable version
use { "chenasraf/text-transform.nvim",
-- stable version
tag = "stable",
requires = {
-- for Telescope popup
'nvim-telescope/telescope.nvim',
'nvim-lua/plenary.nvim',
}
}
-- dev version
use { "chenasraf/text-transform.nvim",
branch = "develop",
requires = {
-- for Telescope popup
'nvim-telescope/telescope.nvim',
'nvim-lua/plenary.nvim',
}
-- dev version
-- branch = "develop",
-- Optional - for Telescope popup
requires = { 'nvim-telescope/telescope.nvim', 'nvim-lua/plenary.nvim' }
}
```

</td>
</tr>
<tr>
<td>

[junegunn/vim-plug](https://github.com/junegunn/vim-plug)

</td>
<td>
### [Plug](https://github.com/junegunn/vim-plug)

```vim
-- Dependencies - for Telescope popup
Plug "nvim-telescope/telescope.nvim"
Plug "nvim-lua/plenary.nvim"

-- stable version
Plug "chenasraf/text-transform.nvim", {
"tag": "stable",
}
-- dev version
Plug "chenasraf/text-transform.nvim", {
"branch": "develop",
}
" Dependencies - optional for Telescope popup
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-lua/plenary.nvim'

" stable version
Plug 'chenasraf/text-transform.nvim', { 'tag': 'stable' }
" dev version
Plug 'chenasraf/text-transform.nvim', { 'branch': 'develop' }
```

</td>
</tr>
If you decide not to use Telescope, you can ignore the dependencies. In that case, be sure to change
your config with `popup_type = 'select'` so that TextTransform never tries to load Telescope.

</tbody>
</table>
</div>
It falls back to `vim.ui.select()` instead, which may or may not still be Telescope behind the
scenes, or something else; depending on your setup.

## 🚀 Getting started

Expand Down Expand Up @@ -207,24 +144,30 @@ require("text-transform").setup({

--- Sort the replacers in the popup.
--- Possible values: 'frequency', 'name'
sort_by = 'frequency',
sort_by = "frequency",

--- The popup type to show.
--- Possible values: 'telescope', 'select'
popup_type = 'telescope'
})
```

## 📝 Commands

The following commands are available for your use in your own mappings or for reference.

| Command | Description |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------ |
| `:TtTelescope` \| `:TextTransform` | Pops up a Telescope window with the available converters which will directly act on the selected text. |
| `:TtCamel` | Replaces selection with `camelCase`. |
| `:TtConst` | Replaces selection with `CONST_CASE`. |
| `:TtDot` | Replaces selection with `dot.case`. |
| `:TtKebab` | Replaces selection with `kebab-case`. |
| `:TtPascal` | Replaces selection with `PascalCase`. |
| `:TtSnake` | Replaces selection with `snake_case`. |
| `:TtTitle` | Replaces selection with `Title Case`. |
| Command | Description |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------- |
| `:TextTransform` | Pop up a either a Telescope window or a selection popup, depending on the `popup_type` config. |
| `:TtTelescope` | Pop up a Telescope window with all the transformers, which will directly act on the selected text or highlighted word. |
| `:TtSelect` | Pop up a selection popup with all the transformers, which will directly act on the selected text or highlighted word. |
| `:TtCamel` | Replace selection/word with `camelCase`. |
| `:TtSnake` | Replace selection/word with `snake_case`. |
| `:TtPascal` | Replace selection/word with `PascalCase`. |
| `:TtConst` | Replace selection/word with `CONST_CASE`. |
| `:TtDot` | Replace selection/word with `dot.case`. |
| `:TtKebab` | Replace selection/word with `kebab-case`. |
| `:TtTitle` | Replace selection/word with `Title Case`. |

## ⌨️⌨️ Keymaps

Expand Down Expand Up @@ -254,17 +197,16 @@ You can also create custom mappings to specific case conversions or to the Teles

```lua
-- Trigger telescope popup
local telescope = require('text-transform.telescope')
vim.keymap.set("n", "<leader>~~", telescope.popup, { silent = true })
vim.keymap.set("n", "<leader>~~", ":TtTelescope", { silent = true, desc = "Transform Text" })

-- Trigger case converters directly
vim.keymap.set({ "n", "v" }, "<leader>Ccc", ":TtCamel", { silent = true })
vim.keymap.set({ "n", "v" }, "<leader>Cco", ":TtConst", { silent = true })
vim.keymap.set({ "n", "v" }, "<leader>Cdo", ":TtDot", { silent = true })
vim.keymap.set({ "n", "v" }, "<leader>Cke", ":TtKebab", { silent = true })
vim.keymap.set({ "n", "v" }, "<leader>Cpa", ":TtPascal", { silent = true })
vim.keymap.set({ "n", "v" }, "<leader>Csn", ":TtSnake", { silent = true })
vim.keymap.set({ "n", "v" }, "<leader>Ctt", ":TtTitle", { silent = true })
vim.keymap.set({ "n", "v" }, "<leader>Ccc", ":TtCamel", { silent = true, desc = "To camelCase" })
vim.keymap.set({ "n", "v" }, "<leader>Csn", ":TtSnake", { silent = true, desc = "To snake_case" })
vim.keymap.set({ "n", "v" }, "<leader>Cpa", ":TtPascal", { silent = true, desc = "To PascalCase" })
vim.keymap.set({ "n", "v" }, "<leader>Cco", ":TtConst", { silent = true, desc = "To CONST_CASE" })
vim.keymap.set({ "n", "v" }, "<leader>Cdo", ":TtDot", { silent = true, desc = "To dot.case" })
vim.keymap.set({ "n", "v" }, "<leader>Cke", ":TtKebab", { silent = true, desc = "To kebab-case" })
vim.keymap.set({ "n", "v" }, "<leader>Ctt", ":TtTitle", { silent = true, desc = "To Title Case" })
```

## 💁🏻 Contributing
Expand Down
13 changes: 7 additions & 6 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
TextTransform.enable() text-transform.txt /*TextTransform.enable()*
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.options text-transform.txt /*TextTransform.options*
TextTransform.popup() text-transform.txt /*TextTransform.popup()*
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.restore_positions() text-transform.txt /*TextTransform.restore_positions()*
TextTransform.save_positions() text-transform.txt /*TextTransform.save_positions()*
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()*
Expand All @@ -17,8 +13,13 @@ 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.toggle() text-transform.txt /*TextTransform.toggle()*
TextTransform.transform_words() text-transform.txt /*TextTransform.transform_words()*
find_word_boundaries() text-transform.txt /*find_word_boundaries()*
init() text-transform.txt /*init()*
state.enable() text-transform.txt /*state.enable()*
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()*
utils.merge() text-transform.txt /*utils.merge()*
51 changes: 22 additions & 29 deletions doc/text-transform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Initializes user commands

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

Default values:
>
TextTransform.options = {
TextTransform.config = {
--- Prints information about internals of the plugin. Very verbose, only useful for debugging.
debug = false,
--- Keymap configurations
Expand Down Expand Up @@ -46,26 +46,19 @@ Default values:
--- Sort the replacers in the popup.
--- Possible values: 'frequency', 'name'
sort_by = "frequency",
}

local function init()
local o = TextTransform.options
D.log("config", "Initializing TextTransform with %s", utils.dump(o))
commands.init_commands()

if o.keymap.telescope_popup then
local keys = o.keymap.telescope_popup
if keys.n then
vim.keymap.set("n", keys.n, telescope.popup, { silent = true })
end
if keys.v then
vim.keymap.set("v", keys.v, telescope.popup, { silent = true })
end
end
end
--- The popup type to show.
--- Possible values: 'telescope', 'select'
popup_type = "telescope",
}

<

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

------------------------------------------------------------------------------
*TextTransform.setup()*
`TextTransform.setup`({options})
Expand Down Expand Up @@ -124,34 +117,34 @@ the full information around the selection logic.

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

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

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

------------------------------------------------------------------------------
*TextTransform.restore_positions()*
`TextTransform.restore_positions`({state})
*state.restore_positions()*
`state.restore_positions`({new_state})
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.popup()*
`TextTransform.popup`()
*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.
Expand Down
33 changes: 29 additions & 4 deletions lua/text-transform/commands.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
-- local D = require("text-transform.util.debug")
local util = require("text-transform.util")
local state = require("text-transform.state")
local replacers = require("text-transform.replacers")
local telescope = require("text-transform.telescope")
local popup = require("text-transform.popup")
local common = require("text-transform.popup_common")
local TextTransform = {}

--- Initializes user commands
Expand All @@ -16,15 +19,37 @@ function TextTransform.init_commands()
TtTitle = "title_case",
}

local cmdopts = { range = true, force = true }
local opts = function(desc)
return util.merge(cmdopts, { desc = desc })
end

for cmd, transformer_name in pairs(map) do
local item
for _, t in ipairs(common.items) do
if t.value == transformer_name then
item = t.label
break
end
end
vim.api.nvim_create_user_command(cmd, function()
state.save_positions()
replacers.replace_selection(transformer_name)
end, {})
end, opts("Change to " .. item))
end

vim.api.nvim_create_user_command("TtTelescope", telescope.popup, {})
vim.api.nvim_create_user_command("TextTransform", telescope.popup, {})
-- specific popups
vim.api.nvim_create_user_command("TtTelescope", function()
local telescope = require("text-transform.telescope")
telescope.telescope_popup()
end, opts("Change Case with Telescope"))
vim.api.nvim_create_user_command("TtSelect", function()
local select = require("text-transform.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
Loading
Loading