From 73525586231a833a3cf337588d41c5ed1aee96c9 Mon Sep 17 00:00:00 2001 From: Donnerinoern <72634505+Donnerinoern@users.noreply.github.com> Date: Mon, 12 Feb 2024 14:19:27 +0100 Subject: [PATCH 1/3] language/markdown: added markdown-previewer.nvim --- modules/languages/markdown/config.nix | 18 +++++++- modules/languages/markdown/markdown.nix | 56 +++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/modules/languages/markdown/config.nix b/modules/languages/markdown/config.nix index 7084314..4483e76 100644 --- a/modules/languages/markdown/config.nix +++ b/modules/languages/markdown/config.nix @@ -4,7 +4,8 @@ lib, ... }: let - inherit (lib) nvim mkIf mkMerge mkBinding isList; + inherit (lib) nvim mkIf mkMerge mkBinding isList concatMapStringsSep; + inherit (nvim.vim) mkVimBool; cfg = config.vim.languages.markdown; self = import ./markdown.nix { @@ -49,6 +50,21 @@ in { ''; }) + (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 { vim.lsp.lspconfig.enable = true; diff --git a/modules/languages/markdown/markdown.nix b/modules/languages/markdown/markdown.nix index 7c07667..737b635 100644 --- a/modules/languages/markdown/markdown.nix +++ b/modules/languages/markdown/markdown.nix @@ -40,6 +40,62 @@ in { }; }; + 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 = { enable = mkOption { description = "Enable Markdown treesitter"; From 319aaca06d6d1b197d7fb49c6aba9d10e9c99103 Mon Sep 17 00:00:00 2001 From: Donnerinoern <72634505+Donnerinoern@users.noreply.github.com> Date: Tue, 13 Feb 2024 13:33:10 +0100 Subject: [PATCH 2/3] language/markdown: moved glow and markdown-preview to utlity/preview --- modules/languages/markdown/config.nix | 36 +--------- modules/languages/markdown/markdown.nix | 69 +------------------ modules/utility/binds/which-key/config.nix | 2 +- modules/utility/default.nix | 1 + modules/utility/preview/default.nix | 6 ++ modules/utility/preview/glow/config.nix | 28 ++++++++ modules/utility/preview/glow/default.nix | 6 ++ modules/utility/preview/glow/glow.nix | 12 ++++ .../preview/markdown-preview/config.nix | 26 +++++++ .../preview/markdown-preview/default.nix | 6 ++ .../markdown-preview/markdown-preview.nix | 57 +++++++++++++++ 11 files changed, 145 insertions(+), 104 deletions(-) create mode 100644 modules/utility/preview/default.nix create mode 100644 modules/utility/preview/glow/config.nix create mode 100644 modules/utility/preview/glow/default.nix create mode 100644 modules/utility/preview/glow/glow.nix create mode 100644 modules/utility/preview/markdown-preview/config.nix create mode 100644 modules/utility/preview/markdown-preview/default.nix create mode 100644 modules/utility/preview/markdown-preview/markdown-preview.nix diff --git a/modules/languages/markdown/config.nix b/modules/languages/markdown/config.nix index 4483e76..964bb69 100644 --- a/modules/languages/markdown/config.nix +++ b/modules/languages/markdown/config.nix @@ -4,14 +4,9 @@ lib, ... }: let - inherit (lib) nvim mkIf mkMerge mkBinding isList concatMapStringsSep; - inherit (nvim.vim) mkVimBool; + 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; @@ -36,35 +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.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 { vim.lsp.lspconfig.enable = true; diff --git a/modules/languages/markdown/markdown.nix b/modules/languages/markdown/markdown.nix index 737b635..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,73 +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"; - }; - }; - - 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 = { 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..84a9d58 --- /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..d9b4170 --- /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.glow.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..9b128a3 --- /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..a0ae0ed --- /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 "enable 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..9fb1697 --- /dev/null +++ b/modules/utility/preview/markdown-preview/config.nix @@ -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}' + ''; + }; +} diff --git a/modules/utility/preview/markdown-preview/default.nix b/modules/utility/preview/markdown-preview/default.nix new file mode 100644 index 0000000..89904c1 --- /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..4db6c54 --- /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 "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"; + }; + }; + }; +} From 2e0776314965fa39cdc96366d680da72bef19150 Mon Sep 17 00:00:00 2001 From: Donnerinoern <72634505+Donnerinoern@users.noreply.github.com> Date: Tue, 13 Feb 2024 15:45:47 +0100 Subject: [PATCH 3/3] utility/preview: cleanup and optionalString --- modules/utility/preview/default.nix | 2 +- modules/utility/preview/glow/config.nix | 6 +++--- modules/utility/preview/glow/default.nix | 2 +- modules/utility/preview/glow/glow.nix | 2 +- modules/utility/preview/markdown-preview/config.nix | 6 +++--- modules/utility/preview/markdown-preview/default.nix | 2 +- .../utility/preview/markdown-preview/markdown-preview.nix | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/utility/preview/default.nix b/modules/utility/preview/default.nix index 84a9d58..0228395 100644 --- a/modules/utility/preview/default.nix +++ b/modules/utility/preview/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./markdown-preview ./glow diff --git a/modules/utility/preview/glow/config.nix b/modules/utility/preview/glow/config.nix index d9b4170..5b9e14f 100644 --- a/modules/utility/preview/glow/config.nix +++ b/modules/utility/preview/glow/config.nix @@ -16,13 +16,13 @@ in { vim.startPlugins = ["glow-nvim"]; vim.maps.normal = mkMerge [ - (mkBinding cfg.glow.mappings.openPreview ":Glow" mappings.openPreview.description) + (mkBinding cfg.mappings.openPreview ":Glow" mappings.openPreview.description) ]; vim.luaConfigRC.glow = nvim.dag.entryAnywhere '' require('glow').setup({ - glow_path = "${pkgs.glow}/bin/glow" - }); + glow_path = "${pkgs.glow}/bin/glow" + }); ''; }; } diff --git a/modules/utility/preview/glow/default.nix b/modules/utility/preview/glow/default.nix index 9b128a3..6acc82f 100644 --- a/modules/utility/preview/glow/default.nix +++ b/modules/utility/preview/glow/default.nix @@ -1,4 +1,4 @@ -_: { +{ imports = [ ./glow.nix ./config.nix diff --git a/modules/utility/preview/glow/glow.nix b/modules/utility/preview/glow/glow.nix index a0ae0ed..e75547c 100644 --- a/modules/utility/preview/glow/glow.nix +++ b/modules/utility/preview/glow/glow.nix @@ -3,7 +3,7 @@ in { options.vim.utility.preview = { glow = { - enable = mkEnableOption "enable markdown preview in neovim with 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 index 9fb1697..b60f612 100644 --- a/modules/utility/preview/markdown-preview/config.nix +++ b/modules/utility/preview/markdown-preview/config.nix @@ -4,7 +4,7 @@ lib, ... }: let - inherit (lib) nvim mkIf mkMerge concatMapStringsSep; + inherit (lib) nvim mkIf concatMapStringsSep optionalString stringLength; inherit (nvim.vim) mkVimBool; cfg = config.vim.utility.preview.markdownPreview; @@ -19,8 +19,8 @@ in { 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}' + ${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 index 89904c1..dd33aba 100644 --- a/modules/utility/preview/markdown-preview/default.nix +++ b/modules/utility/preview/markdown-preview/default.nix @@ -1,4 +1,4 @@ -_: { +{ 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 index 4db6c54..c3244b0 100644 --- a/modules/utility/preview/markdown-preview/markdown-preview.nix +++ b/modules/utility/preview/markdown-preview/markdown-preview.nix @@ -3,7 +3,7 @@ in { options.vim.utility.preview = { markdownPreview = { - enable = mkEnableOption "enable Markdown preview in neovim with markdown-preview.nvim"; + enable = mkEnableOption "Markdown preview in neovim with markdown-preview.nvim"; autoStart = mkOption { type = types.bool;