[Feature Request] Auto associate a set of file with a specific tab when openning
Opened this issue · 4 comments
I'm looking for a way to define a condition to associate a set of file with a tab
For example, I would like when openning, each "*.test.ts" come into a specific tab.
It's best if I can provide a callback to define association policy during setup, something like the pseudo code
require("scope").setup {
policy = function (file)
if (file.end_width(".test.ts") then return 1 end
end
}
Can't you do it with something like this?
vim.api.nvim_create_autocmd("BufAdd", {
callback = function(args)
if args.file:match ".*.test.ts" then
vim.cmd.Bdelete() -- famiu/bufdelete.nvim
vim.cmd.tabfirst()
vim.cmd.buffer(args.buf)
end
end,
})
Can't you do it with something like this?
vim.api.nvim_create_autocmd("BufAdd", { callback = function(args) if args.file:match ".*.test.ts" then vim.cmd.Bdelete() -- famiu/bufdelete.nvim vim.cmd.tabfirst() vim.cmd.buffer(args.buf) end end, })
Thanks for the answer.
I tried with your suggestion. Unfortunately, using this config, I encountered few problem.
- my filetype plugin does not work (more accurately, the filetype for the new buffer is not set) .
- the new opened file is not shown in my bufferline bufs list
- previous opened test file are all closed (Open a.test.ts, then open b.test.ts, then only b.test.ts occured in my first tab)
I will try to figure out what is wrong this weekend.
Anyway, IMHO it's easier and cleaner if we can include the policy inside the plugin config, rather have to create a separate auto-command.
I thought there would be an easy fix like a PreAdd event. I will think about it. Feel free to open a PR if you have something in mind, like the policy strategy.