Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: new lua API (using metatables) (#183)
This deprecates the old Lua API and will be removed in the next tagged release of the plugin, probably `v0.7.0`. Currently every Lua API is a function call, which is fine, and they are similar to one another having few different arguments. This is not extensible and have slight maintenance burden if we want to create new mode (ref: #17) or introduce new API functions. Using `setmetatable` we can build-up the API as we go. This will be extensible and have less maintenance overhead. Following is the new Lua API: > All API functions are dot repeatable except `*.count()` ```lua require('Comment.api').toggle.linewise() require('Comment.api').toggle.linewise.current() require('Comment.api').toggle.linewise.count() require('Comment.api').toggle.blockwise() require('Comment.api').toggle.blockwise.current() require('Comment.api').toggle.blockwise.count() require('Comment.api').comment.linewise() require('Comment.api').comment.linewise.current() require('Comment.api').comment.linewise.count() require('Comment.api').comment.blockwise() require('Comment.api').comment.blockwise.current() require('Comment.api').comment.blockwise.count() require('Comment.api').uncomment.linewise() require('Comment.api').uncomment.linewise.current() require('Comment.api').uncomment.linewise.count() require('Comment.api').uncomment.blockwise() require('Comment.api').uncomment.blockwise.current() require('Comment.api').uncomment.blockwise.count() ``` > _Old API have proper deprecation message which suggests equivalent New API_ --- This also introduces couple of (breaking) changes apart from the lua API: 1. Rename the following `<Plug>` mappings (to be consistent with API) - `<Plug>(comment_toggle_current_linewise)` -> `<Plug>(comment_toggle_linewise_current)` - `<Plug>(comment_toggle_current_blockwise)` -> `<Plug>(comment_toggle_blockwise_current)` 2. Changed field names of `utils.ctype` object - `U.ctype.line` → `U.ctype.linewise` - `U.ctype.block` → `U.ctype.blockwise` 3. Now `require('Comment.api').locked` is a function which takes the name of the new lua API call (old signature is deprecated) ```lua -- OLD require("Comment.api").locked.toggle_current_linewise() require("Comment.api").locked.comment_linewise_op(vim.fn.visualmode()) -- NEW require("Comment.api").locked('toggle.linewise.current')() require("Comment.api").locked('comment.linewise')(vim.fn.visualmode()) ``` ```vim " NOTE: `locked` interface is just a wrapper around `lockmarks` lockmarks lua require("Comment.api").toggle.linewise.current() ``` 4. Removed redundant `cmotion` (last) argument from `require('Comment.opfunc').opfunc()` function
- Loading branch information
Showing
9 changed files
with
357 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
local K = vim.keymap.set | ||
|
||
-- Count mappings | ||
-- Operator-Pending mappings | ||
K( | ||
'n', | ||
'<Plug>(comment_toggle_linewise_count)', | ||
'<CMD>lua require("Comment.api").call("toggle_linewise_count_op")<CR>g@$', | ||
{ desc = 'Comment toggle linewise with count' } | ||
'<Plug>(comment_toggle_linewise)', | ||
'<CMD>lua require("Comment.api").call("toggle.linewise")<CR>g@', | ||
{ desc = 'Comment toggle linewise' } | ||
) | ||
K( | ||
'n', | ||
'<Plug>(comment_toggle_blockwise_count)', | ||
'<CMD>lua require("Comment.api").call("toggle_blockwise_count_op")<CR>g@$', | ||
{ desc = 'Comment toggle blockwise with count' } | ||
'<Plug>(comment_toggle_blockwise)', | ||
'<CMD>lua require("Comment.api").call("toggle.blockwise")<CR>g@', | ||
{ desc = 'Comment toggle blockwise' } | ||
) | ||
|
||
-- Toggle mappings | ||
K( | ||
'n', | ||
'<Plug>(comment_toggle_current_linewise)', | ||
'<CMD>lua require("Comment.api").call("toggle_current_linewise_op")<CR>g@$', | ||
'<Plug>(comment_toggle_linewise_current)', | ||
'<CMD>lua require("Comment.api").call("toggle.linewise.current")<CR>g@$', | ||
{ desc = 'Comment toggle current line' } | ||
) | ||
K( | ||
'n', | ||
'<Plug>(comment_toggle_current_blockwise)', | ||
'<CMD>lua require("Comment.api").call("toggle_current_blockwise_op")<CR>g@$', | ||
'<Plug>(comment_toggle_blockwise_current)', | ||
'<CMD>lua require("Comment.api").call("toggle.blockwise.current")<CR>g@$', | ||
{ desc = 'Comment toggle current block' } | ||
) | ||
|
||
-- Operator-Pending mappings | ||
-- Count mappings | ||
K( | ||
'n', | ||
'<Plug>(comment_toggle_linewise)', | ||
'<CMD>lua require("Comment.api").call("toggle_linewise_op")<CR>g@', | ||
{ desc = 'Comment toggle linewise' } | ||
'<Plug>(comment_toggle_linewise_count)', | ||
'<CMD>lua require("Comment.api").call("toggle.linewise.count_repeat")<CR>g@$', | ||
{ desc = 'Comment toggle linewise with count' } | ||
) | ||
K( | ||
'n', | ||
'<Plug>(comment_toggle_blockwise)', | ||
'<CMD>lua require("Comment.api").call("toggle_blockwise_op")<CR>g@', | ||
{ desc = 'Comment toggle blockwise' } | ||
'<Plug>(comment_toggle_blockwise_count)', | ||
'<CMD>lua require("Comment.api").call("toggle.blockwise.count_repeat")<CR>g@$', | ||
{ desc = 'Comment toggle blockwise with count' } | ||
) | ||
|
||
-- Visual-Mode mappings | ||
K( | ||
'x', | ||
'<Plug>(comment_toggle_linewise_visual)', | ||
'<ESC><CMD>lua require("Comment.api").locked.toggle_linewise_op(vim.fn.visualmode())<CR>', | ||
'<ESC><CMD>lua require("Comment.api").locked("toggle.linewise")(vim.fn.visualmode())<CR>', | ||
{ desc = 'Comment toggle linewise (visual)' } | ||
) | ||
K( | ||
'x', | ||
'<Plug>(comment_toggle_blockwise_visual)', | ||
'<ESC><CMD>lua require("Comment.api").locked.toggle_blockwise_op(vim.fn.visualmode())<CR>', | ||
'<ESC><CMD>lua require("Comment.api").locked("toggle.blockwise")(vim.fn.visualmode())<CR>', | ||
{ desc = 'Comment toggle blockwise (visual)' } | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.