tiagovla / scope.nvim

Revolutionize Your Neovim Tab Workflow: Introducing Enhanced Tab Scoping!
406 stars 21 forks source link

[Feature Request] Auto associate a set of file with a specific tab when openning #13

Open tuanbass opened 1 year ago

tuanbass commented 1 year ago

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 
}
tiagovla commented 1 year ago

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,
})
tuanbass commented 1 year ago

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.

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.

tiagovla commented 1 year ago

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.

tuanbass commented 1 year ago

After testing, I found some points: