Skip to content

Commit

Permalink
feat(pick): add config option for pick alphabet (#972)
Browse files Browse the repository at this point in the history
  • Loading branch information
joaovfsousa authored Oct 24, 2024
1 parent 5c528be commit 5cc447c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
18 changes: 17 additions & 1 deletion doc/bufferline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ The available configuration are:
local modified_a = vim.fn.getftime(buffer_a.path)
local modified_b = vim.fn.getftime(buffer_b.path)
return modified_a > modified_b
end
end,
pick = {
alphabet = "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ1234567890",
},
}
}
<
Expand Down Expand Up @@ -658,6 +661,19 @@ this can also be mapped to something like
nnoremap <silent> gD :BufferLinePickClose<CR>
>
You can configure the characters used for selecting buffers using the
`pick.alphabet` option. By default, both uppercase and lowercase
alphanumeric characters are used.
>lua
options = {
pick = {
alphabet = "abcdefghijklmopqrstuvwxyz"
}
}
<

With the configuration above, bufferline will only use lowercase letters.

==============================================================================
MOUSE ACTIONS *bufferline-mouse-actions*

Expand Down
3 changes: 3 additions & 0 deletions lua/bufferline/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ local function get_defaults()
groups = { items = {}, options = { toggle_hidden_on_enter = true } },
hover = { enabled = false, reveal = {}, delay = 200 },
debug = { logging = false },
pick = {
alphabet = "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ1234567890",
},
}
return { options = opts, highlights = derive_colors(opts.style_preset) }
end
Expand Down
12 changes: 6 additions & 6 deletions lua/bufferline/pick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ local strwidth = vim.api.nvim_strwidth

M.current = {}

local valid = "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ"

function M.reset() M.current = {} end

-- Prompts user to select a buffer then applies a function to the buffer
Expand All @@ -35,15 +33,17 @@ end
---@param element bufferline.Tab|bufferline.Buffer
---@return string?
function M.get(element)
local valid_alphabet = config.options.pick.alphabet

local first_letter = element.name:sub(1, 1)
-- should only match alphanumeric characters
local invalid_char = first_letter:match("[^%w]")

if not M.current[first_letter] and not invalid_char then
local is_valid_char = first_letter:match("[" .. valid_alphabet .. "]")

if not M.current[first_letter] and is_valid_char then
M.current[first_letter] = element.id
return first_letter
end
for letter in valid:gmatch(".") do
for letter in valid_alphabet:gmatch(".") do
if not M.current[letter] then
M.current[letter] = element.id
return letter
Expand Down

0 comments on commit 5cc447c

Please sign in to comment.