diff --git a/README.md b/README.md index f1020e5..5611c97 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ Harpoonline.config = { ---@type string icon = '󰀱', -- An empty string disables showing the icon - -- Harpoon:list() retrieves the default list: The name of that list is nil. + -- Harpoon:list(), without a name, retrieves the default list: -- default_list_name: Configures the display name for the default list. ---@type string default_list_name = '', @@ -236,6 +236,7 @@ The following data is kept up-to-date internally, to be processed by formatters: ```lua ---@class HarpoonLineData H.data = { + -- Harpoon's default list is in use when list_name = nil --- @type string|nil list_name = nil, -- the name of the current list --- @type number diff --git a/lua/harpoonline/init.lua b/lua/harpoonline/init.lua index 3cd7c32..846ac0f 100644 --- a/lua/harpoonline/init.lua +++ b/lua/harpoonline/init.lua @@ -25,7 +25,7 @@ Harpoonline.config = { ---@type string icon = '󰀱', -- An empty string disables showing the icon - -- Harpoon:list() retrieves the default list: The name of that list is nil. + -- Harpoon:list(), without a name, retrieves the default list: -- default_list_name: Configures the display name for the default list. ---@type string default_list_name = '', @@ -96,6 +96,7 @@ H.default_config = vim.deepcopy(Harpoonline.config) ---@class HarpoonLineData H.data = { + -- Harpoon's default list is in use when list_name = nil --- @type string|nil list_name = nil, -- the name of the current list --- @type number @@ -222,11 +223,12 @@ end H.builtin_short = function(data) local opts = H.get_config().formatter_opts.short local icon = H.make_icon() + local list_name = data.list_name and data.list_name or H.get_config().default_list_name return string.format( '%s%s%s[%s%d]', icon, icon == '' and '' or ' ', - data.list_name and data.list_name or '', -- no space after list name... + list_name, -- no space after list name... data.buffer_idx and string.format('%s%s', data.buffer_idx, opts.inner_separator) or '', data.list_length ) @@ -241,12 +243,13 @@ H.builtin_extended = function(data) -- build prefix local show_prefix = true -- show_empty_slots or data.number_of_tags > 0 local icon = H.make_icon() + local list_name = data.list_name and data.list_name or H.get_config().default_list_name local prefix = not show_prefix and '' or string.format( '%s%s%s', -- icon, - data.list_name and ' ' or '', - data.list_name and data.list_name or '' + list_name == '' and '' or ' ', + list_name ) -- build slots diff --git a/tests/test_harpoonline.lua b/tests/test_harpoonline.lua index 1a27732..77281ba 100644 --- a/tests/test_harpoonline.lua +++ b/tests/test_harpoonline.lua @@ -156,6 +156,11 @@ T['format()']['extended']['switch list'] = function() ]]) eq(child.lua_get([[ M.format() ]]), icon .. ' dev 1 [2]') end +T['format()']['extended']['default_list_name'] = function() + child.lua([[M.setup({default_list_name="mainlist"})]]) + add_files_to_list({ '1', '2' }) + eq(child.lua_get([[ M.format() ]]), icon .. ' mainlist 1 [2]') +end -- ╭─────────────────────────────────────────────────────────╮ -- │ Short formatter │ @@ -188,6 +193,21 @@ T['format()']['short']['inner_separator'] = function() add_files_to_list({ '1', '2' }) eq(child.lua_get([[M.format()]]), icon .. ' [2-2]') end +T['format()']['short']['switch list'] = function() + child.lua([[M.setup({ formatter = "short" })]]) + add_files_to_list({ '1', '2' }, 'dev') + child.lua([[ + vim.api.nvim_exec_autocmds("User", { + pattern = "HarpoonSwitchedList", modeline = false, data = "dev" + }) + ]]) + eq(child.lua_get([[ M.format() ]]), icon .. ' dev[2|2]') +end +T['format()']['short']['default_list_name'] = function() + child.lua([[M.setup({ formatter = "short", default_list_name = "mainlist" })]]) + add_files_to_list({ '1', '2' }) + eq(child.lua_get([[ M.format() ]]), icon .. ' mainlist[2|2]') +end -- ╭─────────────────────────────────────────────────────────╮ -- │ Custom formatter │