Skip to content

Commit 5cc447c

Browse files
authored
feat(pick): add config option for pick alphabet (#972)
1 parent 5c528be commit 5cc447c

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

doc/bufferline.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ The available configuration are:
170170
local modified_a = vim.fn.getftime(buffer_a.path)
171171
local modified_b = vim.fn.getftime(buffer_b.path)
172172
return modified_a > modified_b
173-
end
173+
end,
174+
pick = {
175+
alphabet = "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ1234567890",
176+
},
174177
}
175178
}
176179
<
@@ -658,6 +661,19 @@ this can also be mapped to something like
658661
nnoremap <silent> gD :BufferLinePickClose<CR>
659662
>
660663
664+
You can configure the characters used for selecting buffers using the
665+
`pick.alphabet` option. By default, both uppercase and lowercase
666+
alphanumeric characters are used.
667+
>lua
668+
options = {
669+
pick = {
670+
alphabet = "abcdefghijklmopqrstuvwxyz"
671+
}
672+
}
673+
<
674+
675+
With the configuration above, bufferline will only use lowercase letters.
676+
661677
==============================================================================
662678
MOUSE ACTIONS *bufferline-mouse-actions*
663679

lua/bufferline/config.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ local function get_defaults()
674674
groups = { items = {}, options = { toggle_hidden_on_enter = true } },
675675
hover = { enabled = false, reveal = {}, delay = 200 },
676676
debug = { logging = false },
677+
pick = {
678+
alphabet = "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ1234567890",
679+
},
677680
}
678681
return { options = opts, highlights = derive_colors(opts.style_preset) }
679682
end

lua/bufferline/pick.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ local strwidth = vim.api.nvim_strwidth
1010

1111
M.current = {}
1212

13-
local valid = "abcdefghijklmopqrstuvwxyzABCDEFGHIJKLMOPQRSTUVWXYZ"
14-
1513
function M.reset() M.current = {} end
1614

1715
-- Prompts user to select a buffer then applies a function to the buffer
@@ -35,15 +33,17 @@ end
3533
---@param element bufferline.Tab|bufferline.Buffer
3634
---@return string?
3735
function M.get(element)
36+
local valid_alphabet = config.options.pick.alphabet
37+
3838
local first_letter = element.name:sub(1, 1)
39-
-- should only match alphanumeric characters
40-
local invalid_char = first_letter:match("[^%w]")
4139

42-
if not M.current[first_letter] and not invalid_char then
40+
local is_valid_char = first_letter:match("[" .. valid_alphabet .. "]")
41+
42+
if not M.current[first_letter] and is_valid_char then
4343
M.current[first_letter] = element.id
4444
return first_letter
4545
end
46-
for letter in valid:gmatch(".") do
46+
for letter in valid_alphabet:gmatch(".") do
4747
if not M.current[letter] then
4848
M.current[letter] = element.id
4949
return letter

0 commit comments

Comments
 (0)