Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: basic lz.n setup #327

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions docs/manual/hacking/additional-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,62 @@ vim.your-plugin.setupOpts = {
'';
}
```

## Lazy plugins {#sec-lazy-plugins}

If your plugin can be lazy-loaded, you should use `vim.lazy.plugins` to add your plugin. Lazy
plugins are managed by `lz.n`.

```nix
# in modules/.../your-plugin/config.nix
{lib, config, ...}:
let
cfg = config.vim.your-plugin;
in {
vim.lazy.plugins = [
{
# instead of vim.startPlugins, use this:
package = "your-plugin";

# if your plugin uses the `require('your-plugin').setup{...}` pattern
setupModule = "your-plugin";
inherit (cfg) setupOpts;

# events that trigger this plugin to be loaded
events = ["DirChanged"];
cmd = ["YourPluginCommand"];

# keymaps
keys = [
# we'll cover this in detail in the keymaps section
{
key = "<leader>d";
mode = "n";
action = ":YourPluginCommand";
}
]
}
];
}
```

This results in the lua code:
```lua
require('lz.n').load({
{
"name-of-your-plugin",
after = function()
require('your-plugin').setup({--[[ your setupOpts ]]})
end,

events = {"DirChanged"},
cmd = {"YourPluginCommand"},
keys = {
{"<leader>d", ":YourPluginCommand", mode = {"n"}},
},
}
})
```

A full list of options can be found
[here](https://notashelf.github.io/nvf/options.html#opt-vim.lazy.plugins
35 changes: 35 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@
};

## Plugins
# Lazy loading
plugin-lz-n = {
url = "github:nvim-neorocks/lz.n";
flake = false;
};

plugin-lzn-auto-require = {
url = "github:horriblename/lzn-auto-require/require-rewrite";
flake = false;
};

# LSP plugins
plugin-nvim-lspconfig = {
url = "github:neovim/nvim-lspconfig";
Expand Down
24 changes: 24 additions & 0 deletions lib/binds.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@
mkLuaBinding binding.value action binding.description;

pushDownDefault = attr: mapAttrs (_: mkDefault) attr;

mkLznBinding = mode: key: action: desc: {
inherit mode desc key action;
};

mkLznExprBinding = mode: key: action: desc: {
inherit mode desc key action;
lua = true;
silent = true;
expr = true;
};

mkSetLznBinding = binding: action: {
inherit action;
key = binding.value;
desc = binding.description;
};

mkSetLuaLznBinding = binding: action: {
inherit action;
key = binding.value;
lua = true;
desc = binding.description;
};
};
in
binds
5 changes: 1 addition & 4 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@

# built (or "normalized") plugins that are modified
builtStartPlugins = buildConfigPlugins vimOptions.startPlugins;
builtOptPlugins = map (package: {
plugin = package;
optional = true;
}) (buildConfigPlugins vimOptions.optPlugins);
builtOptPlugins = map (package: package // {optional = true;}) (buildConfigPlugins vimOptions.optPlugins);

# additional Lua and Python3 packages, mapped to their respective functions
# to conform to the format mnw expects. end user should
Expand Down
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"build"
"rc"
"warnings"
"lazy"
];

# Extra modules, such as deprecation warnings
Expand Down
8 changes: 8 additions & 0 deletions modules/plugins/comments/comment-nvim/comment-nvim.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{lib, ...}: let
inherit (lib.options) mkEnableOption;
inherit (lib.nvim.binds) mkMappingOption;
inherit (lib.nvim.types) mkPluginSetupOption;
in {
options.vim.comments.comment-nvim = {
enable = mkEnableOption "smart and powerful comment plugin for neovim comment-nvim";
Expand All @@ -15,5 +16,12 @@ in {
toggleSelectedLine = mkMappingOption "Toggle selected comment" "gc";
toggleSelectedBlock = mkMappingOption "Toggle selected block" "gb";
};

setupOpts = mkPluginSetupOption "Comment-nvim" {
mappings = {
basic = mkEnableOption "basic mappings";
extra = mkEnableOption "extra mappings";
};
};
};
}
59 changes: 28 additions & 31 deletions modules/plugins/comments/comment-nvim/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
lib,
...
}: let
inherit (lib.modules) mkIf mkMerge;
inherit (lib.nvim.binds) mkExprBinding mkBinding;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.modules) mkIf;
inherit (lib.nvim.binds) mkLznExprBinding mkLznBinding;

cfg = config.vim.comments.comment-nvim;
self = import ./comment-nvim.nix {inherit lib;};
Expand All @@ -16,35 +15,33 @@ in {
"comment-nvim"
];

vim.maps.normal = mkMerge [
(mkBinding cfg.mappings.toggleOpLeaderLine "<Plug>(comment_toggle_linewise)" mappings.toggleOpLeaderLine.description)
(mkBinding cfg.mappings.toggleOpLeaderBlock "<Plug>(comment_toggle_blockwise)" mappings.toggleOpLeaderBlock.description)
vim.lazy.plugins = [
{
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 ''
function()
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
or '<Plug>(comment_toggle_linewise_count)'
end
''
mappings.toggleCurrentLine.description)
(mkExprBinding cfg.mappings.toggleCurrentBlock ''
function()
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)'
or '<Plug>(comment_toggle_blockwise_count)'
end
''
mappings.toggleCurrentBlock.description)
(mkLznExprBinding ["n"] cfg.mappings.toggleCurrentLine ''
function()
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
or '<Plug>(comment_toggle_linewise_count)'
end
''
mappings.toggleCurrentLine.description)
(mkLznExprBinding ["n"] cfg.mappings.toggleCurrentBlock ''
function()
return vim.api.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)'
or '<Plug>(comment_toggle_blockwise_count)'
end
''
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, },
})
'';
};
}
33 changes: 21 additions & 12 deletions modules/plugins/debugger/nvim-dap/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
inherit (lib.strings) optionalString;
inherit (lib.modules) mkIf mkMerge;
inherit (lib.attrsets) mapAttrs;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding;
inherit (lib.nvim.binds) addDescriptionsToMappings mkSetLuaBinding mkSetLuaLznBinding;
inherit (lib.nvim.dag) entryAnywhere entryAfter;

cfg = config.vim.debugger.nvim-dap;
Expand Down Expand Up @@ -49,24 +49,33 @@ in {
];
})
(mkIf (cfg.enable && cfg.ui.enable) {
vim.startPlugins = ["nvim-dap-ui" "nvim-nio"];
vim.startPlugins = ["nvim-nio"];

vim.pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] (''
local dapui = require("dapui")
dapui.setup()
''
+ optionalString cfg.ui.autoStart ''
vim.lazy.plugins = [
{
package = "nvim-dap-ui";
setupModule = "dapui";
setupOpts = {};

keys = [
(mkSetLuaLznBinding mappings.toggleDapUI "function() require('dapui').toggle() end")
];
}
];

vim.pluginRC.nvim-dap-ui = entryAfter ["nvim-dap"] (
optionalString cfg.ui.autoStart ''
dap.listeners.after.event_initialized["dapui_config"] = function()
dapui.open()
require("dapui").open()
end
dap.listeners.before.event_terminated["dapui_config"] = function()
dapui.close()
require("dapui").close()
end
dap.listeners.before.event_exited["dapui_config"] = function()
dapui.close()
require("dapui").close()
end
'');
vim.maps.normal = mkSetLuaBinding mappings.toggleDapUI "require('dapui').toggle";
''
);
})
];
}
16 changes: 10 additions & 6 deletions modules/plugins/filetree/neo-tree/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
...
}: let
inherit (lib.modules) mkIf;
inherit (lib.nvim.dag) entryAnywhere;
inherit (lib.nvim.lua) toLuaObject;

cfg = config.vim.filetree.neo-tree;
in {
Expand All @@ -20,11 +18,17 @@ in {
"neo-tree-nvim"
];

visuals.nvimWebDevicons.enable = true;
lazy.plugins = [
{
package = "neo-tree-nvim";
setupModule = "neo-tree";
inherit (cfg) setupOpts;

cmd = ["Neotree"];
}
];

pluginRC.neo-tree = entryAnywhere ''
require("neo-tree").setup(${toLuaObject cfg.setupOpts})
'';
visuals.nvimWebDevicons.enable = true;
};
};
}
Loading
Loading