Comment.nvim
Comment.nvim copied to clipboard
feat!: new lua API (using metatables)
TL;DR - If you are not using the Lua API or
<Plug>
mappings then you don't need to worry about anything :)
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()
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:
-
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)
-
-
Changed field names of
utils.ctype
object-
U.ctype.line
→U.ctype.linewise
-
U.ctype.block
→U.ctype.blockwise
-
-
Now
require('Comment.api').locked
is a function which takes the name of the new lua API call (old signature is deprecated)
-- 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())
" NOTE: `locked` interface is just a wrapper around `lockmarks`
lockmarks lua require("Comment.api").toggle.linewise.current()
- Removed redundant
cmotion
(last) argument fromrequire('Comment.opfunc').opfunc()
function
Resolves #180
If anyone finds this destructive, then they can stick with https://github.com/numToStr/Comment.nvim/releases/tag/v0.6.1