|
102 | 102 |
|
103 | 103 | local root_augroup = vim.api.nvim_create_augroup('MyAutoRoot', {}) |
104 | 104 | vim.api.nvim_create_autocmd('BufEnter', { group = root_augroup, callback = set_root }) |
| 105 | + |
| 106 | + |
| 107 | +-- Create an autocommand group to avoid duplicate autocommands |
| 108 | +vim.api.nvim_create_augroup("AutoSaveAndNotify", { clear = true }) |
| 109 | + |
| 110 | +-- Save on leaving Insert mode if the buffer is modified, then notify |
| 111 | +vim.api.nvim_create_autocmd("InsertLeave", { |
| 112 | + group = "AutoSaveAndNotify", |
| 113 | + pattern = "*", |
| 114 | + callback = function() |
| 115 | + if vim.bo.modified then |
| 116 | + vim.cmd("write") |
| 117 | + vim.notify("File saved (InsertLeave)", vim.log.levels.INFO) |
| 118 | + end |
| 119 | + end, |
| 120 | +}) |
| 121 | + |
| 122 | +-- Also save on losing focus if the buffer is modified, then notify |
| 123 | +vim.api.nvim_create_autocmd("FocusLost", { |
| 124 | + group = "AutoSaveAndNotify", |
| 125 | + pattern = "*", |
| 126 | + callback = function() |
| 127 | + if vim.bo.modified then |
| 128 | + vim.cmd("write") |
| 129 | + vim.notify("File saved (FocusLost)", vim.log.levels.INFO) |
| 130 | + end |
| 131 | + end, |
| 132 | +}) |
| 133 | + |
| 134 | + |
| 135 | +vim.api.nvim_create_autocmd({ "TextChanged"}, { |
| 136 | + group = "AutoSaveAndNotify", |
| 137 | + pattern = "*", |
| 138 | + callback = function() |
| 139 | + if vim.fn.mode() ~= "i" and vim.bo.modified then |
| 140 | + vim.cmd("write") |
| 141 | + vim.notify("Auto-saved", vim.log.levels.INFO) |
| 142 | + end |
| 143 | + end, |
| 144 | +}) |
| 145 | + |
| 146 | +vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled(), { bufnr }) |
0 commit comments