diff --git a/modules/treesitter/config.nix b/modules/treesitter/config.nix index b75121b..0bb3a0b 100644 --- a/modules/treesitter/config.nix +++ b/modules/treesitter/config.nix @@ -1,5 +1,4 @@ { - pkgs, config, lib, ... @@ -8,6 +7,11 @@ with lib; with builtins; let cfg = config.vim.treesitter; usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp"; + + self = import ./treesitter.nix {inherit lib;}; + + mappingDefinitions = self.options.vim.treesitter.mappings; + mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; in { config = mkIf cfg.enable { vim.startPlugins = @@ -16,6 +20,16 @@ in { vim.autocomplete.sources = {"treesitter" = "[Treesitter]";}; + # For some reason, using mkSetLuaBinding and putting the lua code does not work. It just selects the whole file. + # This works though, and if it ain't broke, don't fix it. + vim.maps.normal = mkSetBinding mappings.incrementalSelection.init ":lua require('nvim-treesitter.incremental_selection').init_selection()"; + + vim.maps.visualOnly = mkMerge [ + (mkSetBinding mappings.incrementalSelection.incrementByNode ":lua require('nvim-treesitter.incremental_selection').node_incremental()") + (mkSetBinding mappings.incrementalSelection.incrementByScope ":lua require('nvim-treesitter.incremental_selection').scope_incremental()") + (mkSetBinding mappings.incrementalSelection.decrementByNode ":lua require('nvim-treesitter.incremental_selection').node_decremental()") + ]; + # For some reason treesitter highlighting does not work on start if this is set before syntax on vim.configRC.treesitter-fold = mkIf cfg.fold (nvim.dag.entryBefore ["basic"] '' set foldmethod=expr @@ -36,10 +50,10 @@ in { incremental_selection = { enable = true, keymaps = { - init_selection = "gnn", - node_incremental = "grn", - scope_incremental = "grc", - node_decremental = "grm", + init_selection = false, + node_incremental = false, + scope_incremental = false, + node_decremental = false, }, }, } diff --git a/modules/treesitter/treesitter.nix b/modules/treesitter/treesitter.nix index cd4476d..e734125 100644 --- a/modules/treesitter/treesitter.nix +++ b/modules/treesitter/treesitter.nix @@ -1,14 +1,5 @@ -{ - pkgs, - config, - lib, - ... -}: -with lib; -with builtins; let - cfg = config.vim.treesitter; - usingNvimCmp = config.vim.autocomplete.enable && config.vim.autocomplete.type == "nvim-cmp"; -in { +{lib, ...}: +with lib; { options.vim.treesitter = { enable = mkEnableOption "treesitter, also enabled automatically through language options"; @@ -16,13 +7,21 @@ in { autotagHtml = mkEnableOption "autoclose and rename html tag"; + mappings = { + incrementalSelection = { + init = mkMappingOption "Init selection [treesitter]" "gnn"; + incrementByNode = mkMappingOption "Increment selection by node [treesitter]" "grn"; + incrementByScope = mkMappingOption "Increment selection by scope [treesitter]" "grc"; + decrementByNode = mkMappingOption "Decrement selection by node [treesitter]" "grm"; + }; + }; + grammars = mkOption { type = with types; listOf package; default = []; description = nvim.nmd.asciiDoc '' List of treesitter grammars to install. For supported languages use the `vim.language..treesitter` option - ''; }; };