Closed grappas closed 10 months ago
From the README, it says the new approach is to write harpoon:setup()
. Have you tried with that?
also, .setup
will fail, it has to be :setup()
(luaism for passing a reference of harpoon into the function
@roeeyn that was my initial approach. The result was the same.
Little update
return {
'ThePrimeagen/harpoon',
branch = 'harpoon2',
dependencies = {
'nvim-lua/plenary.nvim'
},
config = function()
local harpoon = require("harpoon")
harpoon:setup()
vim.keymap.set("n", "<leader>ha", function() harpoon:list():append() end)
vim.keymap.set("n", "<leader>hh", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
vim.keymap.set("n", "<leader>hi", function() harpoon:list():select(1) end)
vim.keymap.set("n", "<leader>hj", function() harpoon:list():select(2) end)
vim.keymap.set("n", "<leader>hk", function() harpoon:list():select(3) end)
vim.keymap.set("n", "<leader>hl", function() harpoon:list():select(4) end)
end,
}
Now when I tried it works. Dunno why it haven't work before... 🤔
Can you add to README.md proper Lazy config?
I think it may be related to how Lazy works. From its README:
I noticed in your first comment you used opts
instead of config
as your second comment. But I have not used it before, so I may be wrong
@roeeyn that could be it. Trials and errors. ¯_(ツ)_/¯
@grappas
to be clear, this code has a lua error in it
return {
'ThePrimeagen/harpoon',
branch = 'harpoon2',
dependencies = {
'nvim-lua/plenary.nvim',
},
opts = function()
require("harpoon").setup()
end,
}
specifically the line
require("harpoon").setup()
it should be
require("harpoon"):setup()
require("harpoon"):setup()
is equivalent to require("harpoon").setup(require("harpoon"))
BTW why :setup()
instead of .setup()
? It's an uncommon convention and I don't see any reason why one has to use the "OOP sugar" method.
@wookayin this is poor comms
fork is you don't like it
No offense, sorry if that didn't sound nice. I was just asking out of curiosity. Would you mind clarifying on why it's required? for autocmds (what README briefly says)?
@wookayin this is poor comms
fork is you don't like it
Ok. Lets talk conventions: why local? I can't bind it with which-key.nvim because of that.
For those using lazy.nvim plugin manager and want to utilize its lazy loading conventions by defining a keys
object to trigger the loading of harpoon, you still totally can 🤘
Just make sure you local harpoon
outside of your config
func, and store to that in your config
func, and then your keys
will be able to access the same harpoon object 🤌
For example, in my lua/jl/plugins/harpoon.lua
, I'm doing this...
local harpoon -- Ensure we only interact with local harpoon object 🦈
return {
'ThePrimeagen/harpoon',
branch = 'harpoon2', -- Temp; Will be merged soonish 🔥
dependencies = {
'nvim-lua/plenary.nvim',
},
keys = {
{ '<Leader>gh', function () harpoon.ui:toggle_quick_menu(harpoon:list()) end },
{ '<Leader>ga', function () harpoon:list():append() end },
{ '<Leader>gj', function () harpoon:list():select(1) end },
{ '<Leader>gk', function () harpoon:list():select(2) end },
{ '<Leader>gl', function () harpoon:list():select(3) end },
{ '<Leader>g;', function () harpoon:list():select(4) end },
},
config = function ()
harpoon = require("harpoon"):setup() -- Notice we're storing to parent context 👆
end,
}
I like the .setup()
convention lazy.nvim expects too, but honestly this work just fine!
PS. Thank you @ThePrimeagen for your rad work BTW™️ 😎
I've also made .setup(...)
work (though it's a bit of a lie and makes you think it's not as state capturing as it is)
@ThePrimeagen Oh I totally understood why you went this direction though! Really cool to be able to configure separate list objects. Rad work on harpoon2 dude 🔥
Using NVIM v0.10.0-dev-1684+g570367ac83 via lazy.nvim