You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: doc/API.md
+48-9Lines changed: 48 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,9 @@
1
1
# ⚙️ API
2
2
3
-
Following are list of APIs that are exported from the plugin. These can be used to setup [custom keybinding](#usage) or to make your own custom comment function. All API functions can take `opmode` (defined below) and a optional [`cfg`](../README.md#config) argument which can be used to override the [default configuration](../README.md#config)
3
+
Following are list of APIs that are exported from the plugin. These can be used to setup [custom keybinding](#usage) or to make your own custom comment function. All API functions can take a `{motion}` (Read `:h :map-operator`) and a optional [`{cfg}`](../README.md#config) argument which can be used to override the [default configuration](../README.md#config)
4
+
5
+
<details>
6
+
<summary>Deprecated API</summary>
4
7
5
8
```lua
6
9
---@aliasOpMode'line'|'char'|'v'|'V' Vim operator-mode motions. Read `:h map-operator`
0 commit comments