diff --git a/modules/languages/markdown/config.nix b/modules/languages/markdown/config.nix index 7084314..964bb69 100644 --- a/modules/languages/markdown/config.nix +++ b/modules/languages/markdown/config.nix @@ -4,13 +4,9 @@ lib, ... }: let - inherit (lib) nvim mkIf mkMerge mkBinding isList; + inherit (lib) nvim mkIf mkMerge isList; cfg = config.vim.languages.markdown; - self = import ./markdown.nix { - inherit lib config pkgs; - }; - mappings = self.options.vim.languages.markdown.glow.mappings; servers = { marksman = { package = pkgs.marksman; @@ -35,20 +31,6 @@ in { 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" mappings.openPreview.description) - ]; - - vim.luaConfigRC.glow = nvim.dag.entryAnywhere '' - require('glow').setup({ - glow_path = "${pkgs.glow}/bin/glow" - }); - ''; - }) - (mkIf cfg.lsp.enable { vim.lsp.lspconfig.enable = true; diff --git a/modules/languages/markdown/markdown.nix b/modules/languages/markdown/markdown.nix index 7c07667..fe272c1 100644 --- a/modules/languages/markdown/markdown.nix +++ b/modules/languages/markdown/markdown.nix @@ -5,7 +5,7 @@ ... }: let inherit (builtins) attrNames; - inherit (lib) mkEnableOption mkMappingOption mkOption types nvim isList; + inherit (lib) mkEnableOption mkOption types nvim isList; cfg = config.vim.languages.markdown; defaultServer = "marksman"; @@ -29,17 +29,6 @@ in { options.vim.languages.markdown = { 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" "p"; - }; - }; - treesitter = { enable = mkOption { description = "Enable Markdown treesitter"; diff --git a/modules/utility/binds/which-key/config.nix b/modules/utility/binds/which-key/config.nix index 9aa123d..6e2a83c 100644 --- a/modules/utility/binds/which-key/config.nix +++ b/modules/utility/binds/which-key/config.nix @@ -113,7 +113,7 @@ in { } ${ - if config.vim.languages.markdown.glow.enable + if config.vim.utility.preview.glow.enable then '' -- Markdown ["pm"] = { name = "+Preview Markdown" }, diff --git a/modules/utility/default.nix b/modules/utility/default.nix index 50ec048..1fbd60a 100644 --- a/modules/utility/default.nix +++ b/modules/utility/default.nix @@ -10,5 +10,6 @@ _: { ./diffview ./wakatime ./surround + ./preview ]; } diff --git a/modules/utility/preview/default.nix b/modules/utility/preview/default.nix new file mode 100644 index 0000000..0228395 --- /dev/null +++ b/modules/utility/preview/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./markdown-preview + ./glow + ]; +} diff --git a/modules/utility/preview/glow/config.nix b/modules/utility/preview/glow/config.nix new file mode 100644 index 0000000..5b9e14f --- /dev/null +++ b/modules/utility/preview/glow/config.nix @@ -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.mappings.openPreview ":Glow" mappings.openPreview.description) + ]; + + vim.luaConfigRC.glow = nvim.dag.entryAnywhere '' + require('glow').setup({ + glow_path = "${pkgs.glow}/bin/glow" + }); + ''; + }; +} diff --git a/modules/utility/preview/glow/default.nix b/modules/utility/preview/glow/default.nix new file mode 100644 index 0000000..6acc82f --- /dev/null +++ b/modules/utility/preview/glow/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./glow.nix + ./config.nix + ]; +} diff --git a/modules/utility/preview/glow/glow.nix b/modules/utility/preview/glow/glow.nix new file mode 100644 index 0000000..e75547c --- /dev/null +++ b/modules/utility/preview/glow/glow.nix @@ -0,0 +1,12 @@ +{lib, ...}: let + inherit (lib) mkEnableOption mkMappingOption; +in { + options.vim.utility.preview = { + glow = { + enable = mkEnableOption "markdown preview in neovim with glow"; + mappings = { + openPreview = mkMappingOption "Open preview" "p"; + }; + }; + }; +} diff --git a/modules/utility/preview/markdown-preview/config.nix b/modules/utility/preview/markdown-preview/config.nix new file mode 100644 index 0000000..b60f612 --- /dev/null +++ b/modules/utility/preview/markdown-preview/config.nix @@ -0,0 +1,26 @@ +{ + pkgs, + config, + lib, + ... +}: let + inherit (lib) nvim mkIf concatMapStringsSep optionalString stringLength; + 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} + ${optionalString (stringLength cfg.customIP > 0) "let g:mkdp_open_ip = '${cfg.customIP}'"} + ${optionalString (stringLength cfg.customPort > 0) "let g:mkdp_port = '${cfg.customPort}'"} + ''; + }; +} diff --git a/modules/utility/preview/markdown-preview/default.nix b/modules/utility/preview/markdown-preview/default.nix new file mode 100644 index 0000000..dd33aba --- /dev/null +++ b/modules/utility/preview/markdown-preview/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./markdown-preview.nix + ./config.nix + ]; +} diff --git a/modules/utility/preview/markdown-preview/markdown-preview.nix b/modules/utility/preview/markdown-preview/markdown-preview.nix new file mode 100644 index 0000000..c3244b0 --- /dev/null +++ b/modules/utility/preview/markdown-preview/markdown-preview.nix @@ -0,0 +1,57 @@ +{lib, ...}: let + inherit (lib) types mkEnableOption mkOption; +in { + options.vim.utility.preview = { + markdownPreview = { + enable = mkEnableOption "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"; + }; + }; + }; +}