From d9055abe2044f4bf9e81f414215cca81c02cbd72 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 9 Aug 2024 21:32:45 -0500 Subject: [PATCH] plugins/markview: init --- plugins/default.nix | 1 + plugins/languages/markdown/markview.nix | 103 ++++++++++++++++++ .../plugins/languages/markdown/markview.nix | 46 ++++++++ 3 files changed, 150 insertions(+) create mode 100644 plugins/languages/markdown/markview.nix create mode 100644 tests/test-sources/plugins/languages/markdown/markview.nix diff --git a/plugins/default.nix b/plugins/default.nix index 76e38e4d..f45da1f1 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -72,6 +72,7 @@ ./languages/ltex-extra.nix ./languages/markdown/glow.nix ./languages/markdown/markdown-preview.nix + ./languages/markdown/markview.nix ./languages/markdown/preview.nix ./languages/nix.nix ./languages/nvim-jdtls.nix diff --git a/plugins/languages/markdown/markview.nix b/plugins/languages/markdown/markview.nix new file mode 100644 index 00000000..4b95e990 --- /dev/null +++ b/plugins/languages/markdown/markview.nix @@ -0,0 +1,103 @@ +{ + lib, + config, + pkgs, + ... +}: +let + inherit (lib.nixvim) defaultNullOpts; + inherit (lib) types; +in +lib.nixvim.neovim-plugin.mkNeovimPlugin config { + name = "markview"; + originalName = "markview.nvim"; + defaultPackage = pkgs.vimPlugins.markview-nvim; + + maintainers = [ lib.maintainers.khaneliman ]; + + description = '' + An experimental markdown previewer for Neovim. + + Supports a vast amount of rendering customization. + Please refer to the plugin's [documentation](https://github.com/OXY2DEV/markview.nvim/wiki/Configuration-options) for more details. + ''; + + # TODO: remove when https://github.com/NixOS/nixpkgs/pull/333587 is available + extraPlugins = with pkgs.vimPlugins; [ nvim-web-devicons ]; + + settingsOptions = { + buf_ignore = defaultNullOpts.mkListOf types.str [ "nofile" ] '' + Buftypes to disable markview-nvim. + ''; + + mode = + defaultNullOpts.mkListOf types.str + [ + "n" + "no" + ] + '' + Modes where preview is enabled. + ''; + + hybrid_modes = defaultNullOpts.mkListOf types.str null '' + Modes where hybrid mode is enabled. + ''; + + callback = { + on_enable = defaultNullOpts.mkLuaFn' { + pluginDefault = # Lua + '' + function(buf, win) + vim.wo[window].conceallevel = 2; + vim.wo[window].concealcursor = "nc"; + end + ''; + description = '' + Action to perform when markview is enabled. + ''; + }; + + on_disable = defaultNullOpts.mkLuaFn' { + pluginDefault = # Lua + '' + function(buf, win) + vim.wo[window].conceallevel = 0; + vim.wo[window].concealcursor = ""; + end + ''; + description = '' + Action to perform when markview is disabled. + ''; + }; + + on_mode_change = defaultNullOpts.mkLuaFn' { + pluginDefault = # Lua + '' + function(buf, win, mode) + if vim.list_contains(markview.configuration.modes, mode) then + vim.wo[window].conceallevel = 2; + else + vim.wo[window].conceallevel = 0; + end + end + ''; + description = '' + Action to perform when mode is changed, while the plugin is enabled. + ''; + }; + }; + }; + + settingsExample = { + buf_ignore = [ ]; + mode = [ + "n" + "x" + ]; + hybrid_modes = [ + "i" + "r" + ]; + }; +} diff --git a/tests/test-sources/plugins/languages/markdown/markview.nix b/tests/test-sources/plugins/languages/markdown/markview.nix new file mode 100644 index 00000000..5ee06864 --- /dev/null +++ b/tests/test-sources/plugins/languages/markdown/markview.nix @@ -0,0 +1,46 @@ +_: { + empty = { + plugins.markview.enable = true; + }; + + defaults = { + plugins.markview = { + enable = true; + + settings = { + buf_ignore = [ "nofile" ]; + mode = [ + "n" + "no" + ]; + hybrid_modes = [ ]; + callback = { + on_enable = # Lua + '' + function(buf, win) + vim.wo[window].conceallevel = 2; + vim.wo[window].concealcursor = "nc"; + end + ''; + on_disable = # Lua + '' + function(buf, win) + vim.wo[window].conceallevel = 0; + vim.wo[window].concealcursor = ""; + end + ''; + on_mode_change = # Lua + '' + function(buf, win, mode) + if vim.list_contains(markview.configuration.modes, mode) then + vim.wo[window].conceallevel = 2; + else + vim.wo[window].conceallevel = 0; + end + end + ''; + }; + }; + }; + }; +}