From 94be9167d230d4cd6339744a4503069ed7526c9f Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 4 Feb 2023 01:46:34 +0300 Subject: [PATCH] feat: relocate whichkey and add cheatsheet.nvim --- modules/binds/cheatsheet.nix | 22 +++++++ modules/binds/default.nix | 11 ++++ modules/binds/which-key.nix | 20 ++++++ modules/keys/default.nix | 6 -- modules/keys/which-key.nix | 24 ------- modules/lib/dag.nix | 114 +++++++++++++++++----------------- modules/lib/types-plugin.nix | 2 + modules/modules.nix | 3 +- modules/utility/colorizer.nix | 24 +++++++ modules/utility/default.nix | 5 ++ 10 files changed, 144 insertions(+), 87 deletions(-) create mode 100644 modules/binds/cheatsheet.nix create mode 100644 modules/binds/default.nix create mode 100644 modules/binds/which-key.nix delete mode 100644 modules/keys/default.nix delete mode 100644 modules/keys/which-key.nix create mode 100644 modules/utility/colorizer.nix create mode 100644 modules/utility/default.nix diff --git a/modules/binds/cheatsheet.nix b/modules/binds/cheatsheet.nix new file mode 100644 index 0000000..2e18691 --- /dev/null +++ b/modules/binds/cheatsheet.nix @@ -0,0 +1,22 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; +with builtins; let + cfg = config.vim.binds.cheatsheet; +in { + options.vim.binds.cheatsheet = { + enable = mkEnableOption "Searchable cheatsheet for nvim using telescope"; + }; + + config = mkIf (cfg.enable) { + vim.startPlugins = ["cheatsheet-nvim"]; + + vim.luaConfigRC.cheaetsheet-nvim = nvim.dag.entryAnywhere '' + require('cheatsheet').setup({}) + ''; + }; +} diff --git a/modules/binds/default.nix b/modules/binds/default.nix new file mode 100644 index 0000000..9dd64ac --- /dev/null +++ b/modules/binds/default.nix @@ -0,0 +1,11 @@ +{ + config, + lib, + pkgs, + ... +}: { + imports = [ + ./which-key.nix + ./cheatsheet.nix + ]; +} diff --git a/modules/binds/which-key.nix b/modules/binds/which-key.nix new file mode 100644 index 0000000..ef9fdf6 --- /dev/null +++ b/modules/binds/which-key.nix @@ -0,0 +1,20 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; +with builtins; let + cfg = config.vim.binds.whichKey; +in { + options.vim.binds.whichKey = { + enable = mkEnableOption "which-key menu"; + }; + + config = mkIf (cfg.enable) { + vim.startPlugins = ["which-key"]; + + vim.luaConfigRC.whichkey = nvim.dag.entryAnywhere ''local wk = require("which-key").setup {}''; + }; +} diff --git a/modules/keys/default.nix b/modules/keys/default.nix deleted file mode 100644 index 5f5b71a..0000000 --- a/modules/keys/default.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: {imports = [./which-key.nix];} diff --git a/modules/keys/which-key.nix b/modules/keys/which-key.nix deleted file mode 100644 index 0a8d145..0000000 --- a/modules/keys/which-key.nix +++ /dev/null @@ -1,24 +0,0 @@ -{ - pkgs, - config, - lib, - ... -}: -with lib; -with builtins; let - cfg = config.vim.keys; -in { - options.vim.keys = { - enable = mkEnableOption "key binding plugins"; - - whichKey = { - enable = mkEnableOption "which-key menu"; - }; - }; - - config = mkIf (cfg.enable && cfg.whichKey.enable) { - vim.startPlugins = ["which-key"]; - - vim.luaConfigRC.whichkey = nvim.dag.entryAnywhere ''local wk = require("which-key").setup {}''; - }; -} diff --git a/modules/lib/dag.nix b/modules/lib/dag.nix index d6cc871..0b392f9 100644 --- a/modules/lib/dag.nix +++ b/modules/lib/dag.nix @@ -16,62 +16,64 @@ in { isDag = dag: builtins.isAttrs dag && all nvim.dag.isEntry (builtins.attrValues dag); - # Takes an attribute set containing entries built by entryAnywhere, - # entryAfter, and entryBefore to a topologically sorted list of - # entries. - # - # Internally this function uses the `toposort` function in - # `` and its value is accordingly. - # - # Specifically, the result on success is - # - # { result = [ { name = ?; data = ?; } … ] } - # - # For example - # - # nix-repl> topoSort { - # a = entryAnywhere "1"; - # b = entryAfter [ "a" "c" ] "2"; - # c = entryBefore [ "d" ] "3"; - # d = entryBefore [ "e" ] "4"; - # e = entryAnywhere "5"; - # } == { - # result = [ - # { data = "1"; name = "a"; } - # { data = "3"; name = "c"; } - # { data = "2"; name = "b"; } - # { data = "4"; name = "d"; } - # { data = "5"; name = "e"; } - # ]; - # } - # true - # - # And the result on error is - # - # { - # cycle = [ { after = ?; name = ?; data = ? } … ]; - # loops = [ { after = ?; name = ?; data = ? } … ]; - # } - # - # For example - # - # nix-repl> topoSort { - # a = entryAnywhere "1"; - # b = entryAfter [ "a" "c" ] "2"; - # c = entryAfter [ "d" ] "3"; - # d = entryAfter [ "b" ] "4"; - # e = entryAnywhere "5"; - # } == { - # cycle = [ - # { after = [ "a" "c" ]; data = "2"; name = "b"; } - # { after = [ "d" ]; data = "3"; name = "c"; } - # { after = [ "b" ]; data = "4"; name = "d"; } - # ]; - # loops = [ - # { after = [ "a" "c" ]; data = "2"; name = "b"; } - # ]; - # } - # true + /* + Takes an attribute set containing entries built by entryAnywhere, + entryAfter, and entryBefore to a topologically sorted list of + entries. + + Internally this function uses the `toposort` function in + `` and its value is accordingly. + + Specifically, the result on success is + + { result = [ { name = ?; data = ?; } … ] } + + For example + + nix-repl> topoSort { + a = entryAnywhere "1"; + b = entryAfter [ "a" "c" ] "2"; + c = entryBefore [ "d" ] "3"; + d = entryBefore [ "e" ] "4"; + e = entryAnywhere "5"; + } == { + result = [ + { data = "1"; name = "a"; } + { data = "3"; name = "c"; } + { data = "2"; name = "b"; } + { data = "4"; name = "d"; } + { data = "5"; name = "e"; } + ]; + } + true + + And the result on error is + + { + cycle = [ { after = ?; name = ?; data = ? } … ]; + loops = [ { after = ?; name = ?; data = ? } … ]; + } + + For example + + nix-repl> topoSort { + a = entryAnywhere "1"; + b = entryAfter [ "a" "c" ] "2"; + c = entryAfter [ "d" ] "3"; + d = entryAfter [ "b" ] "4"; + e = entryAnywhere "5"; + } == { + cycle = [ + { after = [ "a" "c" ]; data = "2"; name = "b"; } + { after = [ "d" ]; data = "3"; name = "c"; } + { after = [ "b" ]; data = "4"; name = "d"; } + ]; + loops = [ + { after = [ "a" "c" ]; data = "2"; name = "b"; } + ]; + } + true + */ topoSort = dag: let dagBefore = dag: name: builtins.attrNames diff --git a/modules/lib/types-plugin.nix b/modules/lib/types-plugin.nix index 9d615c5..5d3dd9a 100644 --- a/modules/lib/types-plugin.nix +++ b/modules/lib/types-plugin.nix @@ -47,6 +47,8 @@ with lib; let "codewindow-nvim" "nvim-notify" "cinnamon-nvim" + "cheatsheet-nvim" + "colorizer" ]; pluginsType = with types; listOf (nullOr (either (enum availablePlugins) package)); diff --git a/modules/modules.nix b/modules/modules.nix index 70e4d19..c392cc3 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -17,13 +17,14 @@ ./tidal ./autopairs ./snippets - ./keys + ./binds ./markdown ./telescope ./git ./minimap ./dashboard ./notifications + ./utility ]; pkgsModule = {config, ...}: { diff --git a/modules/utility/colorizer.nix b/modules/utility/colorizer.nix new file mode 100644 index 0000000..940ca7c --- /dev/null +++ b/modules/utility/colorizer.nix @@ -0,0 +1,24 @@ +{ + pkgs, + config, + lib, + ... +}: +with lib; +with builtins; let + cfg = config.vim.utility.colorizer; +in { + options.vim.utility.colorizer = { + enable = mkEnableOption "ccc color picker for neovim"; + }; + + config = mkIf (cfg.enable) { + vim.startPlugins = [ + "colorizer" + ]; + + vim.configRC.ccc = + nvim.dag.entryAnywhere '' + ''; + }; +} diff --git a/modules/utility/default.nix b/modules/utility/default.nix new file mode 100644 index 0000000..e56ce40 --- /dev/null +++ b/modules/utility/default.nix @@ -0,0 +1,5 @@ +_: { + imports = [ + ./colorizer.nix + ]; +}