wbthomason / packer.nvim

A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
MIT License
7.72k stars 262 forks source link

Lazy load on something like `exclude_ft` #1131

Closed cuducos closed 1 year ago

cuducos commented 1 year ago

Describe the feature

I love the ft config, as in use {'FooBar/Baz', ft = 'bax'} but sometimes I want a certain plugin to be available in every ft but one or two.

Use case

My use case is that a lot of treesitter + virualtext plugins do not make sense in languages that differ considerably in syntax from others, for example:

Plugins that makes sense here Might not make sense here
C-style like Rust or Go ML-style like Haskell or Elm
Blocks defined w/ open & close char/keywords, like JS or Ruby Indented-based blocks like Python

I would like to do, for example use {'FooBar/Baz', exclude_ft = 'bax'} and have this plugin working in every ft but bax.

Concrete example

haringsrob/nvim_context_vt makes a lot of sense for almost all languages I use in my routine, but Python. In Python, it just pollutes the buffer. This plugin in particular has an exclusion list by ft and my idea came from there: why not bring this option to all Packer-managed plugins?

Possible implementation

I see that ft becomes fts and then we create auto commands from them:

https://github.com/wbthomason/packer.nvim/blob/d3ecfb4c8a33b46ea79356ef20b6a9e7789c86a2/lua/packer/compile.lua#L504-L514

We could do an extra check on that for loop to skip ft in exlude_fts, e.g.:

local function skip(ft)
    for _, val in ipairs(fts) do
        if val == ft then
            return true
        end
    end
    return false
end

for ft, names in pairs(fts) do
    if not skip(ft) then
        table.insert(
            ft_aucmds,
            -- etc ...
        )
    end
end

If that makes sense I am happy to open a PR, but as I have little experience with Lua I might need an bit of support and a few rounds of code reviews to make the PR production ready : )

lewis6991 commented 1 year ago

In v2 this should be achievable via custom loaders (see #1162).

max397574 commented 1 year ago

I think this would already possible with autocmd on BufEnter inside setup and if not vim.tbl_contains({"filetype2","filetype1"},vim.bo[args.buf]) load....

cuducos commented 1 year ago

100% agree, @lewis6991! Once #1162 is merged, I think we can close this issue. Thank you so much.

cuducos commented 1 year ago

Closed by #1162