From 2fe2b60fd4ad9cc7a3021ba11dc13f6fac2bca5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Fri, 17 Feb 2023 22:19:47 +0100 Subject: [PATCH] nvim: add nvim-treesitter-textsubjects --- flake.lock | 17 +++++++++++++++++ flake.nix | 5 +++++ modules/programs/nvim/default.nix | 16 ++++++++++++++++ modules/programs/nvim/init.lua | 8 ++++++++ 4 files changed, 46 insertions(+) diff --git a/flake.lock b/flake.lock index 2837f2c..b4de3d8 100644 --- a/flake.lock +++ b/flake.lock @@ -666,6 +666,22 @@ "type": "github" } }, + "nvim-treesitter-textsubjects": { + "flake": false, + "locked": { + "lastModified": 1676144693, + "narHash": "sha256-4jb9v0xpO17wp85dzojKUQ6hUdNBx3T2tB4fSWoANus=", + "owner": "RRethy", + "repo": "nvim-treesitter-textsubjects", + "rev": "b913508f503527ff540f7fe2dcf1bf1d1f259887", + "type": "github" + }, + "original": { + "owner": "RRethy", + "repo": "nvim-treesitter-textsubjects", + "type": "github" + } + }, "pre-commit-hooks": { "inputs": { "flake-compat": "flake-compat", @@ -757,6 +773,7 @@ "neovim": "neovim", "nil": "nil", "nixpkgs": "nixpkgs_8", + "nvim-treesitter-textsubjects": "nvim-treesitter-textsubjects", "pre-commit-hooks": "pre-commit-hooks_3", "stable": "stable", "utils": "utils_2" diff --git a/flake.nix b/flake.nix index 9f6dffc..6127709 100644 --- a/flake.nix +++ b/flake.nix @@ -56,6 +56,11 @@ hyprland.url = "github:hyprwm/Hyprland"; hyprpaper.url = "github:hyprwm/hyprpaper"; hypr-contrib.url = "github:hyprwm/contrib"; + + nvim-treesitter-textsubjects = { + url = "github:RRethy/nvim-treesitter-textsubjects"; + flake = false; + }; }; outputs = diff --git a/modules/programs/nvim/default.nix b/modules/programs/nvim/default.nix index 84463e0..ed788db 100644 --- a/modules/programs/nvim/default.nix +++ b/modules/programs/nvim/default.nix @@ -1,12 +1,27 @@ { config , lib , pkgs +, inputs , ... }: with lib; let cfg = config.my.programs.vim; + + mkDate = longDate: (lib.concatStringsSep "-" [ + (builtins.substring 0 4 longDate) + (builtins.substring 4 2 longDate) + (builtins.substring 6 2 longDate) + ]); + + mkVersionInput = input: mkDate (input.lastModifiedDate or "19700101") + "_" + (input.shortRev or "dirty"); + + nvim-treesitter-textsubjects = pkgs.vimUtils.buildVimPluginFrom2Nix { + pname = "nvim-treesitter-textsubjects"; + version = mkVersionInput inputs.nvim-treesitter-textsubjects; + src = inputs.nvim-treesitter-textsubjects; + }; in { options.my.programs.vim = { @@ -46,6 +61,7 @@ in nvim-cmp nvim-lspconfig nvim-surround + nvim-treesitter-textsubjects nvim-treesitter.withAllGrammars nvim-ts-context-commentstring nvim-web-devicons # for dashboard-nvim diff --git a/modules/programs/nvim/init.lua b/modules/programs/nvim/init.lua index ddd1778..80cc9c7 100644 --- a/modules/programs/nvim/init.lua +++ b/modules/programs/nvim/init.lua @@ -322,3 +322,11 @@ require("nvim-treesitter.configs").setup({ }) require("nvim-surround").setup({}) + +require("nvim-treesitter.configs").setup({ + textsubjects = { + enable = true, + prev_selection = ",", -- (Optional) keymap to select the previous selection + keymaps = { ["."] = "textsubjects-smart" }, + }, +})