From fef97d4439c6b4038d585415eb2712caef5b2dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Schwanck=20dos=20Santos?= Date: Thu, 18 May 2023 18:15:03 +0100 Subject: [PATCH 1/2] feat: redraw tabline --- lua/harpoon/mark.lua | 9 ++++++++- lua/harpoon/tabline.lua | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lua/harpoon/mark.lua b/lua/harpoon/mark.lua index 3f498d7..7b2465b 100644 --- a/lua/harpoon/mark.lua +++ b/lua/harpoon/mark.lua @@ -11,10 +11,17 @@ local callbacks = {} -- need one event emitted local function emit_changed() log.trace("_emit_changed()") - if harpoon.get_global_settings().save_on_change then + + local global_settings = harpoon.get_global_settings() + + if global_settings.save_on_change then harpoon.save() end + if global_settings.tabline then + vim.cmd("redrawt") + end + if not callbacks["changed"] then log.trace("_emit_changed(): no callbacks for 'changed', returning") return diff --git a/lua/harpoon/tabline.lua b/lua/harpoon/tabline.lua index 2030c27..3013250 100644 --- a/lua/harpoon/tabline.lua +++ b/lua/harpoon/tabline.lua @@ -39,7 +39,14 @@ function M.setup(opts) for i, tab in ipairs(original_tabs) do local is_current = string.match(vim.fn.bufname(), tab.filename) or vim.fn.bufname() == tab.filename - local label = tabs[i].filename + local label + + if tabs[i].filename == "" or tabs[i].filename == "(empty)" then + label = "(empty)" + is_current = false + else + label = tabs[i].filename + end if is_current then From 91666776ff5efd589a16ea1a1ad4094ff5f4111a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ot=C3=A1vio=20Schwanck=20dos=20Santos?= Date: Sat, 20 May 2023 18:13:03 +0100 Subject: [PATCH 2/2] detect current by index --- lua/harpoon/tabline.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lua/harpoon/tabline.lua b/lua/harpoon/tabline.lua index 3013250..cc6f874 100644 --- a/lua/harpoon/tabline.lua +++ b/lua/harpoon/tabline.lua @@ -32,20 +32,21 @@ end function M.setup(opts) function _G.tabline() - local original_tabs = require('harpoon').get_mark_config().marks - local tabs = shorten_filenames(original_tabs) + local tabs = shorten_filenames(require('harpoon').get_mark_config().marks) local tabline = '' - for i, tab in ipairs(original_tabs) do - local is_current = string.match(vim.fn.bufname(), tab.filename) or vim.fn.bufname() == tab.filename + local index = require('harpoon.mark').get_index_of(vim.fn.bufname()) + + for i, tab in ipairs(tabs) do + local is_current = i == index local label - if tabs[i].filename == "" or tabs[i].filename == "(empty)" then + if tab.filename == "" or tab.filename == "(empty)" then label = "(empty)" is_current = false else - label = tabs[i].filename + label = tab.filename end @@ -58,6 +59,7 @@ function M.setup(opts) end tabline = tabline .. label .. (opts.tabline_suffix or ' ') .. '%*' + if i < #tabs then tabline = tabline .. '%T' end