Skip to content

Commit 7f2cc51

Browse files
committed
feat(ALL)!: unify naming of buffers created by modules
Details: - Having descriptive names makes helper buffers more identifiable in `:buffers!` output (instead of many `[Scratch]` entries) and allows storing useful information about buffer (like file path of explorer buffers in 'mini.files') closer to it. Resolve #1455
1 parent 18b01bc commit 7f2cc51

File tree

88 files changed

+260
-159
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+260
-159
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
- BREAKING: Use single space padding for default title/footer.
77
- BREAKING: Use 'single' as default window border in modules where it can be configured. On Neovim>=0.11 also respect non-empty 'winborder' option with lower precedence than explicitly configured value for the module.
88

9+
- BREAKING FEATURE: Unify how module-related buffers are named: `mini<module-name>://<buffer-number>/<useful-info>`. This structure allows creating identifiable, reasonably unique, and useful buffer names. This is a user facing change because in some cases the shown buffer's name will change (like in statusline of opened 'mini.starter' buffer or output of `:buffers!`).
10+
911
## mini.ai
1012

1113
- FEATURE: textobject identifier can now be any single character supported by `:h getcharstr()`. This also makes it possible to use characters outside of Latin alphanumeric and punctuation sets as `custom_textobjects` keys. Default textobject is extended to be anything but Latin letters (to fall back to `:h text-objects`).

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ These modules don't quite fit in any of the previous categories.
163163

164164
- **Buffer local configuration**. Each module can be additionally configured to use certain runtime config settings locally to buffer. See `mini.nvim-buffer-local-config` section in help file for more information.
165165

166+
- **Buffer names**. All module-related buffers are named according to the following format: `mini<module-name>://<buffer-number>/<useful-info>` (forward slashes are used on any platform; `<useful-info>` may be empty). This structure allows creating identifiable, reasonably unique, and useful buffer names. For example, 'mini.files' buffers are created per displayed directory/file with names like `minifiles://10/path/to/displayed/directory`.
167+
166168
- **Disabling**. Each module's core functionality can be disabled globally or locally to buffer. See "Disabling" section in module's help page for more details. See `mini.nvim-disabling-recipes` section in main help file for common recipes.
167169

168170
- **Silencing**. Each module providing non-error feedback can be configured to not do that by setting `config.silent = true` (either inside `setup()` call or on the fly).

doc/mini.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ Table of contents:
100100
to use certain runtime config settings locally to buffer.
101101
See |mini.nvim-buffer-local-config| for more information.
102102

103+
- <Buffer names>. All module-related buffers are named according to the
104+
following format: `mini<module-name>://<buffer-number>/<useful-info>`
105+
(forward slashes are used on any platform; `<useful-info>` may be empty).
106+
This structure allows creating identifiable, reasonably unique, and useful
107+
buffer names. For example, |MiniFiles| buffers are created per displayed
108+
directory/file with names like `minifiles://10/path/to/displayed/directory`.
109+
103110
- <Disabling>. Each module's core functionality can be disabled globally or
104111
locally to buffer. See "Disabling" section in module's help page for more
105112
details. See |mini.nvim-disabling-recipes| for common recipes.

lua/mini/animate.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,6 +1809,7 @@ H.make_openclose_step = function(action_type, win_id, config)
18091809
-- Empty buffer should always be valid (might have been closed by user command)
18101810
if H.empty_buf_id == nil or not vim.api.nvim_buf_is_valid(H.empty_buf_id) then
18111811
H.empty_buf_id = vim.api.nvim_create_buf(false, true)
1812+
H.set_buf_name(H.empty_buf_id, 'open-close-scratch')
18121813
end
18131814

18141815
-- Set step config to window. Possibly (re)open (it could have been
@@ -2099,6 +2100,8 @@ H.check_type = function(name, val, ref, allow_nil)
20992100
H.error(string.format('`%s` should be %s, not %s', name, ref, type(val)))
21002101
end
21012102

2103+
H.set_buf_name = function(buf_id, name) vim.api.nvim_buf_set_name(buf_id, 'minianimate://' .. buf_id .. '/' .. name) end
2104+
21022105
H.validate_if = function(predicate, x, x_name)
21032106
local is_valid, msg = predicate(x, x_name)
21042107
if not is_valid then H.error(msg) end

lua/mini/bufremove.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ MiniBufremove.unshow_in_window = function(win_id)
161161
local has_previous = pcall(vim.cmd, 'bprevious')
162162
if has_previous and cur_buf ~= vim.api.nvim_win_get_buf(win_id) then return end
163163

164-
-- Create new listed buffer
164+
-- Create new listed scratch buffer
165+
-- NOTE: leave it unnamed to allow `:h buffer-reuse`
165166
local new_buf = vim.api.nvim_create_buf(true, false)
166167
vim.api.nvim_win_set_buf(win_id, new_buf)
167168
end)

lua/mini/clue.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1639,7 +1639,10 @@ end
16391639
-- Buffer ---------------------------------------------------------------------
16401640
H.buffer_update = function()
16411641
local buf_id = H.state.buf_id
1642-
if not H.is_valid_buf(buf_id) then buf_id = vim.api.nvim_create_buf(false, true) end
1642+
if not H.is_valid_buf(buf_id) then
1643+
buf_id = vim.api.nvim_create_buf(false, true)
1644+
H.set_buf_name(buf_id, 'content')
1645+
end
16431646

16441647
-- Compute content data
16451648
local keys = H.query_to_keys(H.state.query)
@@ -1887,6 +1890,8 @@ H.check_type = function(name, val, ref, allow_nil)
18871890
H.error(string.format('`%s` should be %s, not %s', name, ref, type(val)))
18881891
end
18891892

1893+
H.set_buf_name = function(buf_id, name) vim.api.nvim_buf_set_name(buf_id, 'miniclue://' .. buf_id .. '/' .. name) end
1894+
18901895
H.map = function(mode, lhs, rhs, opts)
18911896
if lhs == '' then return end
18921897
opts = vim.tbl_deep_extend('force', { silent = true }, opts or {})

lua/mini/colors.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,7 @@ MiniColors.interactive = function(opts)
822822
local init_cs = opts.colorscheme == nil and MiniColors.get_colorscheme()
823823
or MiniColors.as_colorscheme(opts.colorscheme)
824824
local buf_id = vim.api.nvim_create_buf(true, true)
825+
H.set_buf_name(buf_id, 'interactive')
825826

826827
-- Write header lines
827828
local header_lines = {
@@ -2360,6 +2361,8 @@ H.check_type = function(name, val, ref, allow_nil)
23602361
H.error(string.format('`%s` should be %s, not %s', name, ref, type(val)))
23612362
end
23622363

2364+
H.set_buf_name = function(buf_id, name) vim.api.nvim_buf_set_name(buf_id, 'minicolors://' .. buf_id .. '/' .. name) end
2365+
23632366
H.round = function(x)
23642367
if x == nil then return nil end
23652368
return math.floor(x + 0.5)

lua/mini/completion.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ H.show_info_window = function()
12091209
if lines == nil or H.is_whitespace(lines) then return end
12101210

12111211
-- Ensure permanent buffer with "markdown" highlighting to display info
1212-
H.ensure_buffer(H.info, 'MiniCompletion:completion-item-info')
1212+
H.ensure_buffer(H.info, 'item-info')
12131213
H.ensure_highlight(H.info, 'markdown')
12141214
vim.api.nvim_buf_set_lines(H.info.bufnr, 0, -1, false, lines)
12151215

@@ -1366,7 +1366,7 @@ H.show_signature_window = function()
13661366
end
13671367

13681368
-- Ensure permanent buffer with current highlighting to display signature
1369-
H.ensure_buffer(H.signature, 'MiniCompletion:signature-help')
1369+
H.ensure_buffer(H.signature, 'signature-help')
13701370
H.ensure_highlight(H.signature, vim.bo.filetype)
13711371
vim.api.nvim_buf_set_lines(H.signature.bufnr, 0, -1, false, lines)
13721372

@@ -1516,7 +1516,7 @@ H.ensure_buffer = function(cache, name)
15161516

15171517
local buf_id = vim.api.nvim_create_buf(false, true)
15181518
cache.bufnr = buf_id
1519-
vim.api.nvim_buf_set_name(buf_id, name)
1519+
H.set_buf_name(buf_id, name)
15201520
vim.bo[buf_id].buftype = 'nofile'
15211521
end
15221522

@@ -1592,6 +1592,8 @@ H.check_type = function(name, val, ref, allow_nil)
15921592
H.error(string.format('`%s` should be %s, not %s', name, ref, type(val)))
15931593
end
15941594

1595+
H.set_buf_name = function(buf_id, name) vim.api.nvim_buf_set_name(buf_id, 'minicompletion://' .. buf_id .. '/' .. name) end
1596+
15951597
H.is_valid_buf = function(buf_id) return type(buf_id) == 'number' and vim.api.nvim_buf_is_valid(buf_id) end
15961598

15971599
H.is_valid_win = function(win_id) return type(win_id) == 'number' and vim.api.nvim_win_is_valid(win_id) end

lua/mini/deps.lua

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -780,9 +780,6 @@ H.cache = {
780780
git_version = nil,
781781
}
782782

783-
-- Buffer name counts
784-
H.buf_name_counts = {}
785-
786783
-- Helper functionality =======================================================
787784
-- Settings -------------------------------------------------------------------
788785
H.setup_config = function(config)
@@ -1254,7 +1251,7 @@ H.clean_confirm = function(paths)
12541251
if #paths_to_delete == 0 then return H.notify('Nothing to delete') end
12551252
H.clean_delete(paths_to_delete)
12561253
end
1257-
H.show_confirm_buf(lines, { name = 'mini-deps://confirm-clean', exec_on_write = finish_clean })
1254+
H.show_confirm_buf(lines, { name = 'confirm-clean', exec_on_write = finish_clean })
12581255

12591256
-- Define basic highlighting
12601257
vim.cmd('syntax region MiniDepsHint start="^\\%1l" end="\\%' .. n_header .. 'l$"')
@@ -1377,7 +1374,7 @@ H.update_feedback_confirm = function(lines)
13771374
MiniDeps.update(names, { force = true, offline = true })
13781375
end
13791376

1380-
H.show_confirm_buf(report, { name = 'mini-deps://confirm-update', exec_on_write = finish_update, setup_folds = true })
1377+
H.show_confirm_buf(report, { name = 'confirm-update', exec_on_write = finish_update, setup_folds = true })
13811378

13821379
-- Define basic highlighting
13831380
vim.cmd('syntax region MiniDepsHint start="^\\%1l" end="\\%' .. n_header .. 'l$"')
@@ -1414,7 +1411,7 @@ end
14141411
H.show_confirm_buf = function(lines, opts)
14151412
-- Show buffer
14161413
local buf_id = vim.api.nvim_create_buf(true, true)
1417-
H.buf_set_name(buf_id, opts.name)
1414+
H.set_buf_name(buf_id, opts.name)
14181415
vim.api.nvim_buf_set_lines(buf_id, 0, -1, false, lines)
14191416
vim.cmd('tab sbuffer ' .. buf_id)
14201417
local tab_num, win_id = vim.api.nvim_tabpage_get_number(0), vim.api.nvim_get_current_win()
@@ -1590,6 +1587,8 @@ H.check_type = function(name, val, ref, allow_nil)
15901587
H.error(string.format('`%s` should be %s, not %s', name, ref, type(val)))
15911588
end
15921589

1590+
H.set_buf_name = function(buf_id, name) vim.api.nvim_buf_set_name(buf_id, 'minideps://' .. buf_id .. '/' .. name) end
1591+
15931592
H.notify = vim.schedule_wrap(function(msg, level)
15941593
level = level or 'INFO'
15951594
if H.get_config().silent and level ~= 'ERROR' and level ~= 'WARN' then return end
@@ -1626,13 +1625,6 @@ H.source = function(path)
16261625
pcall(function() vim.cmd('source ' .. vim.fn.fnameescape(path)) end)
16271626
end
16281627

1629-
H.buf_set_name = function(buf_id, name)
1630-
local n = (H.buf_name_counts[name] or 0) + 1
1631-
H.buf_name_counts[name] = n
1632-
local suffix = n == 1 and '' or ('_' .. n)
1633-
vim.api.nvim_buf_set_name(buf_id, name .. suffix)
1634-
end
1635-
16361628
-- TODO: Remove after compatibility with Neovim=0.9 is dropped
16371629
H.islist = vim.fn.has('nvim-0.10') == 1 and vim.islist or vim.tbl_islist
16381630

lua/mini/extra.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ MiniExtra.pickers.git_branches = function(local_opts, opts)
590590
local win_target = (pick.get_picker_state().windows or {}).target
591591
if win_target == nil or not H.is_valid_win(win_target) then return end
592592
local buf_id = vim.api.nvim_create_buf(true, true)
593+
H.set_buf_name(buf_id, item:match('^%*?%s*(%S+)'))
593594
preview(buf_id, item)
594595
vim.api.nvim_win_set_buf(win_target, buf_id)
595596
end
@@ -645,6 +646,7 @@ MiniExtra.pickers.git_commits = function(local_opts, opts)
645646
local win_target = (pick.get_picker_state().windows or {}).target
646647
if win_target == nil or not H.is_valid_win(win_target) then return end
647648
local buf_id = vim.api.nvim_create_buf(true, true)
649+
H.set_buf_name(buf_id, item:match('^(%S+)'))
648650
preview(buf_id, item)
649651
-- Set filetype on opened buffer to trigger appropriate `FileType` event
650652
vim.bo[buf_id].filetype = 'git'
@@ -2076,6 +2078,8 @@ H.check_type = function(name, val, ref, allow_nil)
20762078
H.error(string.format('`%s` should be %s, not %s', name, ref, type(val)))
20772079
end
20782080

2081+
H.set_buf_name = function(buf_id, name) vim.api.nvim_buf_set_name(buf_id, 'miniextra://' .. buf_id .. '/' .. name) end
2082+
20792083
H.is_valid_win = function(win_id) return type(win_id) == 'number' and vim.api.nvim_win_is_valid(win_id) end
20802084

20812085
H.ensure_text_width = function(text, width)

0 commit comments

Comments
 (0)