comment-nvim: lazy load

This commit is contained in:
Ching Pei Yang 2024-10-06 19:34:47 +02:00
parent 283ea5b92c
commit 6ae18403a8
No known key found for this signature in database
GPG key ID: 062FBBCE1D0C5DD9
2 changed files with 36 additions and 31 deletions

View file

@ -1,6 +1,7 @@
{lib, ...}: let {lib, ...}: let
inherit (lib.options) mkEnableOption; inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption; inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in { in {
options.vim.comments.comment-nvim = { options.vim.comments.comment-nvim = {
enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim"; enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim";
@ -15,5 +16,12 @@ in {
toggleSelectedLine = mkMappingOption "Toggle selected comment" "gc"; toggleSelectedLine = mkMappingOption "Toggle selected comment" "gc";
toggleSelectedBlock = mkMappingOption "Toggle selected block" "gb"; toggleSelectedBlock = mkMappingOption "Toggle selected block" "gb";
}; };
setupOpts = mkPluginSetupOption "Comment-nvim" {
mappings = {
basic = mkEnableOption "basic mappings";
extra = mkEnableOption "extra mappings";
};
};
}; };
} }

View file

@ -3,9 +3,8 @@
lib, lib,
... ...
}: let }: let
inherit (lib.modules) mkIf mkMerge; inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkExprBinding mkBinding; inherit (lib.nvim.binds) mkLznExprBinding mkLznBinding;
inherit (lib.nvim.dag) entryAnywhere;
cfg = config.vim.comments.comment-nvim; cfg = config.vim.comments.comment-nvim;
self = import ./comment-nvim.nix {inherit lib;}; self = import ./comment-nvim.nix {inherit lib;};
@ -16,35 +15,33 @@ in {
"comment-nvim" "comment-nvim"
]; ];
vim.maps.normal = mkMerge [ vim.lazy.plugins = [
(mkBinding cfg.mappings.toggleOpLeaderLine "<Plug>(comment_toggle_linewise)" mappings.toggleOpLeaderLine.description) {
(mkBinding cfg.mappings.toggleOpLeaderBlock "<Plug>(comment_toggle_blockwise)" mappings.toggleOpLeaderBlock.description) package = "comment-nvim";
setupModule = "Comment";
inherit (cfg) setupOpts;
keys = [
(mkLznBinding ["n"] cfg.mappings.toggleOpLeaderLine "<Plug>(comment_toggle_linewise)" mappings.toggleOpLeaderLine.description)
(mkLznBinding ["n"] cfg.mappings.toggleOpLeaderBlock "<Plug>(comment_toggle_blockwise)" mappings.toggleOpLeaderBlock.description)
(mkExprBinding cfg.mappings.toggleCurrentLine '' (mkLznExprBinding ["n"] cfg.mappings.toggleCurrentLine ''
function() function()
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)' return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
or '<Plug>(comment_toggle_linewise_count)' or '<Plug>(comment_toggle_linewise_count)'
end end
'' ''
mappings.toggleCurrentLine.description) mappings.toggleCurrentLine.description)
(mkExprBinding cfg.mappings.toggleCurrentBlock '' (mkLznExprBinding ["n"] cfg.mappings.toggleCurrentBlock ''
function() function()
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)' return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)'
or '<Plug>(comment_toggle_blockwise_count)' or '<Plug>(comment_toggle_blockwise_count)'
end end
'' ''
mappings.toggleCurrentBlock.description) mappings.toggleCurrentBlock.description)
(mkLznBinding ["x"] cfg.mappings.toggleSelectedLine "<Plug>(comment_toggle_linewise_visual)" mappings.toggleSelectedLine.description)
(mkLznBinding ["x"] cfg.mappings.toggleSelectedBlock "<Plug>(comment_toggle_blockwise_visual)" mappings.toggleSelectedBlock.description)
]; ];
}
vim.maps.visualOnly = mkMerge [
(mkBinding cfg.mappings.toggleSelectedLine "<Plug>(comment_toggle_linewise_visual)" mappings.toggleSelectedLine.description)
(mkBinding cfg.mappings.toggleSelectedBlock "<Plug>(comment_toggle_blockwise_visual)" mappings.toggleSelectedBlock.description)
]; ];
vim.pluginRC.comment-nvim = entryAnywhere ''
require('Comment').setup({
mappings = { basic = false, extra = false, },
})
'';
}; };
} }