Skip to content

Commit 5183816

Browse files
committed
chore!: remove extended keybindings`
1 parent ad7ffa8 commit 5183816

File tree

2 files changed

+48
-91
lines changed

2 files changed

+48
-91
lines changed

lua/Comment/api.lua

-89
Original file line numberDiff line numberDiff line change
@@ -246,93 +246,4 @@ function api.call(cb, op)
246246
end
247247
end
248248

249-
---@private
250-
---Configures the plugin
251-
---@param config? CommentConfig
252-
---@return CommentConfig
253-
function api.setup(config)
254-
local cfg = Config:set(config):get()
255-
256-
if cfg.mappings then
257-
local K = vim.keymap.set
258-
259-
-- Basic Mappings
260-
if cfg.mappings.basic then
261-
-- NORMAL mode mappings
262-
K('n', cfg.opleader.line, '<Plug>(comment_toggle_linewise)', { desc = 'Comment toggle linewise' })
263-
K('n', cfg.opleader.block, '<Plug>(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' })
264-
265-
K('n', cfg.toggler.line, function()
266-
return A.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
267-
or '<Plug>(comment_toggle_linewise_count)'
268-
end, { expr = true, desc = 'Comment toggle current line' })
269-
K('n', cfg.toggler.block, function()
270-
return A.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)'
271-
or '<Plug>(comment_toggle_blockwise_count)'
272-
end, { expr = true, desc = 'Comment toggle current block' })
273-
274-
-- VISUAL mode mappings
275-
K(
276-
'x',
277-
cfg.opleader.line,
278-
'<Plug>(comment_toggle_linewise_visual)',
279-
{ desc = 'Comment toggle linewise (visual)' }
280-
)
281-
K(
282-
'x',
283-
cfg.opleader.block,
284-
'<Plug>(comment_toggle_blockwise_visual)',
285-
{ desc = 'Comment toggle blockwise (visual)' }
286-
)
287-
end
288-
289-
-- Extra Mappings
290-
if cfg.mappings.extra then
291-
K('n', cfg.extra.below, api.insert.linewise.below, { desc = 'Comment insert below' })
292-
K('n', cfg.extra.above, api.insert.linewise.above, { desc = 'Comment insert above' })
293-
K('n', cfg.extra.eol, api.locked('insert.linewise.eol'), { desc = 'Comment insert end of line' })
294-
end
295-
296-
if cfg.mappings.extended then
297-
vim.notify_once(
298-
[=[[Comment] `extended` mappings are deprecated and will be removed on 07 Nov 2022. Please refer to https://github.com/numToStr/Comment.nvim/wiki/Extended-Keybindings on how to define them manually.]=],
299-
vim.log.levels.WARN
300-
)
301-
302-
K('n', 'g>', api.call('comment.linewise', 'g@'), { expr = true, desc = 'Comment region linewise' })
303-
K('n', 'g>c', api.call('comment.linewise.current', 'g@$'), { expr = true, desc = 'Comment current line' })
304-
K('n', 'g>b', api.call('comment.blockwise.current', 'g@$'), { expr = true, desc = 'Comment current block' })
305-
306-
K('n', 'g<', api.call('uncomment.linewise', 'g@'), { expr = true, desc = 'Uncomment region linewise' })
307-
K(
308-
'n',
309-
'g<c',
310-
api.call('uncomment.linewise.current', 'g@$'),
311-
{ expr = true, desc = 'Uncomment current line' }
312-
)
313-
K(
314-
'n',
315-
'g<b',
316-
api.call('uncomment.blockwise.current', 'g@$'),
317-
{ expr = true, desc = 'Uncomment current block' }
318-
)
319-
320-
K(
321-
'x',
322-
'g>',
323-
'<ESC><CMD>lua require("Comment.api").locked("comment.linewise")(vim.fn.visualmode())<CR>',
324-
{ desc = 'Comment region linewise (visual)' }
325-
)
326-
K(
327-
'x',
328-
'g<',
329-
'<ESC><CMD>lua require("Comment.api").locked("uncomment.linewise")(vim.fn.visualmode())<CR>',
330-
{ desc = 'Uncomment region linewise (visual)' }
331-
)
332-
end
333-
end
334-
335-
return cfg
336-
end
337-
338249
return api

lua/Comment/init.lua

+48-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ local C = {}
6767

6868
---Configures the plugin
6969
---@param config? CommentConfig User configuration
70-
---@return CommentConfig #Returns the mutated config
70+
---@return CommentConfig #Returns the modified config
7171
---@see comment.config
7272
---@usage [[
7373
----- Use default configuration
@@ -87,7 +87,53 @@ local C = {}
8787
---})
8888
---@usage ]]
8989
function C.setup(config)
90-
return require('Comment.api').setup(config)
90+
---@diagnostic disable-next-line: invisible
91+
local cfg = require('Comment.config'):set(config):get()
92+
93+
if cfg.mappings then
94+
local api = require('Comment.api')
95+
local vvar = vim.api.nvim_get_vvar
96+
local K = vim.keymap.set
97+
98+
-- Basic Mappings
99+
if cfg.mappings.basic then
100+
-- NORMAL mode mappings
101+
K('n', cfg.opleader.line, '<Plug>(comment_toggle_linewise)', { desc = 'Comment toggle linewise' })
102+
K('n', cfg.opleader.block, '<Plug>(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' })
103+
104+
K('n', cfg.toggler.line, function()
105+
return vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
106+
or '<Plug>(comment_toggle_linewise_count)'
107+
end, { expr = true, desc = 'Comment toggle current line' })
108+
K('n', cfg.toggler.block, function()
109+
return vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)'
110+
or '<Plug>(comment_toggle_blockwise_count)'
111+
end, { expr = true, desc = 'Comment toggle current block' })
112+
113+
-- VISUAL mode mappings
114+
K(
115+
'x',
116+
cfg.opleader.line,
117+
'<Plug>(comment_toggle_linewise_visual)',
118+
{ desc = 'Comment toggle linewise (visual)' }
119+
)
120+
K(
121+
'x',
122+
cfg.opleader.block,
123+
'<Plug>(comment_toggle_blockwise_visual)',
124+
{ desc = 'Comment toggle blockwise (visual)' }
125+
)
126+
end
127+
128+
-- Extra Mappings
129+
if cfg.mappings.extra then
130+
K('n', cfg.extra.below, api.insert.linewise.below, { desc = 'Comment insert below' })
131+
K('n', cfg.extra.above, api.insert.linewise.above, { desc = 'Comment insert above' })
132+
K('n', cfg.extra.eol, api.locked('insert.linewise.eol'), { desc = 'Comment insert end of line' })
133+
end
134+
end
135+
136+
return cfg
91137
end
92138

93139
return C

0 commit comments

Comments
 (0)