Different settings for filename or import statements?

I’m kinda curious whether it would be possible to either load different instructions via filename or possibly import statements at the top of the file. I know you essentially have different configurations loaded via extension, but I was wondering about taking it a step further and having different settings per project type.

say you have a file named random_scraper.py because it has that _scraper.py in the filename it loads snippets useful for working with the request, beautifulsoup, and scrapy libraries. you could even take this a step further and use a tool like yeoman to create new files from templates based on the filename.

another direction to take could be loading different configurations based on the import statements at the top of the file, though that seems like a less desirable solution because you don’t know necessarily if the user will put the import statements at the very top.

I think it is possible, but may wary between different users and their personal preferences. You and always inspect the name of the buffer when opening and run hooks based on it, e.g.

hook global BufCreate .*_scraper\.py$ %{
    # bring your snippets to the buffer scope
    # or souche some configuration from somewhere
}

You can have this in your kakrc and it will only affect your workflow without affecting other developers