diff --git a/lua/autocmd.lua b/lua/autocmd.lua index 9ca9bba..9c13888 100644 --- a/lua/autocmd.lua +++ b/lua/autocmd.lua @@ -2,9 +2,27 @@ local function augroup(name) return vim.api.nvim_create_augroup("nvim_" .. name, { clear = true }) end --- ----------------------------------------------------------------------------- --- General UI & Behavior --- ----------------------------------------------------------------------------- +-- smart column only when needed +local smart_column_group = vim.api.nvim_create_augroup('SmartColumn', { clear = true }) +vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI', 'BufEnter' }, { + group = smart_column_group, + callback = function() + local limit = 120 + local disabled_fts = { 'help', 'text', 'markdown', 'oil', 'snacks_dashboard', 'dashboard' } + + if vim.tbl_contains(disabled_fts, vim.bo.filetype) then + vim.wo.colorcolumn = '' + return + end + + local curr_line = vim.api.nvim_get_current_line() + if vim.fn.strdisplaywidth(curr_line) > limit then + vim.wo.colorcolumn = tostring(limit) + else + vim.wo.colorcolumn = '' + end + end, +}) -- Secure .env Masking (Conceal method) local function toggle_env_mask() @@ -98,10 +116,6 @@ vim.api.nvim_create_autocmd("BufWritePre", { end, }) --- ----------------------------------------------------------------------------- --- LSP Related --- ----------------------------------------------------------------------------- - -- Document Highlight on CursorHold vim.api.nvim_create_autocmd("LspAttach", { group = augroup("lsp_attach_autocmds"), @@ -120,10 +134,6 @@ vim.api.nvim_create_autocmd("LspAttach", { end, }) --- ----------------------------------------------------------------------------- --- Filetype Specific --- ----------------------------------------------------------------------------- - -- Wrap and spellcheck in text filetypes vim.api.nvim_create_autocmd("FileType", { group = augroup("wrap_spell"), @@ -150,10 +160,8 @@ vim.api.nvim_create_user_command("TSInstallAll", function() require("nvim-treesitter.install").install(parsers) end, { desc = "Install all configured Tree-sitter parsers" }) --- ----------------------------------------------------------------------------- --- Macro Notifications --- ----------------------------------------------------------------------------- +-- Macro Notifications vim.api.nvim_create_autocmd("RecordingEnter", { callback = function() vim.notify("Recording macro...", vim.log.levels.INFO, { title = "Macro", timeout = 1000 }) @@ -167,10 +175,8 @@ vim.api.nvim_create_autocmd("RecordingLeave", { end, }) --- ----------------------------------------------------------------------------- --- Auto-Save (3s Debounce) --- ----------------------------------------------------------------------------- +-- Auto-Save (3s Debounce) local save_timer = nil vim.api.nvim_create_autocmd({ "TextChanged", "InsertLeave", "BufLeave", "FocusLost" }, { group = augroup("autosave"), diff --git a/lua/pack_helper.lua b/lua/pack_helper.lua index 60b8435..16acbe8 100644 --- a/lua/pack_helper.lua +++ b/lua/pack_helper.lua @@ -1,5 +1,5 @@ --- @class PackHelper -local M = { registered = {} } +local M = {} -- Shorthands: gh (default), gl: (GitLab), cb: (Codeberg) local SOURCES = setmetatable({ @@ -26,21 +26,8 @@ _G.add = function(specs) return s end)() or s) table.insert(res, n) - M.registered[type(n) == "table" and n.src or n] = true end if #res > 0 then pcall(vim.pack.add, res) end end -M.clean = function() - local del = {} - for url in pairs(vim.pack.get()) do - if not M.registered[url] then table.insert(del, url) end - end - if #del == 0 then return vim.notify("Plugins up to date", 2) end - if vim.fn.input("Delete " .. #del .. " plugins? (y/n): "):lower() == "y" then - for _, u in ipairs(del) do vim.pack.del(u) end - vim.notify("Cleaned " .. #del, 2) - end -end - return M