Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tuanbass opened this issue Aug 4, 2023 · 4 comments

Comments

@tuanbass
Copy link
Contributor

tuanbass commented Aug 4, 2023

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
Copy link
Owner

tiagovla commented Aug 4, 2023

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
Copy link
Contributor Author

tuanbass commented Aug 11, 2023

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.

@tiagovla
Copy link
Owner

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
Copy link
Contributor Author

After testing, I found some points:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants