Closed constantitus closed 12 months ago
Heyyo @constantitus ,
I just tried this function and it works pretty well in my config. Can you share the part of your config where you used this function?
Here are the relevant parts of my config
-- harpoon config
require("harpoon").setup()
local mark = require("harpoon.mark")
local ui = require("harpoon.ui")
vim.keymap.set("n", "<leader>a", mark.add_file)
vim.keymap.set("n", "<leader>e", ui.toggle_quick_menu)
vim.keymap.set("n", "<leader>1", function() ui.nav_file(1) end)
vim.keymap.set("n", "<leader>2", function() ui.nav_file(2) end)
vim.keymap.set("n", "<leader>3", function() ui.nav_file(3) end)
vim.keymap.set("n", "<leader>4", function() ui.nav_file(4) end)
vim.keymap.set("n", "<leader>5", function() ui.nav_file(5) end)
vim.keymap.set("n", "<leader>6", function() ui.nav_file(6) end)
vim.keymap.set("n", "<leader>7", function() ui.nav_file(7) end)
vim.keymap.set("n", "<leader>8", function() ui.nav_file(8) end)
vim.keymap.set("n", "<leader>9", function() ui.nav_file(9) end)
-- staline config
local harpoon_marks = function()
local marks = require("harpoon").get_mark_config().marks
local buffer = vim.api.nvim_buf_get_name(0)
local current = require("harpoon.mark").get_index_of(buffer)
local keymaps = {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
-- local keymaps = {"H", "J", "K", "L"}
local amount = 9
if #marks < amount then
amount = #marks
end
local str = ""
for i = 1, amount do
if i == current then
str = str .. "[" .. keymaps[i] .. "]"
else
str = str .. " " .. keymaps[i] .. " "
end
end
return str
end
require("staline").setup({
sections = {
right = {
{ 'StlHarpoon', harpoon_marks(), },
},
}
With this config I get the marks in my bar, but they don't highlight the one I'm currently in and they also don't update when I add or remove marks.
This is the behaviour with the function added to the plugin itself It highlights the mark I'm on and it updates as I add or remove marks
Hi @constantitus ,
Instead of passing the function call to the section, you can pass the function directly:
require("staline").setup({
sections = {
right = {
{ 'StlHarpoon', harpoon_marks },
},
}
That works, thanks a lot
I've tried adding it in my config as a function, but it doesn't update in real time. Modifying the plugin itself seems to work and it updates in real time. My lua knowledge is very limited, a cleaner way to do this (such as a module or a way to have it in my config) would be greatly appreciated.