Packer.nvim: Feature request - "if not" in ft

Created on 12 Aug 2020  路  5Comments  路  Source: wbthomason/packer.nvim

For example i would not want to load an indent guide plugin for lisps because of this:
image

enhancement good first issue help wanted

Most helpful comment

So, this is like a negated filetype pattern? Neovim makes it a bit annoying to do that, as far as I know, but maybe there's some hack with e.g. a FileType * pattern that runs a function to check the filetype. That's super ugly and not very efficient, though.

I'll think more about how to do this, but ideas/examples from other plugins/PRs would be welcome.

All 5 comments

So, this is like a negated filetype pattern? Neovim makes it a bit annoying to do that, as far as I know, but maybe there's some hack with e.g. a FileType * pattern that runs a function to check the filetype. That's super ugly and not very efficient, though.

I'll think more about how to do this, but ideas/examples from other plugins/PRs would be welcome.

So, this is like a negated filetype pattern? Neovim makes it a bit annoying to do that, as far as I know, but maybe there's some hack with e.g. a FileType * pattern that runs a function to check the filetype. That's super ugly and not very efficient, though.

I'll think more about how to do this, but ideas/examples from other plugins/PRs would be welcome.

You can access the filetype as buffer local option: vim.bo.filetype

Right - accessing the filetype isn't so much the hard part; it's more that it seems inelegant and potentially inefficient to run a check on every FileType * event (as my only current idea for doing this would require).

Maybe that isn't so bad? If anyone feels like making a PR implementing that approach (or a better approach if you have an idea for one), I'd be happy to take a look.

Not sure, if FileType events are retrievable as a table. You could then create a smaller table with the necessary functions.

I don't know of a way to get a table of FileType autocommands, but maybe it's possible.

The approach I'm proposing would look something like:

  1. Collect the set of plugins loaded on a not_ft event, e.g. {html = {'foo', 'bar'}, css = {'baz'}}
  2. Make an "inverted" index, e.g. index = {html = {'baz'}, css = {'foo', 'bar'}}
  3. Make an autocommand au FileType * lua require('packer.load').not_ft(<amatch>)
  4. packer.load.not_ft is something like (in semi-pseudocode):
function not_ft(ft)
  if not index[ft] then
    load(all_not_ft_plugins) 
  elseif
    index[ft] then load(index[ft])
  end
end

I suppose this isn't as ugly as I'd conceived it to be...
I won't have time to add this before March, but if someone wants to pick it up, I'll have time to look at a PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nanotee picture nanotee  路  7Comments

YaBoiBurner picture YaBoiBurner  路  4Comments

GustavoPrietoP picture GustavoPrietoP  路  7Comments

kdav5758 picture kdav5758  路  6Comments

cempassi picture cempassi  路  9Comments