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

View file

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

View file

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

View file

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

View file

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