diff options
Diffstat (limited to 'lua/lvim/core/comment.lua')
-rw-r--r-- | lua/lvim/core/comment.lua | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/lua/lvim/core/comment.lua b/lua/lvim/core/comment.lua index d07739c6..501d01b6 100644 --- a/lua/lvim/core/comment.lua +++ b/lua/lvim/core/comment.lua @@ -1,27 +1,10 @@ local M = {} function M.config() - local pre_hook = nil - if lvim.builtin.treesitter.context_commentstring.enable then - pre_hook = function(ctx) - local U = require "Comment.utils" - - -- Determine whether to use linewise or blockwise commentstring - local type = ctx.ctype == U.ctype.linewise and "__default" or "__multiline" - - -- Determine the location where to calculate commentstring from - local location = nil - if ctx.ctype == U.ctype.blockwise then - location = require("ts_context_commentstring.utils").get_cursor_location() - elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then - location = require("ts_context_commentstring.utils").get_visual_start_location() - end - - return require("ts_context_commentstring.internal").calculate_commentstring { - key = type, - location = location, - } - end + local pre_hook + local loaded, ts_comment = pcall(require, "ts_context_commentstring.integrations.comment_nvim") + if loaded and ts_comment then + pre_hook = ts_comment.create_pre_hook() end lvim.builtin.comment = { active = true, @@ -30,6 +13,11 @@ function M.config() ---@type boolean padding = true, + ---Whether cursor should stay at the + ---same position. Only works in NORMAL + ---mode mappings + sticky = true, + ---Lines to be ignored while comment/uncomment. ---Could be a regex string or a function that returns a regex string. ---Example: Use '^$' to ignore empty lines @@ -45,9 +33,6 @@ function M.config() ---Extra mapping ---Includes `gco`, `gcO`, `gcA` extra = true, - ---Extended mapping - ---Includes `g>`, `g<`, `g>[count]{motion}` and `g<[count]{motion}` - extended = false, }, ---LHS of line and block comment toggle mapping in NORMAL/VISUAL mode @@ -68,6 +53,17 @@ function M.config() block = "gb", }, + ---LHS of extra mappings + ---@type table + extra = { + ---Add comment on the line above + above = "gcO", + ---Add comment on the line below + below = "gco", + ---Add comment at the end of line + eol = "gcA", + }, + ---Pre-hook, called before commenting the line ---@type function|nil pre_hook = pre_hook, |