make lazy loading better...
- add a ft function to make it better when trying to load a plugin on a ft - add shorthands to make it easier to create one load condition
This commit is contained in:
43
lua/lazy/short.lua
Normal file
43
lua/lazy/short.lua
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
--- shorthands for when you only need to define one callback
|
||||||
|
local short = {}
|
||||||
|
|
||||||
|
--- create a usercommand which will trigger the plugin to load
|
||||||
|
---@param name string the name of the command
|
||||||
|
---@param opts vim.api.keyset.user_command? options
|
||||||
|
---@return function callback lazy setup
|
||||||
|
function short:cmd(name, opts)
|
||||||
|
return function(load)
|
||||||
|
load:cmd(name, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- create an auto command which will trigger the plugin to load
|
||||||
|
---@param event string the event to trigger on
|
||||||
|
---@param opts vim.api.keyset.create_autocmd? options
|
||||||
|
---@return function callback lazy setup
|
||||||
|
function short:auto(event, opts)
|
||||||
|
return function(load)
|
||||||
|
load:auto(event, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- create an auto command which will trigger on filetype
|
||||||
|
---@param filetype string filetype to register the auto on
|
||||||
|
function short:ft(filetype)
|
||||||
|
return function(load)
|
||||||
|
load:ft(filetype)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- create a keybind which will trigger the plugin to load
|
||||||
|
---@param mode string the mode to trigger in
|
||||||
|
---@param bind string the binding to use
|
||||||
|
---@param opts vim.keymap.set.Opts? options
|
||||||
|
---@return function callback lazy setup
|
||||||
|
function short:keymap(mode, bind, opts)
|
||||||
|
return function(load)
|
||||||
|
load:keymap(mode, bind, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return short
|
@ -46,7 +46,7 @@ function lazy:cmd(name, opts)
|
|||||||
table.insert(self.command_ids, name)
|
table.insert(self.command_ids, name)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- user an auto command which will trigger the plugin to load
|
--- create an auto command which will trigger the plugin to load
|
||||||
---@param event string the event to trigger on
|
---@param event string the event to trigger on
|
||||||
---@param opts vim.api.keyset.create_autocmd? options
|
---@param opts vim.api.keyset.create_autocmd? options
|
||||||
function lazy:auto(event, opts)
|
function lazy:auto(event, opts)
|
||||||
@ -60,6 +60,14 @@ function lazy:auto(event, opts)
|
|||||||
table.insert(self.auto_ids, vim.api.nvim_create_autocmd(event, opts))
|
table.insert(self.auto_ids, vim.api.nvim_create_autocmd(event, opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- create an auto command which will trigger on filetype
|
||||||
|
---@param filetype string filetype to register the auto on
|
||||||
|
function lazy:ft(filetype)
|
||||||
|
lazy:auto("FileType", {
|
||||||
|
pattern = filetype
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
--- create a keybind which will trigger the plugin to load
|
--- create a keybind which will trigger the plugin to load
|
||||||
---@param mode string the mode to trigger in
|
---@param mode string the mode to trigger in
|
||||||
---@param bind string the binding to use
|
---@param bind string the binding to use
|
||||||
|
Reference in New Issue
Block a user