Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seems the line isn't updated when harpoon status changes #211

Open
theherk opened this issue Jan 24, 2025 · 4 comments
Open

Seems the line isn't updated when harpoon status changes #211

theherk opened this issue Jan 24, 2025 · 4 comments

Comments

@theherk
Copy link

theherk commented Jan 24, 2025

Using the harpoon sorter as given in the wiki, doesn't update on change. After changing the harpoon files list, one must switch buffers for the update to have effect. Or I'm missing something, but I can't sort out what. You can see my configuration here and here, but the sorter is:

function M.harpoon_sorter()
  local cache = {}
  local setup = false
  local function marknum(buf, force)
    local b = cache[buf.number]
    if b == nil or force then
      ---@diagnostic disable-next-line: undefined-field
      local path = require("plenary.path"):new(buf.path):make_relative(vim.uv.cwd())
      for i, mark in ipairs(Harpoon:list():display()) do
        if mark == path then
          b = i
          cache[buf.number] = b
          break
        end
      end
    end
    return b
  end
  -- Use this in `config.bufs.new_bufs_position`
  return function(a, b)
    -- Only run this if harpoon is loaded, otherwise just use the default sorting.
    -- This could be used to only run if a user has harpoon installed, but
    -- I'm mainly using it to avoid loading harpoon on UiEnter.
    local has_harpoon = package.loaded["harpoon"] ~= nil
    if not has_harpoon then
      ---@diagnostic disable-next-line: undefined-field
      return a._valid_index < b._valid_index
    elseif not setup then
      local refresh = function() cache = {} end
      Harpoon:extend({
        ADD = refresh,
        REMOVE = refresh,
        REORDER = refresh,
        LIST_CHANGE = refresh,
      })
      setup = true
    end
    -- switch the a and b._valid_index to place non-harpoon bufs on the left
    -- side of the tabline - this puts them on the right.
    local ma = marknum(a)
    local mb = marknum(b)
    if ma and not mb then
      return true
    elseif mb and not ma then
      return false
    elseif ma == nil and mb == nil then
      ma = a._valid_index
      mb = b._valid_index
    end
    return ma < mb
  end
end

I should clarify that it does work when using the harpoon interface, but I mean when using the :add() and :remove() methods. That's when it doesn't update until switching buffers.

@willothy
Copy link
Owner

Yeah, it's probably outdated. I switched away from Harpoon since it's often broken and isn't actively maintained. I don't have much interest in keeping the sorter updated but would be happy if someone else wanted to :)

@willothy willothy closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2025
@theherk
Copy link
Author

theherk commented Jan 24, 2025

Fair enough. Do you have a preferred alternative for similar features? Thanks for following up so quickly.

@willothy willothy reopened this Jan 25, 2025
@willothy
Copy link
Owner

willothy commented Jan 25, 2025

Yeah that's a good point - I've recently been using folke's snacks.nvim picker since I've been trying to slim my config down a bit and the repos I'm working in are quite large (making fuzzy-search easier than visually parsing a buffer list). But maybe some sort of buffer pinning API would be ideal? That way integrations of this kind would be easier but I wouldn't need to maintain any harpoon-specific code. Thoughts?

@theherk
Copy link
Author

theherk commented Jan 25, 2025

I'm in a similar boat. In fact, I've just recently converted from lazy.nvim to mini.deps and adopted a ton of mini.nvim for a similar reason; slimming down. I guess I can make use of mini.visits, but I don't know it well enough yet. There is something nice about manually setting a list of 2 or 3 files I'm working with. A buffer pinning api is an interesting idea, but it feels like maybe responsibility that belongs outside a bufferline plugin ... or maybe it is perfect for that. 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants