@@ -607,7 +607,7 @@ function Plugin.new(spec)
607607    events  =  {}, --  Events to trigger loading
608608    filetypes  =  {}, --  Filetypes to trigger loading
609609    commands  =  {}, --  Commands to trigger loading
610-     keys  =  {}, --  Keys to trigger loading
610+     mappings  =  {}, --  Keys to trigger loading
611611
612612    --  Configuration
613613    setup_opts  =  spec .setup  or  {}, --  Options for plugin setup()
@@ -924,29 +924,34 @@ end
924924--  Set up lazy loading for specific keymaps
925925function  Plugin :keys (mappings )
926926  self .is_lazy  =  true 
927-   self .keys  =  type (mappings ) ~=  ' table'  and  { mappings  } or  mappings 
927+   self .mappings  =  type (mappings ) ~=  ' table'  and  { mappings  } or  mappings 
928928
929-   for  _ , mapping  in  ipairs (self .keys ) do 
929+   for  _ , mapping  in  ipairs (self .mappings ) do 
930930    local  mode , lhs , rhs , opts 
931931
932932    if  type (mapping ) ==  ' table'  then 
933933      mode  =  mapping [1 ] or  ' n' 
934934      lhs  =  mapping [2 ]
935-       rhs  =  mapping [3 ]  or   function ()  end 
935+       rhs  =  mapping [3 ]
936936      opts  =  mapping [4 ] or  {}
937937    else 
938938      mode , lhs  =  ' n'  , mapping 
939-       rhs  =  function () end 
940939      opts  =  {}
941940    end 
942941
943942    --  Create a keymap that loads the plugin first
944943    vim .keymap .set (mode , lhs , function ()
945-       if  self :load () and  type (rhs ) ==  ' function'  then 
946-         rhs ()
947-       elseif  self :load () and  type (rhs ) ==  ' string'  then 
948-         --  If rhs is a string command
949-         vim .cmd (rhs )
944+       if  type (rhs ) ==  ' function'  then 
945+         self :load (nil , rhs )
946+       elseif  type (rhs ) ==  ' string'  then 
947+         self :load (nil , function () vim .cmd (rhs ) end )
948+       elseif  type (rhs ) ==  ' nil'  then 
949+         --  If rhs not specified, it should be defined in plugin config
950+         --  In this case, we need to pass a callback
951+         self :load (nil , function ()
952+           vim .schedule (function ()
953+             vim .fn .feedkeys (lhs )
954+           end ) end )
950955      end 
951956    end , opts )
952957  end 
0 commit comments