diff --git a/README.md b/README.md index 0e653a3..a4b9f44 100755 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ require("lz.n").load(plugins) | **ft** | `string?` or `string[]` | Lazy-load on filetype. | `ft` | | **keys** | `string?` or `string[]` or `lz.n.KeysSpec[]` | Lazy-load on key mapping. | `keys` | | **colorscheme** | `string?` or `string[]` | Lazy-load on colorscheme. | None. `lazy.nvim` lazy-loads colorschemes automatically[^2]. | -| **priority** | `number?` | Only useful for **start** plugins (not lazy-loaded) to force loading certain plugins first. Default priority is `50`. It's recommended to set this to a high number for colorschemes. | `priority` | +| **priority** | `number?` | Only useful for **start** plugins (not lazy-loaded) to force loading certain plugins first. Default priority is `50` (or `1000` if `colorscheme` is set). | `priority` | [^1]: In contrast to `lazy.nvim`'s `name` field, `lz.n`'s `name` *is not optional*. @@ -147,7 +147,6 @@ require("lz.n").load { "sweetie.nvim", -- lazy-load when setting the `sweetie` colorscheme colorscheme = "sweetie", - priority = 1000, }, { "vim-startuptime", diff --git a/lua/lz/n/loader.lua b/lua/lz/n/loader.lua index 4f29e98..28c1e96 100644 --- a/lua/lz/n/loader.lua +++ b/lua/lz/n/loader.lua @@ -6,6 +6,8 @@ local M = {} local DEFAULT_PRIORITY = 50 +local DEFAULT_COLORSCHEME_PRIORITY = 1000 + ---@package ---@param plugin lz.n.Plugin function M._load(plugin) @@ -40,6 +42,11 @@ local function run_before_all(plugins) end end +---@param plugin lz.n.Plugin +local function get_priority(plugin) + return plugin.priority or (plugin.colorscheme and DEFAULT_COLORSCHEME_PRIORITY) or DEFAULT_PRIORITY +end + ---@param plugins table ---@return lz.n.Plugin[] local function get_eager_plugins(plugins) @@ -52,7 +59,7 @@ local function get_eager_plugins(plugins) table.sort(result, function(a, b) ---@cast a lz.n.Plugin ---@cast b lz.n.Plugin - return (a.priority or DEFAULT_PRIORITY) > (b.priority or DEFAULT_PRIORITY) + return get_priority(a) > get_priority(b) end) return result end