Skip to content

Commit ea146f4

Browse files
committed
chore: doc update and some tweaks
1 parent c7613b0 commit ea146f4

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

lua/Comment/api.lua

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ local api, core = {}, {}
1515

1616
function core.__index(that, ctype)
1717
local idxd = {}
18+
local mode, type = that.cmode, U.ctype[ctype]
1819

1920
---To comment the current-line
2021
---NOTE:
2122
---In current-line linewise method, 'opmode' is not useful which is always equals to `char`
2223
---but we need 'nil' here which is used for current-line
2324
function idxd.current(_, cfg)
24-
Op.opfunc(nil, cfg or Config:get(), that.cmode, U.ctype[ctype])
25+
Op.opfunc(nil, cfg or Config:get(), mode, type)
2526
end
2627

2728
---To comment lines with a count
2829
function idxd.count(count, cfg)
29-
Op.count(count or A.nvim_get_vvar('count'), cfg or Config:get(), that.cmode, U.ctype[ctype])
30+
Op.count(count or A.nvim_get_vvar('count'), cfg or Config:get(), mode, type)
3031
end
3132

3233
---@private
@@ -36,10 +37,10 @@ function core.__index(that, ctype)
3637
idxd.count(count, cfg)
3738
end
3839

39-
return setmetatable({ cmode = that.cmode, ctype = ctype }, {
40+
return setmetatable({}, {
4041
__index = idxd,
41-
__call = function(this, motion, cfg)
42-
Op.opfunc(motion, cfg or Config:get(), this.cmode, U.ctype[this.ctype])
42+
__call = function(_, motion, cfg)
43+
Op.opfunc(motion, cfg or Config:get(), mode, type)
4344
end,
4445
})
4546
end
@@ -56,8 +57,9 @@ end
5657
---@see comment.config
5758
---@usage [[
5859
---local api = require('Comment.api')
60+
---local config = require('Comment.config'):get()
5961
---
60-
---api.toggle.linewise(motion, config)
62+
---api.toggle.linewise(motion, config?)
6163
---api.toggle.linewise.current(motion?, config?)
6264
---api.toggle.linewise.count(count, config?)
6365
---
@@ -115,8 +117,9 @@ api.toggle = setmetatable({ cmode = U.cmode.toggle }, core)
115117
---@see comment.config
116118
---@usage [[
117119
---local api = require('Comment.api')
120+
---local config = require('Comment.config'):get()
118121
---
119-
---api.comment.linewise(motion, config)
122+
---api.comment.linewise(motion, config?)
120123
---api.comment.linewise.current(motion?, config?)
121124
---api.comment.linewise.count(count, config?)
122125
---
@@ -138,8 +141,9 @@ api.comment = setmetatable({ cmode = U.cmode.comment }, core)
138141
---@see comment.config
139142
---@usage [[
140143
---local api = require('Comment.api')
144+
---local config = require('Comment.config'):get()
141145
---
142-
---api.uncomment.linewise(motion, config)
146+
---api.uncomment.linewise(motion, config?)
143147
---api.uncomment.linewise.current(motion?, config?)
144148
---api.uncomment.linewise.count(count, config?)
145149
---
@@ -155,14 +159,15 @@ api.uncomment = setmetatable({ cmode = U.cmode.uncomment }, core)
155159
---@see comment.config
156160
---@usage [[
157161
---local api = require('Comment.api')
162+
---local config = require('Comment.config'):get()
158163
---
159-
---api.insert.linewise.above(cfg?)
160-
---api.insert.linewise.below(cfg?)
161-
---api.insert.linewise.eol(cfg?)
164+
---api.insert.linewise.above(config?)
165+
---api.insert.linewise.below(config?)
166+
---api.insert.linewise.eol(config?)
162167
---
163-
---api.insert.blockwise.above(cfg?)
164-
---api.insert.blockwise.below(cfg?)
165-
---api.insert.blockwise.eol(cfg?)
168+
---api.insert.blockwise.above(config?)
169+
---api.insert.blockwise.below(config?)
170+
---api.insert.blockwise.eol(config?)
166171
---@usage ]]
167172
api.insert = setmetatable({}, {
168173
__index = function(_, ctype)
@@ -218,7 +223,7 @@ end
218223
--- 2. Preserves jumps and marks
219224
--- 3. Stores last cursor position
220225
---@param cb string Name of the API function to call
221-
---@param op 'g@'|'g@$' Operator string to execute
226+
---@param op '"g@"'|'"g@$"' Operator-mode expression
222227
---@return fun():string #Keymap RHS callback
223228
---@see g@
224229
---@see operatorfunc

lua/Comment/config.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@
4949
---NOTE: If given 'false', then the
5050
---plugin won't create any mappings
5151
---@field mappings Mappings|false
52-
---@field toggler Toggler
53-
---@field opleader Opleader
54-
---@field extra ExtraMapping
52+
---@field toggler Toggler See |comment.config.Toggler|
53+
---@field opleader Opleader See |comment.config.Opleader|
54+
---@field extra ExtraMapping See |comment.config.ExtraMapping|
5555
---Function to call before (un)comment.
5656
---It is called with a {ctx} argument
5757
---of type |comment.utils.CommentCtx|
5858
---(default: 'nil')
59-
---@field pre_hook fun(ctx):string
59+
---@field pre_hook fun(c: CommentCtx): string
6060
---Function to call after (un)comment.
6161
---It is called with a {ctx} argument
6262
---of type |comment.utils.CommentCtx|
6363
---(default: 'nil')
64-
---@field post_hook fun(ctx)
64+
---@field post_hook fun(c: CommentCtx)
6565

6666
---Create default mappings
6767
---@class Mappings

lua/Comment/utils.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ end
191191
---@param scol? integer Starting column
192192
---@param ecol? integer Ending column
193193
---@param tabbed? boolean Using tab indentation
194-
---@return fun(line:string|string[]):string
194+
---@return fun(line: string|string[]):string|string[]
195195
function U.commenter(left, right, padding, scol, ecol, tabbed)
196196
local pad = U.get_pad(padding)
197197
local ll = U.is_empty(left) and left or (left .. pad)
@@ -259,7 +259,7 @@ end
259259
---@param padding boolean Is padding enabled?
260260
---@param scol? integer Starting column
261261
---@param ecol? integer Ending column
262-
---@return fun(line:string|string[]):string
262+
---@return fun(line: string|string[]):string|string[]
263263
function U.uncommenter(left, right, padding, scol, ecol)
264264
local pp, plen = U.get_padpat(padding), padding and 1 or 0
265265
local left_len, right_len = #left + plen, #right + plen
@@ -323,7 +323,7 @@ end
323323
---@param padding boolean Is padding enabled?
324324
---@param scol? integer Starting column
325325
---@param ecol? integer Ending column
326-
---@return fun(line:string|string[]):boolean
326+
---@return fun(line: string|string[]):boolean
327327
function U.is_commented(left, right, padding, scol, ecol)
328328
local pp = U.get_padpat(padding)
329329
local ll = U.is_empty(left) and left or '^%s*' .. vim.pesc(left) .. pp

0 commit comments

Comments
 (0)