2022-06-18 06:27:17 +02:00
|
|
|
-- thx to https://github.com/max397574/omega-nvim/blob/master/lua/omega/modules/ui/bufferline.lua
|
|
|
|
local M = {}
|
|
|
|
|
|
|
|
M.lazy_load = function(tb)
|
2022-06-14 14:06:27 +02:00
|
|
|
vim.api.nvim_create_autocmd(tb.events, {
|
|
|
|
pattern = "*",
|
|
|
|
group = vim.api.nvim_create_augroup(tb.augroup_name, {}),
|
|
|
|
callback = function()
|
|
|
|
if tb.condition() then
|
|
|
|
vim.api.nvim_del_augroup_by_name(tb.augroup_name)
|
|
|
|
|
|
|
|
-- dont defer for treesitter as it will show slow highlighting
|
|
|
|
-- This deferring only happens only when we do "nvim filename"
|
|
|
|
if tb.plugins ~= "nvim-treesitter" then
|
|
|
|
vim.defer_fn(function()
|
|
|
|
vim.cmd("PackerLoad " .. tb.plugins)
|
|
|
|
end, 0)
|
|
|
|
else
|
|
|
|
vim.cmd("PackerLoad " .. tb.plugins)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
M.bufferline = function()
|
2022-06-18 06:27:17 +02:00
|
|
|
M.lazy_load {
|
2022-06-16 09:11:12 +02:00
|
|
|
events = { "BufNewFile", "BufRead", "TabEnter" },
|
2022-06-14 14:06:27 +02:00
|
|
|
augroup_name = "BufferLineLazy",
|
|
|
|
plugins = "bufferline.nvim",
|
|
|
|
|
|
|
|
condition = function()
|
|
|
|
return #vim.fn.getbufinfo { buflisted = 1 } >= 2
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.colorizer = function()
|
2022-06-18 06:27:17 +02:00
|
|
|
M.lazy_load {
|
2022-06-14 14:06:27 +02:00
|
|
|
events = { "BufRead", "BufNewFile" },
|
|
|
|
augroup_name = "ColorizerLazy",
|
|
|
|
plugins = "nvim-colorizer.lua",
|
|
|
|
|
|
|
|
condition = function()
|
2022-06-18 06:27:17 +02:00
|
|
|
local items = { "#", "rgb", "hsl", "rgba", "hsla" }
|
2022-06-14 14:06:27 +02:00
|
|
|
|
|
|
|
for _, val in ipairs(items) do
|
|
|
|
if vim.fn.search(val) ~= 0 then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
-- load certain plugins only when there's a file opened in the buffer
|
2022-06-18 06:27:17 +02:00
|
|
|
-- if "nvim filename" is executed -> load the plugin after nvim gui loads
|
2022-06-14 14:06:27 +02:00
|
|
|
-- This gives an instant preview of nvim with the file opened
|
|
|
|
|
2022-06-18 06:27:17 +02:00
|
|
|
M.on_file_open = function(plugin_name)
|
|
|
|
M.lazy_load {
|
2022-06-14 14:06:27 +02:00
|
|
|
events = { "BufRead", "BufWinEnter", "BufNewFile" },
|
2022-06-18 06:27:17 +02:00
|
|
|
augroup_name = "BeLazyOnFileOpen" .. plugin_name,
|
|
|
|
plugins = plugin_name,
|
2022-06-14 14:06:27 +02:00
|
|
|
condition = function()
|
|
|
|
local file = vim.fn.expand "%"
|
|
|
|
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
M.gitsigns = function()
|
|
|
|
-- taken from https://github.com/max397574
|
2022-06-15 16:26:10 +02:00
|
|
|
vim.api.nvim_create_autocmd({ "BufRead" }, {
|
2022-06-14 14:06:27 +02:00
|
|
|
callback = function()
|
|
|
|
local function onexit(code, _)
|
|
|
|
if code == 0 then
|
|
|
|
vim.schedule(function()
|
|
|
|
require("packer").loader "gitsigns.nvim"
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
|
|
|
if lines ~= { "" } then
|
|
|
|
vim.loop.spawn("git", {
|
|
|
|
args = {
|
|
|
|
"ls-files",
|
|
|
|
"--error-unmatch",
|
2022-06-15 16:26:10 +02:00
|
|
|
vim.fn.expand "%:p:h",
|
2022-06-14 14:06:27 +02:00
|
|
|
},
|
|
|
|
}, onexit)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
return M
|