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

feat(packer): query what plugin to load if none if specified #1055

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion lua/packer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,18 @@ packer.make_commands = function()
vim.cmd [[command! -nargs=* PackerCompile lua require('packer').compile(<q-args>)]]
vim.cmd [[command! PackerStatus lua require('packer').status()]]
vim.cmd [[command! PackerProfile lua require('packer').profile_output()]]
vim.cmd [[command! -bang -nargs=+ -complete=customlist,v:lua.require'packer'.loader_complete PackerLoad lua require('packer').loader(<f-args>, '<bang>' == '!')]]
if vim.api.nvim_create_user_command then
vim.api.nvim_create_user_command('PackerLoad', function(opts)
packer.load({plugin_names = opts.fargs, force = opts.bang})
end,
{
bang = true,
complete = packer.loader_complete,
nargs = '*',
})
else
vim.cmd [[command! -bang -nargs=+ -complete=customlist,v:lua.require'packer'.loader_complete PackerLoad lua require('packer').loader(<f-args>, '<bang>' == '!')]]
end
end

packer.reset = function()
Expand Down Expand Up @@ -811,6 +822,25 @@ packer.loader = function(...)
if type(plugin_names[#plugin_names]) == 'boolean' then
plugin_names[#plugin_names] = nil
end
packer.load({plugin_names = plugin_names, force = force})
end

packer.load = function(opts)
local plugin_names = opts.plugin_names
local force = opts.force
if #plugin_names == 0 then
vim.ui.select(packer.loader_complete(), {
'Pick plugin to load',
}, function(choice)
if not choice then
return
end
packer.load({
plugin_names = {choice},
force = opts.force,
})
end)
end

-- We make a new table here because it's more convenient than expanding a space-separated string
-- into the existing plugin_names
Expand All @@ -831,6 +861,7 @@ end
-- Intended to provide completion for PackerLoad command
packer.loader_complete = function(lead, _, _)
local completion_list = {}
lead = lead or ''
for name, plugin in pairs(_G.packer_plugins) do
if vim.startswith(name, lead) and not plugin.loaded then
table.insert(completion_list, name)
Expand Down