-
I just found out about "harpoon sorter" in cokeline today and wanted to give it a try. I use cokeline and harpoon v2, both with near-to-default settings except maybe some key mappings and ui stuff. However, I was not able to make it work as desired. New tabs seem to be always coming in from the left side, no matter the status in harpoon. I was wondering if I have anything incorrect/missing in my config. I tried to come up with the following minimal configs for reproduction. I basically copy and paste the -- cokeline.lua
local function harpoon_sorter()
local cache = {}
local setup = false
local function marknum(buf, force)
local harpoon = require 'harpoon'
local b = cache[buf.number]
if b == nil or force then
local path = require('plenary.path'):new(buf.path):make_relative(vim.uv.cwd())
for i, mark in ipairs(harpoon:list('files'):display()) do
vim.notify(mark)
if mark == path then
b = i
cache[buf.number] = b
break
end
end
end
return b
end
-- Use this in `config.buffers.new_buffers_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
require('harpoon'):extend {
ADD = refresh,
REMOVE = refresh,
REORDER = refresh,
}
setup = true
end
-- switch the a and b._valid_index to place non-harpoon buffers 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
return {
'willothy/nvim-cokeline',
dependencies = {
'nvim-lua/plenary.nvim', -- Required for v0.4.0+
'nvim-tree/nvim-web-devicons', -- If you want devicons
'stevearc/resession.nvim', -- Optional, for persistent history
},
config = function()
require('cokeline').setup {
buffers = {
focus_on_delete = 'next',
new_buffers_position = harpoon_sorter(),
-- new_buffers_position = 'directory',
delete_on_right_click = false,
},
}
end,
} and -- harpoon.lua
return {
'ThePrimeagen/harpoon',
branch = 'harpoon2',
dependencies = { 'nvim-lua/plenary.nvim' },
config = function()
local harpoon = require 'harpoon'
-- REQUIRED
harpoon:setup {}
-- REQUIRED
vim.keymap.set('n', '<leader>hf', function()
harpoon.ui:toggle_quick_menu(harpoon:list())
end, { desc = 'Open harpoon window' })
end,
} I am new to neovim and lua so basically just use kickstart.nvim and my neovim version:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Ah, try removing the "files" list name in the sorter. Sorry, I'll update the docs! In my config I use a "files" list as the default, must've forgotten to remove that when I updated the wiki. |
Beta Was this translation helpful? Give feedback.
Ah, try removing the "files" list name in the sorter. Sorry, I'll update the docs! In my config I use a "files" list as the default, must've forgotten to remove that when I updated the wiki.