From 82b45c6ae07e95eab4a9d948dbc618664d1460d1 Mon Sep 17 00:00:00 2001 From: Ervin Marasigan Date: Wed, 28 Feb 2024 17:50:48 -0600 Subject: [PATCH 1/2] feat: add line and block configuration --- lua/Comment/config.lua | 8 ++++++ lua/Comment/init.lua | 58 ++++++++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/lua/Comment/config.lua b/lua/Comment/config.lua index 01be20f0..b2bc8cba 100644 --- a/lua/Comment/config.lua +++ b/lua/Comment/config.lua @@ -57,6 +57,12 @@ ---Enable extra mapping; `gco`, `gcO` and `gcA` ---(default: 'true') ---@field extra boolean +---Enable line mapping; `gcc` +---(default: 'true') +---@field line boolean +---Enable block mapping; `gbc` +---(default: 'true') +---@field block boolean ---LHS of toggle mappings in NORMAL ---@class Toggler @@ -86,6 +92,8 @@ local Config = { mappings = { basic = true, extra = true, + line = true, + block = true }, toggler = { line = 'gcc', diff --git a/lua/Comment/init.lua b/lua/Comment/init.lua index 2cdfc7b8..edcc1aae 100644 --- a/lua/Comment/init.lua +++ b/lua/Comment/init.lua @@ -97,31 +97,45 @@ function C.setup(config) -- Basic Mappings if cfg.mappings.basic then -- NORMAL mode mappings - K('n', cfg.opleader.line, '(comment_toggle_linewise)', { desc = 'Comment toggle linewise' }) - K('n', cfg.opleader.block, '(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' }) - K('n', cfg.toggler.line, function() - return vvar('count') == 0 and '(comment_toggle_linewise_current)' - or '(comment_toggle_linewise_count)' - end, { expr = true, desc = 'Comment toggle current line' }) - K('n', cfg.toggler.block, function() - return vvar('count') == 0 and '(comment_toggle_blockwise_current)' - or '(comment_toggle_blockwise_count)' - end, { expr = true, desc = 'Comment toggle current block' }) + if cfg.mappings.line then + K('n', cfg.opleader.line, '(comment_toggle_linewise)', { desc = 'Comment toggle linewise' }) + end + if cfg.mappings.block then + K('n', cfg.opleader.block, '(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' }) + end + + if cfg.mappings.line then + K('n', cfg.toggler.line, function() + return vvar('count') == 0 and '(comment_toggle_linewise_current)' + or '(comment_toggle_linewise_count)' + end, { expr = true, desc = 'Comment toggle current line' }) + end + + if cfg.mappings.block then + K('n', cfg.toggler.block, function() + return vvar('count') == 0 and '(comment_toggle_blockwise_current)' + or '(comment_toggle_blockwise_count)' + end, { expr = true, desc = 'Comment toggle current block' }) + end -- VISUAL mode mappings - K( - 'x', - cfg.opleader.line, - '(comment_toggle_linewise_visual)', - { desc = 'Comment toggle linewise (visual)' } - ) - K( - 'x', - cfg.opleader.block, - '(comment_toggle_blockwise_visual)', - { desc = 'Comment toggle blockwise (visual)' } - ) + if cfg.mappings.line then + K( + 'x', + cfg.opleader.line, + '(comment_toggle_linewise_visual)', + { desc = 'Comment toggle linewise (visual)' } + ) + end + if cfg.mappings.block then + K( + 'x', + cfg.opleader.block, + '(comment_toggle_blockwise_visual)', + { desc = 'Comment toggle blockwise (visual)' } + ) + end end -- Extra Mappings From 4cd281ac30cd56ba7d32336f56cf9502b62dc024 Mon Sep 17 00:00:00 2001 From: Ervin Marasigan Date: Wed, 28 Feb 2024 18:10:31 -0600 Subject: [PATCH 2/2] chore: documentation for line and block mapping --- README.md | 4 ++++ doc/Comment.txt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index 0f8454cd..fcccb44d 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,10 @@ Following are the **default** config for the [`setup()`](#setup). If you want to basic = true, ---Extra mapping; `gco`, `gcO`, `gcA` extra = true, + ---Operator-pending mapping; `gc` gc[count]{motion}` + line = true, + ---Operator-pending mapping; `gbc` `gb[count]{motion}` + block = true, }, ---Function to call before (un)comment pre_hook = nil, diff --git a/doc/Comment.txt b/doc/Comment.txt index 2bf2b641..cf574bfe 100644 --- a/doc/Comment.txt +++ b/doc/Comment.txt @@ -158,6 +158,10 @@ Mappings *comment.config.Mappings* `gc{motion}` and `gb{motion}` (default: 'true') {extra} (boolean) Enable extra mapping; `gco`, `gcO` and `gcA` (default: 'true') + {line} (boolean) Enables operator-pending mapping; `gcc` + `gc{motion}` (default: 'true') + {block} (boolean) Enables operator-pending mapping; `gbc` + `gb{motion}` (default: 'true') Toggler *comment.config.Toggler*