startup: load once and only when called for devicons (#1139)

This commit is contained in:
TJ DeVries
2021-08-20 13:47:30 -04:00
committed by GitHub
parent ea5ab8f7c4
commit 260f4617b6

View File

@@ -1,5 +1,3 @@
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
local Path = require "plenary.path" local Path = require "plenary.path"
local Job = require "plenary.job" local Job = require "plenary.job"
@@ -456,7 +454,20 @@ utils.align_str = function()
error "align_str deprecated. please use plenary.strings.align_str" error "align_str deprecated. please use plenary.strings.align_str"
end end
utils.transform_devicons = (function() local load_once = function(f)
local resolved = nil
return function(...)
if resolved == nil then
resolved = f()
end
return resolved(...)
end
end
utils.transform_devicons = load_once(function()
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
if has_devicons then if has_devicons then
if not devicons.has_loaded() then if not devicons.has_loaded() then
devicons.setup() devicons.setup()
@@ -482,9 +493,11 @@ utils.transform_devicons = (function()
return display return display
end end
end end
end)() end)
utils.get_devicons = load_once(function()
local has_devicons, devicons = pcall(require, "nvim-web-devicons")
utils.get_devicons = (function()
if has_devicons then if has_devicons then
if not devicons.has_loaded() then if not devicons.has_loaded() then
devicons.setup() devicons.setup()
@@ -508,6 +521,6 @@ utils.get_devicons = (function()
return "" return ""
end end
end end
end)() end)
return utils return utils