Commit cd1c381
authored
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()` function1 parent fe9bbdb commit cd1c381
File tree
9 files changed
+357
-141
lines changed- after/plugin
- doc
- lua/Comment
9 files changed
+357
-141
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
| |||
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
268 | | - | |
| 269 | + | |
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
272 | | - | |
| 273 | + | |
273 | 274 | | |
274 | 275 | | |
275 | 276 | | |
| |||
433 | 434 | | |
434 | 435 | | |
435 | 436 | | |
436 | | - | |
| 437 | + | |
437 | 438 | | |
438 | 439 | | |
439 | 440 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
13 | | - | |
14 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
| 20 | + | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
27 | | - | |
| 26 | + | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
42 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
4 | 7 | | |
5 | 8 | | |
6 | 9 | | |
| |||
142 | 145 | | |
143 | 146 | | |
144 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
145 | 184 | | |
146 | 185 | | |
147 | 186 | | |
| |||
161 | 200 | | |
162 | 201 | | |
163 | 202 | | |
164 | | - | |
| 203 | + | |
165 | 204 | | |
166 | | - | |
| 205 | + | |
167 | 206 | | |
168 | 207 | | |
169 | | - | |
| 208 | + | |
170 | 209 | | |
171 | | - | |
| 210 | + | |
172 | 211 | | |
173 | 212 | | |
174 | 213 | | |
175 | | - | |
| 214 | + | |
176 | 215 | | |
177 | 216 | | |
178 | 217 | | |
179 | | - | |
| 218 | + | |
180 | 219 | | |
181 | 220 | | |
182 | 221 | | |
183 | 222 | | |
184 | | - | |
| 223 | + | |
185 | 224 | | |
186 | 225 | | |
187 | | - | |
| 226 | + | |
188 | 227 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | 5 | | |
10 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
| 24 | + | |
| 25 | + | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| |||
0 commit comments