@@ -303,56 +303,60 @@ end
303
303
---
304
304
--- Following are the API functions that are available:
305
305
---
306
- --- require('Comment.api').toggle.linewise({motion}, {cfg?})
307
- --- require('Comment.api').toggle.linewise.current({motion?}, {cfg?})
308
- --- require('Comment.api').toggle.linewise.count({count}, {cfg?})
306
+ --- require('Comment.api').toggle.linewise({motion}, {cfg?})
307
+ --- require('Comment.api').toggle.linewise.current({motion?}, {cfg?})
308
+ --- require('Comment.api').toggle.linewise.count({count}, {cfg?})
309
309
---
310
- --- require('Comment.api').toggle.blockwise({motion}, {cfg?})
311
- --- require('Comment.api').toggle.blockwise.current({motion?}, {cfg?})
312
- --- require('Comment.api').toggle.blockwise.count({count}, {cfg?})
310
+ --- require('Comment.api').toggle.blockwise({motion}, {cfg?})
311
+ --- require('Comment.api').toggle.blockwise.current({motion?}, {cfg?})
312
+ --- require('Comment.api').toggle.blockwise.count({count}, {cfg?})
313
313
--- @type table A metatable containing API functions
314
+ --- @see comment.config
314
315
api .toggle = setmetatable ({ cmode = U .cmode .toggle }, core )
315
316
316
317
--- API to (only) comment using line or block comment string
317
318
---
318
319
--- Following are the API functions that are available:
319
320
---
320
- --- require('Comment.api').comment.linewise({motion}, {cfg?})
321
- --- require('Comment.api').comment.linewise.current({motion?}, {cfg?})
322
- --- require('Comment.api').comment.linewise.count({count}, {cfg?})
321
+ --- require('Comment.api').comment.linewise({motion}, {cfg?})
322
+ --- require('Comment.api').comment.linewise.current({motion?}, {cfg?})
323
+ --- require('Comment.api').comment.linewise.count({count}, {cfg?})
323
324
---
324
- --- require('Comment.api').comment.blockwise({motion}, {cfg?})
325
- --- require('Comment.api').comment.blockwise.current({motion?}, {cfg?})
326
- --- require('Comment.api').comment.blockwise.count({count}, {cfg?})
325
+ --- require('Comment.api').comment.blockwise({motion}, {cfg?})
326
+ --- require('Comment.api').comment.blockwise.current({motion?}, {cfg?})
327
+ --- require('Comment.api').comment.blockwise.count({count}, {cfg?})
327
328
--- @type table A metatable containing API functions
329
+ --- @see comment.config
328
330
api .comment = setmetatable ({ cmode = U .cmode .comment }, core )
329
331
330
332
--- API to (only) uncomment using line or block comment string
331
333
---
332
334
--- Following are the API functions that are available:
333
335
---
334
- --- require('Comment.api').uncomment.linewise({motion}, {cfg?})
335
- --- require('Comment.api').uncomment.linewise.current({motion?}, {cfg?})
336
- --- require('Comment.api').uncomment.linewise.count({count}, {cfg?})
336
+ --- require('Comment.api').uncomment.linewise({motion}, {cfg?})
337
+ --- require('Comment.api').uncomment.linewise.current({motion?}, {cfg?})
338
+ --- require('Comment.api').uncomment.linewise.count({count}, {cfg?})
337
339
---
338
- --- require('Comment.api').uncomment.blockwise({motion}, {cfg?})
339
- --- require('Comment.api').uncomment.blockwise.current({motion?}, {cfg?})
340
- --- require('Comment.api').uncomment.blockwise.count({count}, {cfg?})
340
+ --- require('Comment.api').uncomment.blockwise({motion}, {cfg?})
341
+ --- require('Comment.api').uncomment.blockwise.current({motion?}, {cfg?})
342
+ --- require('Comment.api').uncomment.blockwise.count({count}, {cfg?})
341
343
--- @type table A metatable containing API functions
344
+ --- @see comment.config
342
345
api .uncomment = setmetatable ({ cmode = U .cmode .comment }, core )
343
346
344
347
--- API to insert comment on previous, next or at the end-of-line
345
348
---
346
349
--- Following are the API functions that are available:
347
350
---
348
- --- require('Comment.api').insert.linewise.above({cfg?})
349
- --- require('Comment.api').insert.linewise.below({cfg?})
350
- --- require('Comment.api').insert.linewise.eol({cfg?})
351
+ --- require('Comment.api').insert.linewise.above({cfg?})
352
+ --- require('Comment.api').insert.linewise.below({cfg?})
353
+ --- require('Comment.api').insert.linewise.eol({cfg?})
351
354
---
352
- --- require('Comment.api').insert.blockwise.above({cfg?})
353
- --- require('Comment.api').insert.blockwise.below({cfg?})
354
- --- require('Comment.api').insert.blockwise.eol({cfg?})
355
+ --- require('Comment.api').insert.blockwise.above({cfg?})
356
+ --- require('Comment.api').insert.blockwise.below({cfg?})
357
+ --- require('Comment.api').insert.blockwise.eol({cfg?})
355
358
--- @type table A metatable containing API functions
359
+ --- @see comment.config
356
360
api .insert = setmetatable ({}, {
357
361
__index = function (_ , ctype )
358
362
return {
@@ -369,17 +373,29 @@ api.insert = setmetatable({}, {
369
373
end ,
370
374
})
371
375
372
- --- Wraps a given function with `lockmarks` to preserve marks/jumps when commenting
376
+ -- TODO: After removing old API
377
+ -- 1. make `api.locked` a simple function call
378
+ -- 2. fix emmylua doc
379
+
380
+ --- Wraps the given API function name with `lockmarks` to preserve marks/jumps
373
381
--- @type fun ( cb : string ): fun ( motion : OpMotion )
374
- --- @usage `require('Comment.api').locked('toggle.linewise.current')()`
382
+ --- @see lockmarks
383
+ --- @usage [[
384
+ --- local api = require('Comment.api')
385
+ --- vim.keymap.set(
386
+ --- 'n', '<leader>c', api.locked('toggle.linewise.current')
387
+ --- )
388
+ --- vim.keymap.set(
389
+ --- 'n', '<leader>o', api.locked('insert.linewise.below')
390
+ --- )
391
+ --- @usage ]]
375
392
api .locked = setmetatable ({}, {
376
393
__index = function (this , cb )
377
394
D (string.format (' locker.%s(args...)' , cb ), string.format (' locked(%q)(args...)' , cb ))
378
395
return this (cb )
379
396
end ,
380
- -- TODO: After removal of the old api functions, make `api.locked` a simple function call
381
397
__call = function (_ , cb )
382
- --- Actual function which will be attached to operatorfunc
398
+ --- operatorfunc callback
383
399
--- @param motion OpMotion
384
400
return function (motion )
385
401
return A .nvim_command (
@@ -390,13 +406,23 @@ api.locked = setmetatable({}, {
390
406
})
391
407
392
408
--- Callback function which does the following
393
- --- 1. Sets operatorfunc for dot-repeat
409
+ --- 1. Sets ' operatorfunc' for dot-repeat
394
410
--- 2. Preserves jumps and marks
395
411
--- 3. Stores last cursor position
396
412
--- @param cb string Name of the API function to call
397
413
--- @param op ' g@' | ' g@$' Operator string to execute
398
414
--- @return fun (): string _ Keymap RHS callback
399
- --- @usage `vim.keymap.set('n', 'gc', api.call('toggle.linewise', 'g@'), { expr = true })`
415
+ --- @usage [[
416
+ --- local api = require('Comment.api')
417
+ --- vim.keymap.set(
418
+ --- 'n', 'gc', api.call('toggle.linewise', 'g@'),
419
+ --- { expr = true }
420
+ --- )
421
+ --- vim.keymap.set(
422
+ --- 'n', 'gcc', api.call('toggle.linewise.current', 'g@$'),
423
+ --- { expr = true }
424
+ --- )
425
+ --- @usage ]]
400
426
function api .call (cb , op )
401
427
return function ()
402
428
A .nvim_set_option (' operatorfunc' , (" v:lua.require'Comment.api'.locked'%s'" ):format (cb ))
0 commit comments