Close vim if only non-file windows are open

This commit is contained in:
2025-04-23 22:38:44 +01:00
parent bf83c416c5
commit c7d39fe79c

View File

@@ -32,35 +32,33 @@ vim.api.nvim_create_autocmd('FocusLost', {
-- command = 'silent! wa', -- Save all files when text is changed -- command = 'silent! wa', -- Save all files when text is changed
-- }) -- })
vim.api.nvim_create_autocmd("User", { vim.api.nvim_create_autocmd('User', {
pattern = "OilActionsPost", pattern = 'OilActionsPost',
callback = function(event) 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) Snacks.rename.on_rename_file(event.data.actions.src_url, event.data.actions.dest_url)
end end
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" }, { vim.api.nvim_create_autocmd({ 'User' }, {
pattern = "CodeCompanionRequestStarted", pattern = 'CodeCompanionRequestStarted',
group = fidget_group, group = fidget_group,
callback = function(event) 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 -- Pass event instead of request if the callback receives the full event object
local handle = FidgetHelper:create_progress_handle(event) local handle = FidgetHelper:create_progress_handle(event)
FidgetHelper:store_progress_handle(event.data.id, handle) FidgetHelper:store_progress_handle(event.data.id, handle)
end, end,
}) })
vim.api.nvim_create_autocmd({ "User" }, { vim.api.nvim_create_autocmd({ 'User' }, {
pattern = "CodeCompanionRequestFinished", pattern = 'CodeCompanionRequestFinished',
group = fidget_group, group = fidget_group,
callback = function(event) 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
-- Pass event instead of request if the callback receives the full event object
local handle = FidgetHelper:pop_progress_handle(event.data.id) local handle = FidgetHelper:pop_progress_handle(event.data.id)
if handle then if handle then
FidgetHelper:report_exit_status(handle, event) FidgetHelper:report_exit_status(handle, event)
@@ -69,11 +67,19 @@ vim.api.nvim_create_autocmd({ "User" }, {
end, end,
}) })
-- augroup modes vim.api.nvim_create_autocmd('BufEnter', {
-- autocmd! callback = function(event)
-- autocmd FocusLost * call feedkeys("\<Esc>") "Go to normal mode when moving away local windows = vim.api.nvim_list_wins()
-- autocmd BufNewFile * call feedkeys("i") "Go to insert mode when starting a new file
-- augroup END 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 }) local modes_group = vim.api.nvim_create_augroup('modes', { clear = true })
vim.api.nvim_create_autocmd('FocusLost', { vim.api.nvim_create_autocmd('FocusLost', {