refactor(nvim): overhaul nix glue and be more lazy

nixos
Moritz Böhme 2023-06-11 10:22:19 +02:00
parent 21bba2e8fd
commit 9a920427a9
Signed by: moritz
GPG Key ID: 970C6E89EB0547A9
5 changed files with 63 additions and 94 deletions

View File

@ -9,7 +9,10 @@ let
cfg = config.my.programs.nvim;
boolToString = bool: if bool then "true" else "false";
quote = str: ''"${toString str}"'';
listToString = list: ''{ ${concatStringsSep ", " (map quote list)} }'';
id = x: x;
listToString = sep: f: list: ''{ ${concatStringsSep sep (map f list)} }'';
listToStringOneLine = listToString ", ";
listToStringMultiLine = listToString ",\n";
keybinding =
{ key
, cmd
@ -42,31 +45,23 @@ let
, priority
, keys
}:
''
{
dir = "${plugin}",
name = "${plugin.name}",
lazy = ${boolToString lazy},
enabled = ${boolToString enabled},
dependencies = { ${concatStringsSep ", " (map lazySpecFromPlugin dependencies)} },
${optionalString (init != null)
"init = function(plugin)
${toString init}
end,"
}
${optionalString (conf != null)
"config = function(plugin, opts)
${toString conf}
end,"
}
keys = { ${concatStringsSep ",\n" (map keybinding keys)} },
event = ${listToString event},
cmd = ${listToString cmd},
ft = ${listToString ft},
priority = ${toString priority},
}
'';
lazySpecs = concatStringsSep ", " (map lazySpecFromPlugin cfg.plugins);
listToStringMultiLine id
([
"dir = ${quote plugin}"
"name = ${quote plugin.name}"
"lazy = ${boolToString lazy}"
]
++ (optional (!enabled) "enabled = ${boolToString enabled}")
++ (optional (dependencies != [ ]) "dependencies = ${listToStringMultiLine id (map lazySpecFromPlugin dependencies)}")
++ (optional (init != null) "init = function(plugin)\n${toString init}\nend")
++ (optional (conf != null) "config = function(plugin, opts)\n${toString conf}\nend")
++ (optional (keys != [ ]) "keys = ${listToStringMultiLine id (map keybinding keys)}")
++ (optional (event != [ ]) "event = ${listToStringOneLine quote event}")
++ (optional (cmd != [ ]) "cmd = ${listToStringOneLine quote cmd}")
++ (optional (ft != [ ]) "ft = ${listToStringOneLine quote ft}")
++ (optional (priority != 50) "priority = ${toString priority}")
);
lazySpecs = listToStringMultiLine id (map lazySpecFromPlugin cfg.plugins);
lazy = ''
require("lazy").setup({
${lazySpecs}
@ -117,7 +112,7 @@ in
};
lazy = mkOption {
type = bool;
default = false;
default = true;
description = ''
Whether to load the plugin lazily.
'';

View File

@ -5,42 +5,46 @@ with builtins;
config.my.programs.nvim.plugins = with pkgs.vimPlugins; [
{
plugin = which-key-nvim;
lazy = false;
conf = readFile ./which-key-nvim.lua;
}
{
plugin = catppuccin-nvim;
conf = readFile ./catppuccin-nvim.lua;
lazy = false;
priority = 99;
}
{
plugin = formatter-nvim;
lazy = true;
keys = [
{ key = "="; cmd = "<cmd>Format<cr>"; desc = "format (formatter)"; }
];
conf = readFile ./formatter-nvim.lua;
dependencies = [{ plugin = which-key-nvim; lazy = true; }];
dependencies = [{ plugin = which-key-nvim; }];
}
{
plugin = oil-nvim;
lazy = false;
conf = readFile ./oil-nvim.lua;
dependencies = [
{ plugin = which-key-nvim; lazy = true; }
{ plugin = nvim-web-devicons; lazy = true; }
{ plugin = which-key-nvim; }
{ plugin = nvim-web-devicons; }
];
}
{ plugin = nvim-ts-context-commentstring; }
{
plugin = mini-nvim;
lazy = false;
conf = readFile ./mini-nvim.lua;
}
{
plugin = noice-nvim;
lazy = false;
conf = readFile ./noice-nvim.lua;
dependencies = [{ plugin = nui-nvim; lazy = true; }];
dependencies = [{ plugin = nui-nvim; }];
}
{
plugin = trouble-nvim;
lazy = true;
keys = [
{ key = "<leader>xx"; cmd = "<cmd>TroubleToggle document_diagnostics<cr>"; desc = "Document Diagnostics (Trouble)"; }
{ key = "<leader>xX"; cmd = "<cmd>TroubleToggle workspace_diagnostics<cr>"; desc = "Workspace Diagnostics (Troule)"; }
@ -75,13 +79,12 @@ with builtins;
conf = readFile ./trouble-nvim.lua;
dependencies = [
{ plugin = which-key-nvim; }
{ plugin = nvim-web-devicons; lazy = true; }
{ plugin = nvim-web-devicons; }
];
}
{
plugin = nvim-cmp;
conf = readFile ./nvim-cmp.lua;
lazy = true;
event = [ "InsertEnter" ];
dependencies = [
{ plugin = cmp-async-path; }
@ -98,131 +101,94 @@ with builtins;
];
}
{ plugin = friendly-snippets; }
{ plugin = luasnip; lazy = true; }
{ plugin = luasnip; }
];
}
{
plugin = todo-comments-nvim;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./todo-comments-nvim.lua;
dependencies = [{ plugin = plenary-nvim; lazy = true; }];
dependencies = [{ plugin = plenary-nvim; }];
}
{
plugin = direnv-vim;
lazy = false;
}
{
plugin = nvim-treesitter.withAllGrammars;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./nvim-treesitter.lua;
dependencies = [
{ plugin = nvim-ts-context-commentstring; }
{
plugin = orgmode;
lazy = true;
conf = readFile ./orgmode.lua;
}
];
}
{
plugin = nvim-lspconfig;
lazy = true;
event = [ "BufReadPre" "BufNewFile" ];
conf = readFile ./nvim-lspconfig.lua;
dependencies = [
{
plugin = null-ls-nvim;
lazy = true;
conf = readFile ./null-ls-nvim.lua;
dependencies = [
{ plugin = which-key-nvim; lazy = true; }
{ plugin = plenary-nvim; lazy = true; }
{ plugin = which-key-nvim; }
{ plugin = plenary-nvim; }
];
}
{
plugin = which-key-nvim;
lazy = true;
}
{
plugin = lspkind-nvim;
lazy = true;
}
{
plugin = lsp_lines-nvim;
lazy = true;
}
{ plugin = which-key-nvim; }
{ plugin = lspkind-nvim; }
{ plugin = lsp_lines-nvim; }
{
plugin = lspsaga-nvim-original;
lazy = true;
dependencies = [
{ plugin = nvim-web-devicons; lazy = true; }
{ plugin = nvim-treesitter.withAllGrammars; lazy = true; }
{ plugin = nvim-web-devicons; }
{ plugin = nvim-treesitter.withAllGrammars; }
];
}
{
plugin = nvim-ufo;
lazy = true;
dependencies = [
{ plugin = promise-async; lazy = true; }
{ plugin = promise-async; }
];
}
];
}
{
event = [ "VeryLazy" ];
lazy = true;
plugin = vim-fugitive;
}
{
plugin = vim-tmux-navigator;
lazy = false;
}
{
plugin = gitsigns-nvim;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./gitsigns-nvim.lua;
dependencies = [{ plugin = which-key-nvim; }];
}
{
plugin = nvim-lastplace;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./nvim-lastplace.lua;
}
{
plugin = nvim-treesitter-textsubjects;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./nvim-treesitter-textsubjects.lua;
dependencies = [
{
plugin = nvim-treesitter.withAllGrammars;
lazy = true;
}
];
}
{
plugin = nvim-ts-context-commentstring;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./nvim-ts-context-commentstring.lua;
dependencies = [
{
plugin = nvim-treesitter.withAllGrammars;
lazy = true;
}
];
}
{
plugin = smartcolumn-nvim;
lazy = true;
event = [ "BufReadPost" "BufNewFile" ];
conf = readFile ./smartcolumn-nvim.lua;
}
{
plugin = telescope-fzf-native-nvim;
conf = readFile ./telescope-fzf-native-nvim.lua;
lazy = true;
keys = [
{ key = "<leader>ff"; cmd = "<cmd>Telescope find_files<cr>"; desc = "Find files"; }
{ key = "<leader>fb"; cmd = "<cmd>Telescope buffers<cr>"; desc = "Find buffers"; }
@ -242,13 +208,17 @@ with builtins;
dependencies = [
{
plugin = telescope-nvim;
lazy = true;
dependencies = [
{ plugin = plenary-nvim; lazy = true; }
{ plugin = which-key-nvim; lazy = true; }
{ plugin = plenary-nvim; }
{ plugin = which-key-nvim; }
];
}
];
}
{
plugin = vim-startuptime;
cmd = [ "StartupTime" ];
conf = readFile ./vim-startuptime.lua;
}
];
}

View File

@ -1,5 +1,11 @@
require("mini.align").setup()
require("mini.comment").setup()
require("mini.comment").setup({
options = {
custom_commentstring = function()
return require("ts_context_commentstring.internal").calculate_commentstring() or vim.bo.commentstring
end,
},
})
require("mini.surround").setup()
require("mini.move").setup()
require("mini.pairs").setup()

View File

@ -9,4 +9,7 @@ require("nvim-treesitter.configs").setup({
-- code block highlights that do not have ts grammar
additional_vim_regex_highlighting = { "org" },
},
context_commentstring = {
enable = true,
},
})

View File

@ -1,5 +0,0 @@
require("nvim-treesitter.configs").setup({
context_commentstring = {
enable = true,
},
})