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

How do you load config file? #81

Closed
medwatt opened this issue Oct 10, 2021 · 5 comments
Closed

How do you load config file? #81

medwatt opened this issue Oct 10, 2021 · 5 comments
Labels
question Further information is requested

Comments

@medwatt
Copy link

medwatt commented Oct 10, 2021

I currently have this in my init.lua. As long as the plugin is not installed, I get an error on startup telling me the plugin is not installed. If I install the plugin, then the code works fine and runs the config file. Let's say I delete my plugins folder and want to reinstall everything from scratch. Then, I will have to all the lines with the run option, install the plugins, and reinsert the line back. Surely, there has to be a better way to do this.

require "paq" {
    {'folke/which-key.nvim', run = require('main.plugin_config.which-key_config')}
}
@LukeDRussell
Copy link

I just have separate calls, like so:

-- Use paq to install plugins
require "paq" {
        "savq/paq-nvim";
        "ojroques/nvim-hardline"
}

-- hardline status and tab line
require('hardline').setup {
        theme = 'default'
}

@Bowuigi
Copy link

Bowuigi commented Dec 7, 2021

Replace whatever is on the run with the following:

function() if pcall(require, "[plugin]") then require("main.plugin_config.[plugin]_config")() end end

Here is a function to generate all of this automagically:

function PConfig(plugin)
    return function() if pcall(require, plugin) then require("main.plugin_config."..plugin.."_config")() end end
end

So you could just do, for example:

require("paq") {
    {"folke/which-key.nvim", run = PConfig("which-key")}
}

@savq savq added the question Further information is requested label Dec 10, 2021
@RayZ0rr
Copy link

RayZ0rr commented Jan 13, 2022

Here is a function to generate all of this automagically:

This looks like a neat little alternative to config in packer. @savq Could you add this to README or the wiki ?

@megalithic
Copy link

Any thoughts on if this is still the way to achieve such packer-esque behaviour for collocating plugin configs? Since run only seems to run post-install; how does this work to actively do the config require sourcing each time you load nvim? @Bowuigi / @savq -- thank you for this amazing plugin!

@RayZ0rr
Copy link

RayZ0rr commented Mar 10, 2022

I don't think this fits paq's minimalistic nature. One solution to this problem is to put plugins and configurations in a table and then load them separately. Eg from my own config:

local plugAndConfig = {

  -- Each element should be like this:
  -- {'plugin/name','config name used in require'}
  -- config name is optional

  -- Let Paq (plugin manager) manage itself
  {"savq/paq-nvim"},

  --------------------------------------------------
  -- GENERAL
  --------------------------------------------------

  -- fzf ----------------------------------------
  {'vijaymarupudi/nvim-fzf'},
  {'kyazdani42/nvim-web-devicons'},
  {'ibhagwan/fzf-lua','plugins/general/fzf-lua'},
  -- Undo history ------------------------------
  {'mbbill/undotree',"plugins/general/undotree"},
  -- Build, Run tasks (commands) in background asynchronously
  {'skywind3000/asyncrun.vim','plugins/general/asyncRunTasks'},
  -- File Browser ------------------------------
  {'is0n/fm-nvim','plugins/general/fm-nvim'},
  -- Autocompletion plugin ---------------------
  {'hrsh7th/cmp-nvim-lsp'},
  {'hrsh7th/cmp-buffer'},
  {'hrsh7th/cmp-path'},
  {'hrsh7th/nvim-cmp','plugins/general/nvim-cmp'},
  -- Other plugins and configs
}

local plugList = {}
local configList = {}

for idx, items in pairs(plugAndConfig) do
  plugList[idx] = items[1]
  if items[2] then
    table.insert(configList,items[2]);
  end
end

-- don't throw any error on first use by packer
local ok, paq = pcall(require, "paq")
if not ok then return end

require("paq")(plugList)

-- Load configs
for idx, config in pairs(configList) do
  require(config)
end

@medwatt medwatt closed this as completed Mar 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants