From e131d90bbacff5cceeaec291cb3fbab912ddcf17 Mon Sep 17 00:00:00 2001 From: p0uyaDev Date: Thu, 9 Jul 2026 02:07:28 +0200 Subject: [PATCH 1/4] feat(recipes): add harpoon-bufsync recipe --- .../recipes/harpoon-bufsync/README.md | 21 ++++++ .../recipes/harpoon-bufsync/init.lua | 66 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 lua/astrocommunity/recipes/harpoon-bufsync/README.md create mode 100644 lua/astrocommunity/recipes/harpoon-bufsync/init.lua diff --git a/lua/astrocommunity/recipes/harpoon-bufsync/README.md b/lua/astrocommunity/recipes/harpoon-bufsync/README.md new file mode 100644 index 000000000..eefbef2ed --- /dev/null +++ b/lua/astrocommunity/recipes/harpoon-bufsync/README.md @@ -0,0 +1,21 @@ +# Harpoon BufSync + +Sync your AstroNvim buffer tabline to your Harpoon marks — close, open, and sort buffers based on your pinned files. + +## Overview + +Harpoon lets you pin frequently-used files for quick navigation. But your tabline (Heirline) doesn't reflect that order — it tracks buffers by open-time and internal buffer ID. This recipe bridges that gap: with a single keybind (`bsh`), it closes non-Harpoon buffers, opens missing Harpoon files, and sorts the tabline to match your Harpoon order. + +## Requirements + +- [Harpoon v2](https://github.com/ThePrimeagen/harpoon) (branch `harpoon2`) +- [AstroCore](https://github.com/AstroNvim/astrocore) (bundled with AstroNvim) +- [Heirline](https://github.com/rebelot/heirline.nvim) (AstroNvim default tabline) + +## Installation + +Add to your `community.lua`: + +```lua +{ import = "astrocommunity.recipes.harpoon-bufsync" }, +``` diff --git a/lua/astrocommunity/recipes/harpoon-bufsync/init.lua b/lua/astrocommunity/recipes/harpoon-bufsync/init.lua new file mode 100644 index 000000000..7b8181276 --- /dev/null +++ b/lua/astrocommunity/recipes/harpoon-bufsync/init.lua @@ -0,0 +1,66 @@ +return { + { + "AstroNvim/astrocore", + ---@param opts AstroCoreOpts + opts = function(_, opts) + opts.mappings = opts.mappings or {} + opts.mappings.n = opts.mappings.n or {} + + -- Sync tabline buffers to Harpoon mark order + opts.mappings.n["bsh"] = { + function() + local harpoon = require "harpoon" + local harpoon_items = harpoon:list().items + + -- Build path -> harpoon index map + local harpoon_order = {} + for i, item in ipairs(harpoon_items) do + local path = vim.fn.fnamemodify(item.value, ":p") + harpoon_order[path] = i + end + + -- Get current tab's buffer list (this IS the tabline order) + local bufs = vim.t.bufs or {} + + -- Close buffers NOT in Harpoon list + for _, bufnr in ipairs(bufs) do + if require("astrocore.buffer").is_valid(bufnr) then + local buf_path = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":p") + if not harpoon_order[buf_path] then require("astrocore.buffer").close(bufnr) end + end + end + + -- Open Harpoon files that aren't open yet + local open_paths = {} + for _, bufnr in ipairs(vim.t.bufs or {}) do + open_paths[vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":p")] = true + end + + for _, item in ipairs(harpoon_items) do + local path = vim.fn.fnamemodify(item.value, ":p") + if not open_paths[path] and vim.fn.filereadable(path) == 1 then + vim.cmd("edit " .. vim.fn.fnameescape(path)) + end + end + + -- Re-sort vim.t.bufs by Harpoon order + local new_order = {} + for _, bufnr in ipairs(vim.t.bufs or {}) do + local buf_path = vim.fn.fnamemodify(vim.api.nvim_buf_get_name(bufnr), ":p") + if harpoon_order[buf_path] then + table.insert(new_order, { idx = harpoon_order[buf_path], bufnr = bufnr }) + end + end + table.sort(new_order, function(a, b) return a.idx < b.idx end) + + -- Write back the sorted order + vim.t.bufs = vim.tbl_map(function(item) return item.bufnr end, new_order) + + -- Refresh the tabline + vim.cmd "redrawtabline" + end, + desc = "Sort by Harpoon", + } + end, + }, +} From 89e2e4ddceab48919d1111a90489cfff6f20f04b Mon Sep 17 00:00:00 2001 From: p0uyaDev Date: Mon, 27 Jul 2026 03:02:27 +0200 Subject: [PATCH 2/4] feat(buffers): add bidirectional sync to harpoon-bufsync Extend harpoon-bufsync recipe with reverse sync direction: - b: Reset Harpoon marks from currently open buffers - Existing bsh: Sync tabline to Harpoon order remains unchanged Enables snapshot mode: work with buffers naturally, then snapshot into Harpoon. --- .../recipes/harpoon-bufsync/README.md | 15 ++++---- .../recipes/harpoon-bufsync/init.lua | 36 ++++++++++++++++++- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/lua/astrocommunity/recipes/harpoon-bufsync/README.md b/lua/astrocommunity/recipes/harpoon-bufsync/README.md index eefbef2ed..a56b9b42d 100644 --- a/lua/astrocommunity/recipes/harpoon-bufsync/README.md +++ b/lua/astrocommunity/recipes/harpoon-bufsync/README.md @@ -1,10 +1,17 @@ # Harpoon BufSync -Sync your AstroNvim buffer tabline to your Harpoon marks — close, open, and sort buffers based on your pinned files. +> Bidirectional buffer synchronization between AstroNvim tabline and Harpoon marks ## Overview -Harpoon lets you pin frequently-used files for quick navigation. But your tabline (Heirline) doesn't reflect that order — it tracks buffers by open-time and internal buffer ID. This recipe bridges that gap: with a single keybind (`bsh`), it closes non-Harpoon buffers, opens missing Harpoon files, and sorts the tabline to match your Harpoon order. +Harpoon lets you pin frequently-used files for quick navigation. But your tabline (Heirline) doesn't reflect that order — it tracks buffers by open-time and internal buffer ID. + +This recipe bridges that gap with **two keybindings**: + +- **Harpoon → Tabline** (`bsh`): Closes non-Harpoon buffers, opens missing Harpoon files, and sorts the tabline to match your Harpoon order +- **Tabline → Harpoon** (`b`): Resets your Harpoon marks to match currently open buffers in tabline order + +Work naturally with your buffers, snapshot them into Harpoon, or restore your Harpoon set — both directions available on demand. ## Requirements @@ -15,7 +22,3 @@ Harpoon lets you pin frequently-used files for quick navigation. But your tablin ## Installation Add to your `community.lua`: - -```lua -{ import = "astrocommunity.recipes.harpoon-bufsync" }, -``` diff --git a/lua/astrocommunity/recipes/harpoon-bufsync/init.lua b/lua/astrocommunity/recipes/harpoon-bufsync/init.lua index 7b8181276..911949e55 100644 --- a/lua/astrocommunity/recipes/harpoon-bufsync/init.lua +++ b/lua/astrocommunity/recipes/harpoon-bufsync/init.lua @@ -6,7 +6,41 @@ return { opts.mappings = opts.mappings or {} opts.mappings.n = opts.mappings.n or {} - -- Sync tabline buffers to Harpoon mark order + -- ── b: Reset Harpoon from open buffers ────── + opts.mappings.n["b"] = { + function() + local harpoon = require "harpoon" + local list = harpoon:list() + local buffer = require "astrocore.buffer" + + -- Remember where we are + local current_buf = vim.api.nvim_get_current_buf() + + -- Nuke existing Harpoon marks + list.items = {} + + -- Re-add each open buffer, preserving tabline order + for _, bufnr in ipairs(vim.t.bufs or {}) do + if buffer.is_valid(bufnr) then + local path = vim.api.nvim_buf_get_name(bufnr) + if path ~= "" and vim.fn.filereadable(path) == 1 then + -- Switch to this buffer so Harpoon's add() picks it up + pcall(vim.api.nvim_set_current_buf, bufnr) + list:add() + end + end + end + + -- Restore the buffer we started on + pcall(vim.api.nvim_set_current_buf, current_buf) + + -- Quick feedback + vim.notify("Harpoon marks reset: " .. #list.items .. " files from tabline", vim.log.levels.INFO) + end, + desc = "Reset Harpoon from buffers", + } + + -- ── bsh: Sync tabline to Harpoon order ───────────── opts.mappings.n["bsh"] = { function() local harpoon = require "harpoon" From 4332f8c67121ff75ff56436b0b67684df67f17b2 Mon Sep 17 00:00:00 2001 From: p0uyaDev Date: Sat, 8 Aug 2026 00:59:00 +0200 Subject: [PATCH 3/4] chore(README): remove unnecessary parts --- lua/astrocommunity/recipes/harpoon-bufsync/README.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lua/astrocommunity/recipes/harpoon-bufsync/README.md b/lua/astrocommunity/recipes/harpoon-bufsync/README.md index a56b9b42d..b2f2c4585 100644 --- a/lua/astrocommunity/recipes/harpoon-bufsync/README.md +++ b/lua/astrocommunity/recipes/harpoon-bufsync/README.md @@ -12,13 +12,3 @@ This recipe bridges that gap with **two keybindings**: - **Tabline → Harpoon** (`b`): Resets your Harpoon marks to match currently open buffers in tabline order Work naturally with your buffers, snapshot them into Harpoon, or restore your Harpoon set — both directions available on demand. - -## Requirements - -- [Harpoon v2](https://github.com/ThePrimeagen/harpoon) (branch `harpoon2`) -- [AstroCore](https://github.com/AstroNvim/astrocore) (bundled with AstroNvim) -- [Heirline](https://github.com/rebelot/heirline.nvim) (AstroNvim default tabline) - -## Installation - -Add to your `community.lua`: From 388cc0ff6c3ee4edb5dfee256fe488ddf77fab2c Mon Sep 17 00:00:00 2001 From: Uzair Aftab Date: Mon, 10 Aug 2026 11:52:57 +0200 Subject: [PATCH 4/4] chore: remove unnessecary comments --- lua/astrocommunity/recipes/harpoon-bufsync/init.lua | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lua/astrocommunity/recipes/harpoon-bufsync/init.lua b/lua/astrocommunity/recipes/harpoon-bufsync/init.lua index 911949e55..c436974d1 100644 --- a/lua/astrocommunity/recipes/harpoon-bufsync/init.lua +++ b/lua/astrocommunity/recipes/harpoon-bufsync/init.lua @@ -13,10 +13,8 @@ return { local list = harpoon:list() local buffer = require "astrocore.buffer" - -- Remember where we are local current_buf = vim.api.nvim_get_current_buf() - -- Nuke existing Harpoon marks list.items = {} -- Re-add each open buffer, preserving tabline order @@ -31,10 +29,8 @@ return { end end - -- Restore the buffer we started on pcall(vim.api.nvim_set_current_buf, current_buf) - -- Quick feedback vim.notify("Harpoon marks reset: " .. #list.items .. " files from tabline", vim.log.levels.INFO) end, desc = "Reset Harpoon from buffers", @@ -90,7 +86,6 @@ return { -- Write back the sorted order vim.t.bufs = vim.tbl_map(function(item) return item.bufnr end, new_order) - -- Refresh the tabline vim.cmd "redrawtabline" end, desc = "Sort by Harpoon",