Packer.nvim: PackerCompile sometimes produces invalid code

Created on 26 Sep 2020  路  7Comments  路  Source: wbthomason/packer.nvim

First of all, thank you for making such a nice plugin. I've been switching my config over to Packer and it is a joy to use. I particularly like the code generation feature, it allows me to simplify my configuration and smoothes over some of the rough edges of native packages.

Unfortunately I seem to have hit a few edge cases while making the transition. I apologize in advance for being "that annoying user" :)

Under certain circumstances, Packer will generate invalid code. I wrote a minimal packages.lua that reproduces the issue:

vim.cmd 'packadd! packer.nvim'

require'packer'.startup(function(use)
    use {
        'glacambre/firenvim',
        cond = 'vim.g.started_by_firenvim',
        config = function()
            vim.o.laststatus = 0
            vim.bo.filetype = 'markdown'
        end,
    }
end)

And here's the code being generated by packer:

-- Conditional loads
if
    vim.g.started_by_firenvim
    then
      vim.cmd("packadd firenvim")

    -- Config for: firenvim
    ^[LJ^B^BQ^@^@^B^@^F^@  6^@^@^@9^@^A^@)^A^@^@=^A^B^@6^@^@^@9^@^C^@'^A^E^@=^A^D^@K^@^A^@^Mmarkdown^Mfiletype^Gbo^Olaststatus^Fo^Hvim^@

    end

I'm assuming the combination of using cond and passing a function to config is what causes the problem. Passing a string to it instead solves the issue.

bug

All 7 comments

Thanks for the report (and please never apologize for finding and reporting weird bugs; I love users who do that :) ).

Indeed, this seems to be a weird interaction with cond and config. I'm working on a fix now.

@nanotee This should be fixed now; please let me know if you continue to experience errors!

No more errors on my end, thanks for the quick fix!

Of course, thanks for the excellent report(s)!

It seems I spoke too soon. The commit fixed passing functions to config, but now passing a string doesn't work:

local packer = require('packer')

packer.startup(function(use)
    use {
        'user/plugin',
        cond = 'foo',
        config = 'require("foo.bar")',
    }
end)

Generates:

-- Conditional loads
if
    foo
    then
      vim.cmd("packadd plugin")

    -- Config for: plugin

    end

Oh, I know what this is. Dumb error on my part - should be fixed now, in 55dd0f1. Sorry about that.

Everything seems to work now, thanks again

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cempassi picture cempassi  路  9Comments

kdav5758 picture kdav5758  路  6Comments

wbthomason picture wbthomason  路  7Comments

GustavoPrietoP picture GustavoPrietoP  路  7Comments

clason picture clason  路  4Comments