aboutsummaryrefslogtreecommitdiffstats
path: root/lua/config/autocmds.lua
diff options
context:
space:
mode:
authorElvis Claros Castro <elvis@claros.ar>2026-09-27 12:46:49 -0300
committerElvis Claros Castro <elvis@claros.ar>2026-09-27 12:46:49 -0300
commitdf7c711e2a49d51249350f52c63274b72aacb739 (patch)
tree426da3b65371f857f3ee3d9893d7ff3279aac02e /lua/config/autocmds.lua
parenta0bd84df02ce235123dfc939327e8bd33dffdd7e (diff)
downloadnvim-conf-df7c711e2a49d51249350f52c63274b72aacb739.tar.gz
nvim-conf-df7c711e2a49d51249350f52c63274b72aacb739.zip
Migración de plugins a funcionalidad nativa: statusline y treesitter propios, se quitan mason, lualine, mini, notify y otros
Diffstat (limited to 'lua/config/autocmds.lua')
-rw-r--r--lua/config/autocmds.lua137
1 files changed, 136 insertions, 1 deletions
diff --git a/lua/config/autocmds.lua b/lua/config/autocmds.lua
index ffb5d57..ccb9bd0 100644
--- a/lua/config/autocmds.lua
+++ b/lua/config/autocmds.lua
@@ -15,7 +15,6 @@ vim.api.nvim_create_autocmd("FileType", {
"lspinfo",
"spectre_panel",
"startuptime",
- "tsplayground",
"PlenaryTestPopup",
},
callback = function(event)
@@ -162,6 +161,128 @@ vim.api.nvim_create_autocmd("User", {
end,
})
+-- Progreso LSP como notificación de snacks.notifier (reemplaza noice lsp.progress)
+---@type table<number, {token:lsp.ProgressToken, msg:string, done:boolean}[]>
+local lsp_progress = vim.defaulttable()
+vim.api.nvim_create_autocmd("LspProgress", {
+ group = augroup "lsp_progress_notify",
+ ---@param ev {data: {client_id: integer, params: lsp.ProgressParams}}
+ callback = function(ev)
+ local client = vim.lsp.get_client_by_id(ev.data.client_id)
+ local value = ev.data.params.value --[[@as {percentage?: number, title?: string, message?: string, kind: "begin" | "report" | "end"}]]
+ if not client or type(value) ~= "table" then
+ return
+ end
+ local p = lsp_progress[client.id]
+
+ for i = 1, #p + 1 do
+ if i == #p + 1 or p[i].token == ev.data.params.token then
+ p[i] = {
+ token = ev.data.params.token,
+ msg = ("[%3d%%] %s%s"):format(
+ value.kind == "end" and 100 or value.percentage or 100,
+ value.title or "",
+ value.message and (" **%s**"):format(value.message) or ""
+ ),
+ done = value.kind == "end",
+ }
+ break
+ end
+ end
+
+ local msg = {} ---@type string[]
+ lsp_progress[client.id] = vim.tbl_filter(function(v)
+ return table.insert(msg, v.msg) or not v.done
+ end, p)
+
+ local spinner = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
+ vim.notify(table.concat(msg, "\n"), vim.log.levels.INFO, {
+ id = "lsp_progress",
+ title = client.name,
+ opts = function(notif)
+ notif.icon = #lsp_progress[client.id] == 0 and " "
+ or spinner[math.floor(vim.uv.hrtime() / (1e6 * 80)) % #spinner + 1]
+ end,
+ })
+ end,
+})
+
+-- Formatear/minificar JSON con jq (reemplaza json-nvim)
+vim.api.nvim_create_autocmd("FileType", {
+ group = augroup "json_jq",
+ pattern = "json",
+ callback = function(event)
+ vim.keymap.set("n", "<leader>jff", ":%!jq .<CR>", { buffer = event.buf, desc = "Formatear JSON con jq" })
+ vim.keymap.set("n", "<leader>jmf", ":%!jq -c .<CR>", { buffer = event.buf, desc = "Minificar JSON con jq" })
+ end,
+})
+
+-- Cerrar buffers inactivos tras 120 min (reemplaza nvim-early-retirement)
+local retirement_age_mins = 120
+local buf_last_used = {}
+vim.api.nvim_create_autocmd("BufEnter", {
+ group = augroup "early_retirement",
+ callback = function(event)
+ buf_last_used[event.buf] = os.time()
+ end,
+})
+local retirement_timer = assert(vim.uv.new_timer())
+retirement_timer:start(
+ 60000,
+ 60000,
+ vim.schedule_wrap(function()
+ local now = os.time()
+ for _, buf in ipairs(vim.api.nvim_list_bufs()) do
+ if
+ vim.api.nvim_buf_is_valid(buf)
+ and vim.bo[buf].buflisted
+ and not vim.bo[buf].modified
+ and #vim.fn.win_findbuf(buf) == 0
+ then
+ local last = buf_last_used[buf]
+ if last == nil then
+ buf_last_used[buf] = now
+ elseif now - last > retirement_age_mins * 60 then
+ pcall(vim.api.nvim_buf_delete, buf, {})
+ buf_last_used[buf] = nil
+ end
+ end
+ end
+ end)
+)
+
+-- Detección simple de indentación (reemplaza indent-o-matic); editorconfig nativo tiene prioridad
+vim.api.nvim_create_autocmd("BufReadPost", {
+ group = augroup "detect_indent",
+ callback = function(event)
+ local ec = vim.b[event.buf].editorconfig
+ if ec and (ec.indent_style or ec.indent_size) then
+ return
+ end
+ local tabs, spaces, min_spaces = 0, 0, math.huge
+ for _, line in ipairs(vim.api.nvim_buf_get_lines(event.buf, 0, 200, false)) do
+ local ws = line:match "^%s+"
+ if ws then
+ if ws:find "\t" then
+ tabs = tabs + 1
+ else
+ spaces = spaces + 1
+ if #ws > 1 and #ws < min_spaces then
+ min_spaces = #ws
+ end
+ end
+ end
+ end
+ if tabs > spaces then
+ vim.bo[event.buf].expandtab = false
+ elseif spaces > 0 and min_spaces ~= math.huge then
+ vim.bo[event.buf].expandtab = true
+ vim.bo[event.buf].shiftwidth = min_spaces
+ vim.bo[event.buf].softtabstop = min_spaces
+ end
+ end,
+})
+
-- vim.api.nvim_create_autocmd("User", {
@@ -177,3 +298,17 @@ vim.api.nvim_create_autocmd("User", {
-- end
-- end,
-- })
+
+-- WezTerm no implementa el borrado de imágenes del protocolo kitty (snacks.image
+-- usa el modo fallback sin placeholders), así que al salir de un buffer de imagen
+-- quedan restos en pantalla. Forzar un repintado completo los limpia.
+if vim.env.TERM_PROGRAM == "WezTerm" then
+ vim.api.nvim_create_autocmd("BufWinLeave", {
+ group = vim.api.nvim_create_augroup("wezterm_image_cleanup", { clear = true }),
+ callback = function(ev)
+ if vim.bo[ev.buf].filetype == "image" then
+ vim.schedule(function() vim.cmd "mode" end)
+ end
+ end,
+ })
+end