Skip to content

Commit

Permalink
Re-merge modern command creation, with a fix for the observed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wbthomason committed Dec 5, 2022
2 parents 1d8babf + 0bf722c commit 502a89f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
11 changes: 10 additions & 1 deletion lua/packer/compile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,17 @@ local function make_loaders(_, plugins, output_lua, should_profile)
for command, names in pairs(commands) do
local command_line
if string.match(command, '^%w+$') then
-- Better command completions here are due to @folke
command_line = fmt(
'pcall(vim.cmd, [[command -nargs=* -range -bang -complete=file %s lua require("packer.load")({%s}, { cmd = "%s", l1 = <line1>, l2 = <line2>, bang = <q-bang>, args = <q-args>, mods = "<mods>" }, _G.packer_plugins)]])',
[[pcall(vim.api.nvim_create_user_command, '%s', function(cmdargs)
require('packer.load')({%s}, { cmd = '%s', l1 = cmdargs.line1, l2 = cmdargs.line2, bang = cmdargs.bang, args = cmdargs.args, mods = cmdargs.mods }, _G.packer_plugins)
end,
{nargs = '*', range = true, bang = true, complete = function()
require('packer.load')({%s}, { cmd = '%s' }, _G.packer_plugins)
vim.api.nvim_input('<space><bs><tab>')
end})]],
command,
table.concat(names, ', '),
command,
table.concat(names, ', '),
command
Expand Down
14 changes: 11 additions & 3 deletions lua/packer/load.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,18 @@ local function loader_apply_after(plugin, plugins, name)
end
end

local function apply_cause_side_effcts(cause)
local function apply_cause_side_effects(cause)
if cause.cmd then
local lines = cause.l1 == cause.l2 and '' or (cause.l1 .. ',' .. cause.l2)
cmd(fmt('%s %s%s%s %s', cause.mods or '', lines, cause.cmd, cause.bang, cause.args))
-- This is a hack to deal with people who haven't recompiled after updating to the new command
-- creation logic
local bang = ''
if type(cause.bang) == 'string' then
bang = cause.bang
elseif type(cause.bang) == 'boolean' and cause.bang then
bang = '!'
end
cmd(fmt('%s %s%s%s %s', cause.mods or '', lines, cause.cmd, bang, cause.args))
elseif cause.keys then
local extra = ''
while true do
Expand Down Expand Up @@ -161,7 +169,7 @@ packer_load = function(names, cause, plugins, force)
end
end
-- Retrigger cmd/keymap...
apply_cause_side_effcts(cause)
apply_cause_side_effects(cause)
end

local function load_wrapper(names, cause, plugins, force)
Expand Down

0 comments on commit 502a89f

Please sign in to comment.