Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
fix: default_list_name: The display name for harpoon's default list (#24
Browse files Browse the repository at this point in the history
)

Co-authored-by: abeldekat <abel@nomail.com>
  • Loading branch information
abeldekat and abeldekat authored Apr 8, 2024
1 parent f7615e6 commit 5b0839b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '',
Expand Down Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions lua/harpoonline/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tests/test_harpoonline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 │
Expand Down Expand Up @@ -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 │
Expand Down

0 comments on commit 5b0839b

Please sign in to comment.