diff --git a/lua/autocmd.lua b/lua/autocmd.lua index 709bad3..c5e2d98 100644 --- a/lua/autocmd.lua +++ b/lua/autocmd.lua @@ -32,35 +32,33 @@ vim.api.nvim_create_autocmd('FocusLost', { -- command = 'silent! wa', -- Save all files when text is changed -- }) -vim.api.nvim_create_autocmd("User", { - pattern = "OilActionsPost", +vim.api.nvim_create_autocmd('User', { + pattern = 'OilActionsPost', callback = function(event) - if event.data.actions.type == "move" then + if event.data.actions.type == 'move' then Snacks.rename.on_rename_file(event.data.actions.src_url, event.data.actions.dest_url) end end, }) -local fidget_group = vim.api.nvim_create_augroup("CodeCompanionFidgetHooks", { clear = true }) +local fidget_group = vim.api.nvim_create_augroup('CodeCompanionFidgetHooks', { clear = true }) -vim.api.nvim_create_autocmd({ "User" }, { - pattern = "CodeCompanionRequestStarted", +vim.api.nvim_create_autocmd({ 'User' }, { + pattern = 'CodeCompanionRequestStarted', group = fidget_group, callback = function(event) - local FidgetHelper = require('utils.fidget_helper') + local FidgetHelper = require 'utils.fidget_helper' -- Pass event instead of request if the callback receives the full event object local handle = FidgetHelper:create_progress_handle(event) FidgetHelper:store_progress_handle(event.data.id, handle) end, }) -vim.api.nvim_create_autocmd({ "User" }, { - pattern = "CodeCompanionRequestFinished", +vim.api.nvim_create_autocmd({ 'User' }, { + pattern = 'CodeCompanionRequestFinished', group = fidget_group, callback = function(event) - local FidgetHelper = require('utils.fidget_helper') - -- Pass event instead of request if the callback receives the full event object - -- Pass event instead of request if the callback receives the full event object + local FidgetHelper = require 'utils.fidget_helper' local handle = FidgetHelper:pop_progress_handle(event.data.id) if handle then FidgetHelper:report_exit_status(handle, event) @@ -69,11 +67,19 @@ vim.api.nvim_create_autocmd({ "User" }, { end, }) --- augroup modes --- autocmd! --- autocmd FocusLost * call feedkeys("\") "Go to normal mode when moving away --- autocmd BufNewFile * call feedkeys("i") "Go to insert mode when starting a new file --- augroup END +vim.api.nvim_create_autocmd('BufEnter', { + callback = function(event) + local windows = vim.api.nvim_list_wins() + + for _, window in ipairs(windows) do + local bufnr = vim.api.nvim_win_get_buf(window) + if vim.api.nvim_get_option_value('buflisted', { buf = bufnr }) then + return + end + end + vim.cmd 'qa' + end, +}) local modes_group = vim.api.nvim_create_augroup('modes', { clear = true }) vim.api.nvim_create_autocmd('FocusLost', {