language/markdown: moved glow and markdown-preview to utlity/preview

This commit is contained in:
Donnerinoern 2024-02-13 13:33:10 +01:00
parent 7352558623
commit 319aaca06d
11 changed files with 145 additions and 104 deletions

View file

@ -4,14 +4,9 @@
lib, lib,
... ...
}: let }: let
inherit (lib) nvim mkIf mkMerge mkBinding isList concatMapStringsSep; inherit (lib) nvim mkIf mkMerge isList;
inherit (nvim.vim) mkVimBool;
cfg = config.vim.languages.markdown; cfg = config.vim.languages.markdown;
self = import ./markdown.nix {
inherit lib config pkgs;
};
mappings = self.options.vim.languages.markdown.glow.mappings;
servers = { servers = {
marksman = { marksman = {
package = pkgs.marksman; package = pkgs.marksman;
@ -36,35 +31,6 @@ in {
vim.treesitter.grammars = [cfg.treesitter.mdPackage cfg.treesitter.mdInlinePackage]; vim.treesitter.grammars = [cfg.treesitter.mdPackage cfg.treesitter.mdInlinePackage];
}) })
(mkIf cfg.glow.enable {
vim.startPlugins = ["glow-nvim"];
vim.maps.normal = mkMerge [
(mkBinding cfg.glow.mappings.openPreview ":Glow<CR>" mappings.openPreview.description)
];
vim.luaConfigRC.glow = nvim.dag.entryAnywhere ''
require('glow').setup({
glow_path = "${pkgs.glow}/bin/glow"
});
'';
})
(mkIf cfg.markdownPreview.enable {
vim.startPlugins = [pkgs.vimPlugins.markdown-preview-nvim];
vim.configRC.markdown-preview = nvim.dag.entryAnywhere ''
let g:mkdp_auto_start = ${mkVimBool cfg.markdownPreview.autoStart}
let g:mkdp_auto_close = ${mkVimBool cfg.markdownPreview.autoClose}
let g:mkdp_refresh_slow = ${mkVimBool cfg.markdownPreview.lazyRefresh}
let g:mkdp_filetypes = [${concatMapStringsSep ", " (x: "'" + x + "'") cfg.markdownPreview.filetypes}]
let g:mkdp_command_for_global = ${mkVimBool cfg.markdownPreview.alwaysAllowPreview}
let g:mkdp_open_to_the_world = ${mkVimBool cfg.markdownPreview.broadcastServer}
let g:mkdp_open_ip = '${cfg.markdownPreview.customIP}'
let g:mkdp_port = '${cfg.markdownPreview.customPort}'
'';
})
(mkIf cfg.lsp.enable { (mkIf cfg.lsp.enable {
vim.lsp.lspconfig.enable = true; vim.lsp.lspconfig.enable = true;

View file

@ -5,7 +5,7 @@
... ...
}: let }: let
inherit (builtins) attrNames; inherit (builtins) attrNames;
inherit (lib) mkEnableOption mkMappingOption mkOption types nvim isList; inherit (lib) mkEnableOption mkOption types nvim isList;
cfg = config.vim.languages.markdown; cfg = config.vim.languages.markdown;
defaultServer = "marksman"; defaultServer = "marksman";
@ -29,73 +29,6 @@ in {
options.vim.languages.markdown = { options.vim.languages.markdown = {
enable = mkEnableOption "Markdown markup language support"; enable = mkEnableOption "Markdown markup language support";
glow = {
enable = mkOption {
type = types.bool;
default = true;
description = "Enable markdown preview in neovim with glow";
};
mappings = {
openPreview = mkMappingOption "Open preview" "<leader>p";
};
};
markdownPreview = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enable markdown preview in neovim with markdown-preview.nvim";
};
autoStart = mkOption {
type = types.bool;
default = false;
description = "Automatically open the preview window after entering a Markdown buffer";
};
autoClose = mkOption {
type = types.bool;
default = true;
description = "Automatically close the preview window after leaving a Markdown buffer";
};
lazyRefresh = mkOption {
type = types.bool;
default = false;
description = "Only update preview when saving or leaving insert mode";
};
filetypes = mkOption {
type = types.listOf types.str;
default = ["markdown"];
description = "Allowed filetypes";
};
alwaysAllowPreview = mkOption {
type = types.bool;
default = false;
description = "Allow preview on all filetypes";
};
broadcastServer = mkOption {
type = types.bool;
default = false;
description = "Allow for outside and network wide connections";
};
customIP = mkOption {
type = types.str;
default = "";
description = "IP-address to use";
};
customPort = mkOption {
type = types.str;
default = "";
description = "Port to use";
};
};
treesitter = { treesitter = {
enable = mkOption { enable = mkOption {
description = "Enable Markdown treesitter"; description = "Enable Markdown treesitter";

View file

@ -113,7 +113,7 @@ in {
} }
${ ${
if config.vim.languages.markdown.glow.enable if config.vim.utility.preview.glow.enable
then '' then ''
-- Markdown -- Markdown
["<leader>pm"] = { name = "+Preview Markdown" }, ["<leader>pm"] = { name = "+Preview Markdown" },

View file

@ -10,5 +10,6 @@ _: {
./diffview ./diffview
./wakatime ./wakatime
./surround ./surround
./preview
]; ];
} }

View file

@ -0,0 +1,6 @@
_: {
imports = [
./markdown-preview
./glow
];
}

View file

@ -0,0 +1,28 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) nvim mkIf mkMerge mkBinding;
cfg = config.vim.utility.preview.glow;
self = import ./glow.nix {
inherit lib config pkgs;
};
mappings = self.options.vim.utility.preview.glow.mappings;
in {
config = mkIf cfg.enable {
vim.startPlugins = ["glow-nvim"];
vim.maps.normal = mkMerge [
(mkBinding cfg.glow.mappings.openPreview ":Glow<CR>" mappings.openPreview.description)
];
vim.luaConfigRC.glow = nvim.dag.entryAnywhere ''
require('glow').setup({
glow_path = "${pkgs.glow}/bin/glow"
});
'';
};
}

View file

@ -0,0 +1,6 @@
_: {
imports = [
./glow.nix
./config.nix
];
}

View file

@ -0,0 +1,12 @@
{lib, ...}: let
inherit (lib) mkEnableOption mkMappingOption;
in {
options.vim.utility.preview = {
glow = {
enable = mkEnableOption "enable markdown preview in neovim with glow";
mappings = {
openPreview = mkMappingOption "Open preview" "<leader>p";
};
};
};
}

View file

@ -0,0 +1,26 @@
{
pkgs,
config,
lib,
...
}: let
inherit (lib) nvim mkIf mkMerge concatMapStringsSep;
inherit (nvim.vim) mkVimBool;
cfg = config.vim.utility.preview.markdownPreview;
in {
config = mkIf cfg.enable {
vim.startPlugins = [pkgs.vimPlugins.markdown-preview-nvim];
vim.configRC.markdown-preview = nvim.dag.entryAnywhere ''
let g:mkdp_auto_start = ${mkVimBool cfg.autoStart}
let g:mkdp_auto_close = ${mkVimBool cfg.autoClose}
let g:mkdp_refresh_slow = ${mkVimBool cfg.lazyRefresh}
let g:mkdp_filetypes = [${concatMapStringsSep ", " (x: "'" + x + "'") cfg.filetypes}]
let g:mkdp_command_for_global = ${mkVimBool cfg.alwaysAllowPreview}
let g:mkdp_open_to_the_world = ${mkVimBool cfg.broadcastServer}
let g:mkdp_open_ip = '${cfg.customIP}'
let g:mkdp_port = '${cfg.customPort}'
'';
};
}

View file

@ -0,0 +1,6 @@
_: {
imports = [
./markdown-preview.nix
./config.nix
];
}

View file

@ -0,0 +1,57 @@
{lib, ...}: let
inherit (lib) types mkEnableOption mkOption;
in {
options.vim.utility.preview = {
markdownPreview = {
enable = mkEnableOption "enable Markdown preview in neovim with markdown-preview.nvim";
autoStart = mkOption {
type = types.bool;
default = false;
description = "Automatically open the preview window after entering a Markdown buffer";
};
autoClose = mkOption {
type = types.bool;
default = true;
description = "Automatically close the preview window after leaving a Markdown buffer";
};
lazyRefresh = mkOption {
type = types.bool;
default = false;
description = "Only update preview when saving or leaving insert mode";
};
filetypes = mkOption {
type = with types; listOf str;
default = ["markdown"];
description = "Allowed filetypes";
};
alwaysAllowPreview = mkOption {
type = types.bool;
default = false;
description = "Allow preview on all filetypes";
};
broadcastServer = mkOption {
type = types.bool;
default = false;
description = "Allow for outside and network wide connections";
};
customIP = mkOption {
type = types.str;
default = "";
description = "IP-address to use";
};
customPort = mkOption {
type = types.str;
default = "";
description = "Port to use";
};
};
};
}