refactor(nvim): Reformat code

This commit is contained in:
Ahmad Ansori Palembani 2025-05-27 11:02:37 +07:00
parent b39c708cde
commit 26954bc417
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
5 changed files with 507 additions and 501 deletions

View file

@ -1,95 +1,95 @@
return {
{ "wakatime/vim-wakatime", lazy = false },
{
-- FIXME: Use my own colourscheme
"folke/tokyonight.nvim",
lazy = false,
priority = 1000,
config = function ()
require("tokyonight").setup({
style = "moon",
transparent = true,
styles = {
sidebars = "transparent"
},
on_highlights = function (hl, c)
hl.CursorLineNr = { fg = c.yellow, bold = true }
end,
})
vim.cmd([[colorscheme tokyonight-moon]])
end,
},
{
"nvim-lualine/lualine.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function ()
local _progress = require("lualine.components.progress")
local progress = function ()
return "" .. _progress()
end
local _location = require("lualine.components.location")
local location = function ()
return "" .. _location()
end
require("lualine").setup {
options = {
theme = "tokyonight", -- FIXME: Use my own colourscheme
-- theme = "zi",
section_separators = "",
component_separators = "",
},
extensions = {"neo-tree", "oil", "lazy"},
sections = {
lualine_a = {"mode"},
lualine_b = {"branch", "diff", "diagnostics"},
lualine_c = {"filename"},
lualine_x = {location},
lualine_y = {progress},
lualine_z = {"encoding", "fileformat", "filetype"},
},
}
end,
},
{
"tpope/vim-commentary", -- shortcut to comment a line
keys = {
{ "gc", mode = { "n", "v", "i" } },
},
init = function ()
vim.api.nvim_create_autocmd("FileType", {
pattern = { "nix", "hyprlang" },
callback = function()
vim.opt_local.commentstring = "#%s"
end,
group = generalSettingsGroup,
})
end,
},
{
"dstein64/vim-startuptime",
cmd = "StartupTime", -- Note to self: lazy load on command
init = function ()
-- Note to self: init is called during startup. Configuration for vim plugins typically should be set in an init function
end,
},
{
"lukas-reineke/indent-blankline.nvim",
main = "ibl",
config = function ()
require("ibl").setup()
end
},
{
"folke/todo-comments.nvim",
cmd = { "TodoTrouble", "TodoTelescope" },
event = "LazyFile",
dependencies = { "nvim-lua/plenary.nvim" },
config = true,
},
{
"akinsho/git-conflict.nvim",
event = "LazyFile",
version = "*",
config = true,
},
{ "wakatime/vim-wakatime", lazy = false },
{
-- FIXME: Use my own colourscheme
"folke/tokyonight.nvim",
lazy = false,
priority = 1000,
config = function()
require("tokyonight").setup({
style = "moon",
transparent = true,
styles = {
sidebars = "transparent"
},
on_highlights = function(hl, c)
hl.CursorLineNr = { fg = c.yellow, bold = true }
end,
})
vim.cmd([[colorscheme tokyonight-moon]])
end,
},
{
"nvim-lualine/lualine.nvim",
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
local _progress = require("lualine.components.progress")
local progress = function()
return "" .. _progress()
end
local _location = require("lualine.components.location")
local location = function()
return "" .. _location()
end
require("lualine").setup {
options = {
theme = "tokyonight", -- FIXME: Use my own colourscheme
-- theme = "zi",
section_separators = "",
component_separators = "",
},
extensions = { "neo-tree", "oil", "lazy" },
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "filename" },
lualine_x = { location },
lualine_y = { progress },
lualine_z = { "encoding", "fileformat", "filetype" },
},
}
end,
},
{
"tpope/vim-commentary", -- shortcut to comment a line
keys = {
{ "gc", mode = { "n", "v", "i" } },
},
init = function()
vim.api.nvim_create_autocmd("FileType", {
pattern = { "nix", "hyprlang" },
callback = function()
vim.opt_local.commentstring = "#%s"
end,
group = generalSettingsGroup,
})
end,
},
{
"dstein64/vim-startuptime",
cmd = "StartupTime", -- Note to self: lazy load on command
init = function()
-- Note to self: init is called during startup. Configuration for vim plugins typically should be set in an init function
end,
},
{
"lukas-reineke/indent-blankline.nvim",
main = "ibl",
config = function()
require("ibl").setup()
end
},
{
"folke/todo-comments.nvim",
cmd = { "TodoTrouble", "TodoTelescope" },
event = "LazyFile",
dependencies = { "nvim-lua/plenary.nvim" },
config = true,
},
{
"akinsho/git-conflict.nvim",
event = "LazyFile",
version = "*",
config = true,
},
}

View file

@ -1,265 +1,266 @@
require("null.util").lazy_file()
return {
{
"mason-org/mason.nvim",
lazy = true,
config = function(_, _opts)
require("mason").setup()
end,
},
{
"mason-org/mason-lspconfig.nvim",
lazy = true,
dependencies = {
"mason-org/mason.nvim",
},
opts = {
ensure_installed = {
"ast_grep",
{
"mason-org/mason.nvim",
lazy = true,
config = function(_, _opts)
require("mason").setup()
end,
},
{
"mason-org/mason-lspconfig.nvim",
lazy = true,
dependencies = {
"mason-org/mason.nvim",
},
opts = {
ensure_installed = {
"ast_grep",
-- >> Kotlin
-- "kotlin_language_server",
-- << Kotlin
-- >> Kotlin
-- "kotlin_language_server",
-- << Kotlin
-- >> Python
"pyright",
-- "ruff",
-- "ruff_lsp",
-- << Python
-- >> Python
"pyright",
-- "ruff",
-- "ruff_lsp",
-- << Python
-- >> Jinja
"jinja_lsp",
-- << Jinja
-- >> Jinja
"jinja_lsp",
-- << Jinja
-- >> Lua
"emmylua_ls",
"luau_lsp",
-- << Lua
},
automatic_installation = { exclude = { "rust_analyzer" } },
},
config = function(_, opts)
require("mason-lspconfig").setup(opts)
end,
},
{
"neovim/nvim-lspconfig",
lazy = true,
dependencies = {
"mason-org/mason-lspconfig.nvim",
},
opts = function()
return {
diagnostics = {
underline = true,
update_in_insert = false,
virtual_text = {
spacing = 4,
source = "if_many",
prefix = "",
},
severity_sort = true,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "",
[vim.diagnostic.severity.WARN] = "",
[vim.diagnostic.severity.HINT] = "",
[vim.diagnostic.severity.INFO] = "",
},
},
},
}
end,
config = function(_, opts)
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
-- >> Lua
"emmylua_ls",
"luau_lsp",
-- << Lua
},
automatic_installation = { exclude = { "rust_analyzer" } },
},
config = function(_, opts)
require("mason-lspconfig").setup(opts)
end,
},
{
"neovim/nvim-lspconfig",
lazy = true,
dependencies = {
"mason-org/mason-lspconfig.nvim",
},
opts = function()
return {
diagnostics = {
underline = true,
update_in_insert = false,
virtual_text = {
spacing = 4,
source = "if_many",
prefix = "",
},
severity_sort = true,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = "",
[vim.diagnostic.severity.WARN] = "",
[vim.diagnostic.severity.HINT] = "",
[vim.diagnostic.severity.INFO] = "",
},
},
},
}
end,
config = function(_, opts)
vim.diagnostic.config(vim.deepcopy(opts.diagnostics))
-- Setup lspconfig
local has_cmp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
local capabilities = vim.tbl_deep_extend(
"force",
{},
vim.lsp.protocol.make_client_capabilities(),
has_cmp and cmp_nvim_lsp.default_capabilities() or {},
opts.capabilities or {}
)
local lsp = require("lspconfig")
-- FIXME: Re enable once ruff is able to type check
-- lsp.ruff_lsp.setup({
-- capabilities = capabilities,
-- })
lsp.pyright.setup({
capabilities = capabilities,
})
-- FIXME: Causing memleak, probably not compatible with Oil / neotree
-- lsp.kotlin_language_server.setup({
-- capabilities = capabilities,
-- })
lsp.emmylua_ls.setup({
capabilities = capabilities,
root_markers = {
".luarc.json",
"luarc.json",
".git",
"lazy-lock.json",
".emmyrc.json",
},
settings = {
workspace = {
library = vim.api.nvim_get_runtime_file("lua/*.lua", true),
},
},
})
lsp.rust_analyzer.setup({
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
assist = {
importGranularity = "module",
importPrefix = "by_self",
},
cargo = {
loadOutDirsFromCheck = true
},
procMacro = {
enable = true
},
}
},
})
end,
},
{
"mfussenegger/nvim-lint",
event = { "LazyFile" },
dependencies = {
"mason-org/mason.nvim",
},
opts = function()
return {
ignored = { },
}
end,
config = function(_, opts)
require("lint").linters_by_ft = {
bash = {
"shellcheck",
},
cmake = {
"cmakelint",
},
}
vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" }, {
callback = function(E)
if E.event == "TextChanged" then
return
end
require("lint").try_lint()
-- FIXME: If filename in opts.ignored:
-- vim.diagnostic.disable()
end,
})
end,
},
{
"hrsh7th/nvim-cmp",
event = { "LazyFile" },
dependencies = {
"neovim/nvim-lspconfig",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
},
config = function(_, opts)
-- From vimrc, may need clean up
local cmp = require("cmp")
-- Setup lspconfig
local has_cmp, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
local capabilities = vim.tbl_deep_extend(
"force",
{},
vim.lsp.protocol.make_client_capabilities(),
has_cmp and cmp_nvim_lsp.default_capabilities() or {},
opts.capabilities or {}
)
local lsp = require("lspconfig")
-- FIXME: Re enable once ruff is able to type check
-- lsp.ruff_lsp.setup({
-- capabilities = capabilities,
-- })
lsp.pyright.setup({
capabilities = capabilities,
})
-- FIXME: Causing memleak, probably not compatible with Oil / neotree
-- lsp.kotlin_language_server.setup({
-- capabilities = capabilities,
-- })
lsp.emmylua_ls.setup({
capabilities = capabilities,
root_markers = {
".luarc.json",
"luarc.json",
".git",
"lazy-lock.json",
".emmyrc.json",
},
settings = {
workspace = {
library = vim.api.nvim_get_runtime_file("lua/*.lua", true),
},
},
})
lsp.rust_analyzer.setup({
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
assist = {
importGranularity = "module",
importPrefix = "by_self",
},
cargo = {
loadOutDirsFromCheck = true
},
procMacro = {
enable = true
},
}
},
})
end,
},
{
"mfussenegger/nvim-lint",
event = { "LazyFile" },
dependencies = {
"mason-org/mason.nvim",
},
opts = function()
return {
ignored = {},
}
end,
config = function(_, opts)
require("lint").linters_by_ft = {
bash = {
"shellcheck",
},
cmake = {
"cmakelint",
},
}
vim.api.nvim_create_autocmd({ "BufWritePost", "BufReadPost", "InsertLeave", "TextChanged" }, {
callback = function(E)
if E.event == "TextChanged" then
return
end
require("lint").try_lint()
-- FIXME: If filename in opts.ignored:
-- vim.diagnostic.disable()
end,
})
end,
},
{
"hrsh7th/nvim-cmp",
event = { "LazyFile" },
dependencies = {
"neovim/nvim-lspconfig",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
},
config = function(_, opts)
-- From vimrc, may need clean up
local cmp = require("cmp")
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
cmp.setup({
auto_brackets = { "python" },
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
-- require("snippy").expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
-- NOTE: fallback function (or the first parameter inside `cmp.mapping(function(fallback) {})`) sends a already mapped key.
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<A-Space>"] = cmp.mapping.complete(), -- Alt instead of Ctrl because Ctrl+Space is used by IME to switch between input method
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping(function(fallback)
if cmp.visible() and not cmp.confirm() then
cmp.abort()
else
fallback()
end
end, {"i", "s"}),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- elseif has_words_before() then
-- cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
end
end, { "i", "s" }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
-- { name = "vsnip" }, -- For vsnip users.
-- { name = "luasnip" }, -- For luasnip users.
-- { name = "ultisnips" }, -- For ultisnips users.
-- { name = "snippy" }, -- For snippy users.
}, {
{ name = "buffer" },
})
})
cmp.setup({
auto_brackets = { "python" },
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
-- require("snippy").expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
-- NOTE: fallback function (or the first parameter inside `cmp.mapping(function(fallback) {})`) sends a already mapped key.
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<A-Space>"] = cmp.mapping.complete(), -- Alt instead of Ctrl because Ctrl+Space is used by IME to switch between input method
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping(function(fallback)
if cmp.visible() and not cmp.confirm() then
cmp.abort()
else
fallback()
end
end, { "i", "s" }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
-- elseif has_words_before() then
-- cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
end
end, { "i", "s" }),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
-- { name = "vsnip" }, -- For vsnip users.
-- { name = "luasnip" }, -- For luasnip users.
-- { name = "ultisnips" }, -- For ultisnips users.
-- { name = "snippy" }, -- For snippy users.
}, {
{ name = "buffer" },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype("gitcommit", {
sources = cmp.config.sources({
{ name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = "buffer" },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype("gitcommit", {
sources = cmp.config.sources({
{ name = "cmp_git" }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = "buffer" },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won"t work anymore).
cmp.setup.cmdline("/", {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" }
}
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won"t work anymore).
cmp.setup.cmdline("/", {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" }
}
})
-- Use cmdline & path source for ":" (if you enabled `native_menu`, this won"t work anymore).
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" }
}, {
{ name = "cmdline" }
})
})
end,
},
-- Use cmdline & path source for ":" (if you enabled `native_menu`, this won"t work anymore).
cmp.setup.cmdline(":", {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = "path" }
}, {
{ name = "cmdline" }
})
})
end,
},
}

View file

@ -1,86 +1,86 @@
require("null.util").lazy_file()
return {
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
event = { "LazyFile", "VeryLazy" },
opts = {
ensure_installed = {
"c",
"elixir",
"fluent",
"go",
"gsp",
"hyprlang",
"json5",
"julia",
-- "latex",
"python",
"rust",
"sxhkdrc",
"latex",
-- HTML template langs
"javascript",
"typescript",
"html",
"htmljinja",
"jinja",
"jinja_inline",
},
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
event = { "LazyFile", "VeryLazy" },
opts = {
ensure_installed = {
"c",
"elixir",
"fluent",
"go",
"gsp",
"hyprlang",
"json5",
"julia",
-- "latex",
"python",
"rust",
"sxhkdrc",
"latex",
-- HTML template langs
"javascript",
"typescript",
"html",
"htmljinja",
"jinja",
"jinja_inline",
},
sync_install = false,
auto_install = true,
sync_install = false,
auto_install = true,
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
},
config = function (_, opts)
local config = require("nvim-treesitter.parsers").get_parser_configs()
config.gsp = {
install_info = {
url = "https://git.sr.ht/~mango/tree-sitter-gsp",
files = {"src/parser.c"},
},
filetype = "gsp",
}
config.fluent = {
install_info = {
url = "https://github.com/projectfluent/tree-sitter-fluent", -- local path or git repo
files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc
},
filetype = "fluent", -- if filetype does not match the parser name
}
config.htmljinja = {
install_info = {
url = "https://github.com/null2264/tree-sitter-htmldjango", -- local path or git repo
files = {"src/parser.c"}, -- note that some parsers also require src/scanner.c or src/scanner.cc
},
filetype = "htmljinja", -- if filetype does not match the parser name
}
vim.filetype.add({
extension = { rasi = "rasi" },
pattern = {
[".*/hypr/.*%.conf"] = "hyprlang",
},
})
vim.filetype.add({
extension = {
mdx = "mdx"
}
})
vim.treesitter.language.register("markdown", "mdx")
require("nvim-treesitter.configs").setup(opts)
end
},
{
url = "https://git.sr.ht/~mango/tree-sitter-gsp",
fp = "gsp",
},
{
url = "https://github.com/null2264/tree-sitter-htmldjango",
fp = "htmljinja",
},
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
},
config = function(_, opts)
local config = require("nvim-treesitter.parsers").get_parser_configs()
config.gsp = {
install_info = {
url = "https://git.sr.ht/~mango/tree-sitter-gsp",
files = { "src/parser.c" },
},
filetype = "gsp",
}
config.fluent = {
install_info = {
url = "https://github.com/projectfluent/tree-sitter-fluent", -- local path or git repo
files = { "src/parser.c" }, -- note that some parsers also require src/scanner.c or src/scanner.cc
},
filetype = "fluent", -- if filetype does not match the parser name
}
config.htmljinja = {
install_info = {
url = "https://github.com/null2264/tree-sitter-htmldjango", -- local path or git repo
files = { "src/parser.c" }, -- note that some parsers also require src/scanner.c or src/scanner.cc
},
filetype = "htmljinja", -- if filetype does not match the parser name
}
vim.filetype.add({
extension = { rasi = "rasi" },
pattern = {
[".*/hypr/.*%.conf"] = "hyprlang",
},
})
vim.filetype.add({
extension = {
mdx = "mdx"
}
})
vim.treesitter.language.register("markdown", "mdx")
require("nvim-treesitter.configs").setup(opts)
end
},
{
url = "https://git.sr.ht/~mango/tree-sitter-gsp",
fp = "gsp",
},
{
url = "https://github.com/null2264/tree-sitter-htmldjango",
fp = "htmljinja",
},
}

View file

@ -1,103 +1,104 @@
local M = {}
function M.getch_lazy_nvim() -- Get or Fetch lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
return require("lazy")
return require("lazy")
end
function M.map(modes, key, target, opts)
local mt = {}
local mt = {}
for mode in modes:gmatch"." do
table.insert(mt, mode)
end
for mode in modes:gmatch "." do
table.insert(mt, mode)
end
vim.keymap.set(mt, key, target, opts or {
noremap = true,
silent = true,
})
vim.keymap.set(mt, key, target, opts or {
noremap = true,
silent = true,
})
end
-- <<[LAZY] REF: https://github.com/LazyVim/LazyVim/blob/7a5dbea/lua/lazyvim/util/plugin.lua#L59-L124
-- Properly load file based plugins without blocking the UI
function M.lazy_file()
M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0
M.use_lazy_file = M.use_lazy_file and vim.fn.argc(-1) > 0
-- Add support for the LazyFile event
local Event = require("lazy.core.handler.event")
-- Add support for the LazyFile event
local Event = require("lazy.core.handler.event")
if M.use_lazy_file then
-- We'll handle delayed execution of events ourselves
Event.mappings.LazyFile = { id = "LazyFile", event = "User", pattern = "LazyFile" }
Event.mappings["User LazyFile"] = Event.mappings.LazyFile
else
-- Don't delay execution of LazyFile events, but let lazy know about the mapping
Event.mappings.LazyFile = { id = "LazyFile", event = { "BufReadPost", "BufNewFile", "BufWritePre" } }
Event.mappings["User LazyFile"] = Event.mappings.LazyFile
return
end
if M.use_lazy_file then
-- We'll handle delayed execution of events ourselves
Event.mappings.LazyFile = { id = "LazyFile", event = "User", pattern = "LazyFile" }
Event.mappings["User LazyFile"] = Event.mappings.LazyFile
else
-- Don't delay execution of LazyFile events, but let lazy know about the mapping
Event.mappings.LazyFile = { id = "LazyFile", event = { "BufReadPost", "BufNewFile", "BufWritePre" } }
Event.mappings["User LazyFile"] = Event.mappings.LazyFile
return
end
local events = {} ---@type {event: string, buf: number, data?: any}[]
local events = {} ---@type {event: string, buf: number, data?: any}[]
local done = false
local function load()
if #events == 0 or done then
return
end
done = true
vim.api.nvim_del_augroup_by_name("lazy_file")
local done = false
local function load()
if #events == 0 or done then
return
end
done = true
vim.api.nvim_del_augroup_by_name("lazy_file")
---@type table<string,string[]>
local skips = {}
for _, event in ipairs(events) do
skips[event.event] = skips[event.event] or Event.get_augroups(event.event)
end
---@type table<string,string[]>
local skips = {}
for _, event in ipairs(events) do
skips[event.event] = skips[event.event] or Event.get_augroups(event.event)
end
vim.api.nvim_exec_autocmds("User", { pattern = "LazyFile", modeline = false })
for _, event in ipairs(events) do
if vim.api.nvim_buf_is_valid(event.buf) then
Event.trigger({
event = event.event,
exclude = skips[event.event],
data = event.data,
buf = event.buf,
})
if vim.bo[event.buf].filetype then
Event.trigger({
event = "FileType",
buf = event.buf,
})
end
end
end
vim.api.nvim_exec_autocmds("CursorMoved", { modeline = false })
events = {}
end
vim.api.nvim_exec_autocmds("User", { pattern = "LazyFile", modeline = false })
for _, event in ipairs(events) do
if vim.api.nvim_buf_is_valid(event.buf) then
Event.trigger({
event = event.event,
exclude = skips[event.event],
data = event.data,
buf = event.buf,
})
if vim.bo[event.buf].filetype then
Event.trigger({
event = "FileType",
buf = event.buf,
})
end
end
end
vim.api.nvim_exec_autocmds("CursorMoved", { modeline = false })
events = {}
end
-- schedule wrap so that nested autocmds are executed
-- and the UI can continue rendering without blocking
load = vim.schedule_wrap(load)
-- schedule wrap so that nested autocmds are executed
-- and the UI can continue rendering without blocking
load = vim.schedule_wrap(load)
vim.api.nvim_create_autocmd(M.lazy_file_events, {
group = vim.api.nvim_create_augroup("lazy_file", { clear = true }),
callback = function(event)
table.insert(events, event)
load()
end,
})
vim.api.nvim_create_autocmd(M.lazy_file_events, {
group = vim.api.nvim_create_augroup("lazy_file", { clear = true }),
callback = function(event)
table.insert(events, event)
load()
end,
})
end
-- >>[LAZY]
return M

View file

@ -2,6 +2,10 @@
end_of_line = lf
insert_final_newline = true
[*.lua]
indent_style = space
indent_size = 4
[*.{nix,kbd}]
indent_style = space
indent_size = 2