Skip to content

Commit

Permalink
Add harpoonline and telescope harpoon extension
Browse files Browse the repository at this point in the history
Marks in lualine, custom mapping to delete marks in Telescope
Also see ThePrimeagen/harpoon#512
and ThePrimeagen/harpoon#499
  • Loading branch information
iain-at-squiz committed Mar 27, 2024
1 parent 9acb7a9 commit 0bf2add
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 34 deletions.
11 changes: 6 additions & 5 deletions .config/nvim/lazy-lock.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" },
"LazyVim": { "branch": "main", "commit": "1de90e7e4c94f51b187c4cd4fcfb6480f4303c46" },
"LazyVim": { "branch": "main", "commit": "c901640167ec5b123ff8524b01518c9a370a0d31" },
"LuaSnip": { "branch": "master", "commit": "a7a4b4682c4b3e2ba82b82a4e6e5f5a0e79dec32" },
"SchemaStore.nvim": { "branch": "main", "commit": "65f07cde64d9123eab8639c1a3f7aa7939060cde" },
"SchemaStore.nvim": { "branch": "main", "commit": "4ce271f0db8b5224b4d69a43a75c13f5b4dcba43" },
"barbecue": { "branch": "main", "commit": "cd7e7da622d68136e13721865b4d919efd6325ed" },
"base16-nvim": { "branch": "master", "commit": "b3e9ec6a82c05b562cd71f40fe8964438a9ba64a" },
"base16-vim": { "branch": "main", "commit": "257d0d2aa78a41f5297620ce55268b8ab173c8d2" },
Expand All @@ -22,11 +22,12 @@
"gitlinker.nvim": { "branch": "master", "commit": "cc59f732f3d043b626c8702cb725c82e54d35c25" },
"gitsigns.nvim": { "branch": "main", "commit": "078041e9d060a386b0c9d3a8c7a7b019a35d3fb0" },
"harpoon": { "branch": "harpoon2", "commit": "a38be6e0dd4c6db66997deab71fc4453ace97f9c" },
"harpoonline": { "branch": "main", "commit": "b55648d903e33236bd47fc9f9892b14c4cfea749" },
"highlight-undo.nvim": { "branch": "main", "commit": "50a6884a8476be04ecce8f1c4ed692c5000ef0a1" },
"hurl.nvim": { "branch": "main", "commit": "8a3de4f29c16ed0146d65f51dee785877f0d5fb7" },
"inc-rename.nvim": { "branch": "main", "commit": "6f9b5f9cb237e12935144cdc535322b8c93c1b25" },
"indent-blankline.nvim": { "branch": "master", "commit": "3d08501caef2329aba5121b753e903904088f7e6" },
"lazy.nvim": { "branch": "main", "commit": "68941b7b13861ca44ad5d4caf7296d9160b4732f" },
"lazy.nvim": { "branch": "main", "commit": "65887ea871d44822bff47504202b3643f29d614e" },
"log-highlight.nvim": { "branch": "main", "commit": "c18d1fd20c411f9fd9702d6d0d09edf3faa2bb96" },
"lsp_lines.nvim": { "branch": "main", "commit": "cf2306dd332e34a3e91075b40bdd4f6db824b2ee" },
"lualine.nvim": { "branch": "master", "commit": "b5e8bb642138f787a2c1c5aedc2a78cb2cebbd67" },
Expand All @@ -52,9 +53,9 @@
"nvim-markdown-preview": { "branch": "master", "commit": "3d6f941beb223b23122973d077522e9e2ee33068" },
"nvim-navic": { "branch": "master", "commit": "8649f694d3e76ee10c19255dece6411c29206a54" },
"nvim-notify": { "branch": "master", "commit": "5371f4bfc1f6d3adf4fe9d62cd3a9d44356bfd15" },
"nvim-spectre": { "branch": "master", "commit": "31f62d7fc30257b2a5c5327ff7b47719da37a1b4" },
"nvim-spectre": { "branch": "master", "commit": "2b012554a2536465243c0dff3605b5927c49ed23" },
"nvim-tmux-navigation": { "branch": "main", "commit": "4898c98702954439233fdaf764c39636681e2861" },
"nvim-treesitter": { "branch": "master", "commit": "7f3179315959bd762abd0f8dbe0361db805fb2d4" },
"nvim-treesitter": { "branch": "master", "commit": "aa8d8bc600e00f84d11b9d40c6900d72d0f68fa3" },
"nvim-treesitter-context": { "branch": "master", "commit": "f19766163c18515fb4d3c12d572bf9cba6cdb990" },
"nvim-treesitter-textobjects": { "branch": "master", "commit": "d2a4ffc22d9d38d44edb73da007b3cf43451e9b4" },
"nvim-ts-autotag": { "branch": "main", "commit": "531f48334c422222aebc888fd36e7d109cb354cd" },
Expand Down
2 changes: 1 addition & 1 deletion .config/nvim/lazyvim.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lazyvim.plugins.extras.util.mini-hipatterns"
],
"news": {
"NEWS.md": "2123"
"NEWS.md": "2850"
},
"version": 3
}
35 changes: 8 additions & 27 deletions .config/nvim/lua/plugins/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,18 @@ return {
{
"nvim-lualine/lualine.nvim",
event = "VeryLazy",
dependencies = { "RRethy/base16-nvim" },
dependencies = { "RRethy/base16-nvim", { "abeldekat/harpoonline", version = "*" } },
opts = function()
local icons = require("lazyvim.config").icons
local util = require("lazyvim.util")
-- Show harpoon marks in lualine:
-- https://twitter.com/dillon_mulroy/status/1658310366919643137?s=20
local harpoon = require("harpoon")
local noice = require("noice")

local function harpoon_component()
local current_file = vim.api.nvim_buf_get_name(0):gsub(vim.fn.getcwd() .. "/", "")
local list = harpoon:list()
local total_marks = list:length()

if total_marks == 0 then
return ""
end

local current_mark = "-"
local mark_idx = nil
for idx, item in ipairs(list.items) do
if item.value == current_file then
mark_idx = idx
end
end
if mark_idx ~= nil then
current_mark = tostring(mark_idx)
end

return string.format("󱡅 %s/%d", current_mark, total_marks)
end
local Harpoonline = require("harpoonline")
Harpoonline.setup({
on_update = function()
require("lualine").refresh()
end,
})

return {
options = {
Expand All @@ -42,7 +23,7 @@ return {
},
sections = {
lualine_a = { "mode" },
lualine_b = { { harpoon_component } },
lualine_b = { { Harpoonline.format, "filename" } },
lualine_c = {
{
"diagnostics",
Expand Down
47 changes: 46 additions & 1 deletion .config/nvim/lua/plugins/harpoon.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,56 @@
return {
"ThePrimeagen/harpoon",
branch = "harpoon2",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim",
},
opts = {
menu = {
width = vim.api.nvim_win_get_width(0) - 4,
},
},
config = function(_, opts)
local harpoon = require("harpoon")
harpoon:setup(opts)

-- basic telescope configuration
local conf = require("telescope.config").values
local actions = require("telescope.actions")

local function toggle_telescope(harpoon_files)
local file_paths = {}
for _, item in ipairs(harpoon_files.items) do
table.insert(file_paths, item.value)
end

require("telescope.pickers")
.new({}, {
prompt_title = "Harpoon",
finder = require("telescope.finders").new_table({
results = file_paths,
}),
previewer = conf.file_previewer({}),
sorter = conf.generic_sorter({}),
attach_mappings = function(_, map)
map({ "i", "n" }, "<M-d>", function(prompt_bufnr)
local action_state = require("telescope.actions.state")
local current_picker = action_state.get_current_picker(prompt_bufnr)

current_picker:delete_selection(function(selection)
require("harpoon"):list():removeAt(selection.index)
end)
end, { desc = "Remove from harpoon list" })
return true
end,
})
:find()
end

vim.keymap.set("n", "<leader>h", function()
toggle_telescope(harpoon:list())
end, { desc = "Open harpoon window" })
end,
keys = {
{
"<leader>H",
Expand All @@ -15,7 +60,7 @@ return {
desc = "Harpoon file",
},
{
"<leader>h",
"<C-e>",
function()
local harpoon = require("harpoon")
harpoon.ui:toggle_quick_menu(harpoon:list())
Expand Down

0 comments on commit 0bf2add

Please sign in to comment.