mirror of
https://github.com/norcalli/nvim-colorizer.lua.git
synced 2026-09-10 07:06:14 -04:00
chore: use lazy.nvim in minimal.lua (#106)
* chore: refactors minimal.lua to use lazy.nvim
This commit is contained in:
parent
a040f4d7b2
commit
6059927ee6
|
|
@ -16,7 +16,7 @@ return {
|
|||
css = true,
|
||||
css_fn = true,
|
||||
mode = "background",
|
||||
tailwind = false,
|
||||
tailwind = "both",
|
||||
sass = { enable = false, parsers = { css = true } },
|
||||
virtualtext = "■",
|
||||
virtualtext_inline = false,
|
||||
|
|
|
|||
156
test/minimal.lua
156
test/minimal.lua
|
|
@ -1,75 +1,123 @@
|
|||
-- Run this file as `nvim --clean -u minimal.lua`
|
||||
local base_dir = "colorizer_issue"
|
||||
local use_remote = false
|
||||
local local_plugin_dir = os.getenv("HOME") .. "/git/nvim-colorizer.lua"
|
||||
|
||||
local function clone_repo_if_missing(name, url, dir)
|
||||
local install_path = vim.fn.fnamemodify(dir .. "/" .. name, ":p")
|
||||
if vim.fn.isdirectory(install_path) == 0 then
|
||||
vim.fn.system({ "git", "clone", "--depth=1", url, install_path })
|
||||
end
|
||||
vim.opt.runtimepath:append(install_path)
|
||||
-- ADD ANY ADDITIONAL PLUGINS TO `plugins` TABLE IN `define_plugins` FUNCTION
|
||||
|
||||
local settings = {
|
||||
use_remote = false, -- Use colorizer master or local git directory
|
||||
base_dir = "colorizer_repro", -- Directory to clone lazy.nvim
|
||||
local_plugin_dir = os.getenv("HOME") .. "/git/nvim-colorizer.lua", -- Local git directory for colorizer. Used if use_remote is false
|
||||
}
|
||||
|
||||
if not vim.loop.fs_stat(settings.base_dir) then
|
||||
vim.fn.system({
|
||||
"git",
|
||||
"clone",
|
||||
"--filter=blob:none",
|
||||
"https://github.com/folke/lazy.nvim.git",
|
||||
"--branch=stable",
|
||||
settings.base_dir,
|
||||
})
|
||||
end
|
||||
vim.opt.rtp:prepend(settings.base_dir)
|
||||
|
||||
if use_remote then
|
||||
local remote_plugins = {
|
||||
colorizer = "https://github.com/NvChad/nvim-colorizer.lua",
|
||||
kanagawa = "https://github.com/rebelot/kanagawa.nvim",
|
||||
}
|
||||
for name, url in pairs(remote_plugins) do
|
||||
clone_repo_if_missing(name, url, base_dir)
|
||||
end
|
||||
else
|
||||
local remote_plugins = {
|
||||
kanagawa = "https://github.com/rebelot/kanagawa.nvim",
|
||||
}
|
||||
for name, url in pairs(remote_plugins) do
|
||||
clone_repo_if_missing(name, url, base_dir)
|
||||
end
|
||||
if vim.fn.isdirectory(local_plugin_dir) == 1 then
|
||||
vim.opt.runtimepath:append(local_plugin_dir)
|
||||
else
|
||||
vim.notify("Local plugin directory not found: " .. local_plugin_dir, vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
|
||||
local function get_opts(file_path)
|
||||
local opts
|
||||
local success, err = pcall(function()
|
||||
opts = dofile(file_path)
|
||||
end)
|
||||
if not success then
|
||||
vim.notify("Error reloading file: " .. err, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
if not opts or type(opts) ~= "table" then
|
||||
vim.notify("Invalid options in " .. file_path, vim.log.levels.ERROR)
|
||||
return
|
||||
-- Load options returned from lua file
|
||||
local function load_options(file_path)
|
||||
local success, opts = pcall(dofile, file_path)
|
||||
if not success or type(opts) ~= "table" then
|
||||
vim.notify("Failed to load options from " .. file_path, vim.log.levels.ERROR)
|
||||
return nil
|
||||
end
|
||||
return opts
|
||||
end
|
||||
|
||||
-- Configure setup opts
|
||||
local setup_opts = get_opts("expect.txt")
|
||||
require("colorizer").setup(setup_opts)
|
||||
-- Configure colorizer plugin
|
||||
local function configure_colorizer()
|
||||
vim.opt.termguicolors = true
|
||||
local opts = load_options("expect.txt")
|
||||
if opts then
|
||||
require("colorizer").setup(opts)
|
||||
else
|
||||
vim.notify("Could not load colorizer options from expect.txt", vim.log.levels.WARN)
|
||||
end
|
||||
end
|
||||
|
||||
local function add_colorizer_plugin(plugins)
|
||||
local base_config = {
|
||||
event = "BufReadPre",
|
||||
cmd = {
|
||||
"ColorizerToggle",
|
||||
"ColorizerAttachToBuffer",
|
||||
"ColorizerDetachFromBuffer",
|
||||
"ColorizerReloadAllBuffers",
|
||||
},
|
||||
config = configure_colorizer,
|
||||
}
|
||||
if settings.use_remote then
|
||||
table.insert(
|
||||
plugins,
|
||||
vim.tbl_extend("force", base_config, {
|
||||
"NvChad/nvim-colorizer.lua",
|
||||
url = "https://github.com/NvChad/nvim-colorizer.lua",
|
||||
})
|
||||
)
|
||||
else
|
||||
local local_dir = settings.local_plugin_dir
|
||||
if vim.fn.isdirectory(local_dir) == 1 then
|
||||
vim.opt.rtp:append(local_dir)
|
||||
table.insert(
|
||||
plugins,
|
||||
vim.tbl_extend("force", base_config, {
|
||||
dir = local_dir,
|
||||
lazy = false,
|
||||
})
|
||||
)
|
||||
else
|
||||
vim.notify("Local plugin directory not found: " .. local_dir, vim.log.levels.ERROR)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Define additional plugins
|
||||
local function define_plugins()
|
||||
local plugins = {
|
||||
{
|
||||
"rebelot/kanagawa.nvim",
|
||||
url = "https://github.com/rebelot/kanagawa.nvim",
|
||||
config = function()
|
||||
vim.cmd.colorscheme("kanagawa")
|
||||
end,
|
||||
},
|
||||
}
|
||||
add_colorizer_plugin(plugins)
|
||||
return plugins
|
||||
end
|
||||
|
||||
-- Initialize and setup lazy.nvim
|
||||
local ok, lazy = pcall(require, "lazy")
|
||||
if not ok then
|
||||
vim.notify("Failed to require lazy.nvim", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
lazy.setup(define_plugins())
|
||||
|
||||
-- Automatically reload colorizer configuration on `expect.txt` changes
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
pattern = "expect.txt",
|
||||
callback = function(evt)
|
||||
vim.schedule(function()
|
||||
local opts = get_opts(evt.match)
|
||||
if not opts then
|
||||
return
|
||||
local opts = load_options(evt.match)
|
||||
if opts then
|
||||
require("colorizer").detach_from_buffer(evt.buf)
|
||||
require("colorizer").attach_to_buffer(evt.buf, opts.user_default_options)
|
||||
vim.notify(
|
||||
"Colorizer reloaded with updated options from " .. evt.match,
|
||||
vim.log.levels.INFO
|
||||
)
|
||||
end
|
||||
opts = opts.user_default_options
|
||||
require("colorizer").detach_from_buffer(evt.buf)
|
||||
require("colorizer").attach_to_buffer(evt.buf, opts)
|
||||
vim.notify("Colorizer reloaded with updated options from " .. evt.match, vim.log.levels.INFO)
|
||||
end)
|
||||
end,
|
||||
})
|
||||
|
||||
vim.cmd.colorscheme("kanagawa")
|
||||
vim.cmd.edit("expect.txt")
|
||||
|
||||
-- ADD INIT.LUA SETTINGS _NECESSARY_ FOR REPRODUCING THE ISSUE
|
||||
|
|
|
|||
Loading…
Reference in a new issue