From 01c830d8ede0f9aa30d5151a9f2d474f74439417 Mon Sep 17 00:00:00 2001 From: Patrick Auernig Date: Wed, 25 Sep 2024 22:12:36 +0200 Subject: [PATCH] plugins/harpoon: switch to harpoon2 branch and update keybinds --- lazy-lock.json | 16 ++++----- lua/valeth/plugins/harpoon.lua | 61 ++++++++++++++++++++++++++++------ 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/lazy-lock.json b/lazy-lock.json index eaa9add..6c09789 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -6,9 +6,9 @@ "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "crates.nvim": { "branch": "main", "commit": "5a24e3ba60e28e0cfde540696630b3c5a4db6dfd" }, "dressing.nvim": { "branch": "master", "commit": "1b7921eecc65af1baf8ac1dc06f0794934cbcfb2" }, - "formatter.nvim": { "branch": "master", "commit": "ad246d34ce7a32f752071ed81b09b94e6b127fad" }, + "formatter.nvim": { "branch": "master", "commit": "01d976117743876f1c102bda2a03d93c7a37d85f" }, "gitsigns.nvim": { "branch": "main", "commit": "1ef74b546732f185d0f806860fa5404df7614f28" }, - "harpoon": { "branch": "master", "commit": "1bc17e3e42ea3c46b33c0bbad6a880792692a1b3" }, + "harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" }, "indent-blankline.nvim": { "branch": "master", "commit": "18603eb949eba08300799f64027af11ef922283f" }, "lazy.nvim": { "branch": "main", "commit": "460e1cd8f24e364d54543a4b0e83f6f4ec1f65fb" }, "lspkind.nvim": { "branch": "master", "commit": "cff4ae321a91ee3473a92ea1a8c637e3a9510aec" }, @@ -17,18 +17,18 @@ "mason-nvim-dap.nvim": { "branch": "main", "commit": "f0cd12f7a8a310c58cecebddb6b219ffad1cfd0f" }, "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, "mini.icons": { "branch": "main", "commit": "2d89252993fec829b24720097a687412d10f6c85" }, - "neoconf.nvim": { "branch": "main", "commit": "61b10cd334dc8f693e391c5ef8c5832093a46cf5" }, + "neoconf.nvim": { "branch": "main", "commit": "4bba87a057867004e70596dafe7262bbaac38810" }, "neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, - "neogit": { "branch": "master", "commit": "9959b58a897036ce89d47385021db1f716613399" }, + "neogit": { "branch": "master", "commit": "c4bf4a3d06c6001b10228bdbad325084fbd2d9f3" }, "noice.nvim": { "branch": "main", "commit": "c1ba80ccf6b3bd8c7fc88fe2e61085131d44ad65" }, "nui.nvim": { "branch": "main", "commit": "b58e2bfda5cea347c9d58b7f11cf3012c7b3953f" }, "nvim-autopairs": { "branch": "master", "commit": "f158dcb865c36f72c92358f87787dab2c272eaf3" }, "nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" }, "nvim-dap": { "branch": "master", "commit": "debd7c2f80eaf20c5f5df25db8d8c1b9b18f4421" }, "nvim-dap-ui": { "branch": "master", "commit": "34160a7ce6072ef332f350ae1d4a6a501daf0159" }, - "nvim-lspconfig": { "branch": "master", "commit": "dd329912c8d446240584a2dbcd3802af3a19105a" }, + "nvim-lspconfig": { "branch": "master", "commit": "a9bc587e9ae0cbcb3e90a2e9342f86b3b78c4408" }, "nvim-notify": { "branch": "master", "commit": "fbef5d32be8466dd76544a257d3f3dce20082a07" }, - "nvim-treesitter": { "branch": "master", "commit": "621f5901f0b3e762cc4c5ed0f9246cf1495193ad" }, + "nvim-treesitter": { "branch": "master", "commit": "0c8a582e474e248f2a4406188e0c653f92a064cf" }, "nvim-treesitter-context": { "branch": "master", "commit": "3d5390c49e3f8fe457b376df2a49aa39d75b7911" }, "nvim-treesitter-endwise": { "branch": "master", "commit": "8b34305ffc28bd75a22f5a0a9928ee726a85c9a6" }, "nvim-ufo": { "branch": "main", "commit": "203c9f434feec57909ab4b1e028abeb3349b7847" }, @@ -37,10 +37,10 @@ "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, "promise-async": { "branch": "main", "commit": "119e8961014c9bfaf1487bf3c2a393d254f337e2" }, "rainbow_csv.nvim": { "branch": "main", "commit": "7f3fddfe813641035fac2cdf94c2ff69bb0bf0b9" }, - "render-markdown.nvim": { "branch": "main", "commit": "75a0a9596a91130fae43d3b7c0d6c651645ef1df" }, + "render-markdown.nvim": { "branch": "main", "commit": "37f52f02ab4ed98112477fe6a1c6320955ec40e6" }, "resession.nvim": { "branch": "master", "commit": "c4d92a57b3936a2d6e1c087dbd6b670da2b1b082" }, "statuscol.nvim": { "branch": "main", "commit": "1022f922b77b44c36f8057ac29adbfd89ce86958" }, - "telescope.nvim": { "branch": "master", "commit": "b324469959908c1c7434eb65d80e87895e6828f7" }, + "telescope.nvim": { "branch": "master", "commit": "6b08cdcc22a630d19172b9db55f7b8db5f81d761" }, "trouble.nvim": { "branch": "main", "commit": "6efc446226679fda0547c0fd6a7892fd5f5b15d8" }, "vim-wakatime": { "branch": "master", "commit": "f699e30ca1ba0c7f316847316fd0ba19d3ee51c1" }, "which-key.nvim": { "branch": "main", "commit": "fb070344402cfc662299d9914f5546d840a22126" }, diff --git a/lua/valeth/plugins/harpoon.lua b/lua/valeth/plugins/harpoon.lua index 95d229f..54aee57 100644 --- a/lua/valeth/plugins/harpoon.lua +++ b/lua/valeth/plugins/harpoon.lua @@ -1,5 +1,6 @@ local spec = { "ThePrimeagen/harpoon", + branch = "harpoon2", } spec.dependencies = { @@ -7,21 +8,61 @@ spec.dependencies = { "nvim-telescope/telescope.nvim", } -spec.keys = { - { "fh", "Telescope harpoon marks", desc = "Show harpoon marks" }, -} +-- TODO: Add keybinds to remove mark from list and reorder them +local function toggle_telescope(harpoon_files) + local file_paths = {} + + for _, item in ipairs(harpoon_files.items) do + table.insert(file_paths, item.value) + end + + local config = require("telescope.config").values + local pickers = require("telescope.pickers") + local finders = require("telescope.finders") + + local picker = pickers.new({}, { + prompt_title = "Harpoon", + finder = finders.new_table({ + results = file_paths, + }), + previewer = config.file_previewer({}), + sorter = config.generic_sorter({}), + }) + + picker:find() +end spec.config = function() - local telescope = require("telescope") + local harpoon = require("harpoon") + local keymap = vim.keymap.set - telescope.load_extension("harpoon") + harpoon:setup() - local harpoon_mark = require("harpoon.mark") - local harpoon_ui = require("harpoon.ui") + keymap("n", "hl", function() + toggle_telescope(harpoon:list()) + end, { desc = "Show harpoon marks" }) - vim.keymap.set("n", "am", harpoon_mark.add_file, { desc = "Add a file to marks" }) - vim.keymap.set("n", "gn", harpoon_ui.nav_next, { desc = "Go to next mark" }) - vim.keymap.set("n", "gp", harpoon_ui.nav_prev, { desc = "Go to previous mark" }) + keymap("n", "ha", function() + harpoon:list():add() + end, { desc = "Add current file to marks" }) + + keymap("n", "hr", function() + harpoon:list():remove() + end, { desc = "Remove current file from marks" }) + + keymap("n", "hn", function() + harpoon:list():next() + end, { desc = "Go to next mark" }) + + keymap("n", "hp", function() + harpoon:list():prev() + end, { desc = "Go to previous mark" }) + + for i = 1, 5 do + keymap("n", "h" .. i, function() + harpoon:list():select(i) + end, { desc = "Go to marked file " .. i }) + end end return spec