diff --git a/plugins/default.nix b/plugins/default.nix index d0928fb5..899e8ff3 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -29,6 +29,7 @@ ./git/neogit.nix ./languages/clangd-extensions.nix + ./languages/julia/julia-cell.nix ./languages/ledger.nix ./languages/markdown-preview.nix ./languages/nix.nix diff --git a/plugins/languages/julia/julia-cell.nix b/plugins/languages/julia/julia-cell.nix new file mode 100644 index 00000000..2daa700e --- /dev/null +++ b/plugins/languages/julia/julia-cell.nix @@ -0,0 +1,114 @@ +{ + pkgs, + lib, + config, + ... +}: let + cfg = config.plugins.julia-cell; + helpers = import ../../helpers.nix {inherit lib;}; + + # The keys are the option name in nixvim (under plugins.julia-cell.keymaps) + # cmd: Such that the mapping action is ':JuliaCell${cmd}' + # desc: The description of the option. + mappings = { + executeCell = { + cmd = "ExecuteCell"; + desc = "executing the current code cell"; + }; + executeCellJump = { + cmd = "ExecuteCellJump"; + desc = "executing the current code cell and jumping to the next cell"; + }; + run = { + cmd = "Run"; + desc = "running the entire file"; + }; + clear = { + cmd = "Clear"; + desc = "clearing the REPL"; + }; + prevCell = { + cmd = "PrevCell"; + desc = "jumping to the previous cell header"; + }; + nextCell = { + cmd = "NextCell"; + desc = "jumping to the next cell header"; + }; + }; +in + with lib; { + options.plugins.julia-cell = { + enable = mkEnableOption "julia-cell"; + + package = helpers.mkPackageOption "julia-cell" pkgs.vimPlugins.vim-julia-cell; + + delimitCellsBy = helpers.defaultNullOpts.mkEnumFirstDefault ["marks" "tags"] '' + Specifies if cells are delimited by 'marks' or 'tags'. + ''; + + tag = helpers.defaultNullOpts.mkStr "##" "Specifies the tag format."; + + extraConfig = mkOption { + type = types.attrs; + default = {}; + description = '' + The configuration options for julia-cell without the 'julia_cell_' prefix. + Example: To set 'julia_cell_foobar' to 1, write + extraConfig = { + foobar = true; + }; + ''; + }; + + keymaps = + { + silent = mkOption { + type = types.bool; + description = "Whether julia-cell keymaps should be silent"; + default = false; + }; + } + // ( + mapAttrs + ( + name: value: + helpers.mkNullOrOption types.str "Keymap for ${value.desc}." + ) + mappings + ); + }; + + config = mkIf cfg.enable { + extraPlugins = [cfg.package]; + + globals = + mapAttrs' + (name: nameValuePair ("julia_cell_" + name)) + ( + { + delimit_cells_by = cfg.delimitCellsBy; + inherit (cfg) tag; + } + // cfg.extraConfig + ); + + maps.normal = mkMerge ( + mapAttrsToList + ( + name: value: let + key = cfg.keymaps.${name}; + in + if key == null + then {} + else { + ${key} = { + action = ":JuliaCell${value.cmd}"; + inherit (cfg.keymaps) silent; + }; + } + ) + mappings + ); + }; + } diff --git a/tests/test-sources/plugins/languages/julia/julia-cell.nix b/tests/test-sources/plugins/languages/julia/julia-cell.nix new file mode 100644 index 00000000..31e4856c --- /dev/null +++ b/tests/test-sources/plugins/languages/julia/julia-cell.nix @@ -0,0 +1,25 @@ +{ + empty = { + plugins.julia-cell.enable = true; + }; + + example = { + plugins.julia-cell = { + enable = true; + + delimitCellsBy = "marks"; + tag = "##"; + + keymaps = { + silent = true; + + executeCell = "a"; + executeCellJump = "b"; + run = "c"; + clear = "d"; + prevCell = "e"; + nextCell = "f"; + }; + }; + }; +}