|
| 1 | +-- Example exlusions taken from https://github.com/okuuva/auto-save.nvim |
| 2 | + |
| 3 | +-- some recommended exclusions. you can use `:lua print(vim.bo.filetype)` to |
| 4 | +-- get the filetype string of the current buffer |
| 5 | +local excluded_filetypes = { |
| 6 | + -- this one is especially useful if you use neovim as a commit message editor |
| 7 | + 'gitcommit', |
| 8 | + -- most of these are usually set to non-modifiable, which prevents autosaving |
| 9 | + -- by default, but it doesn't hurt to be extra safe. |
| 10 | + 'NvimTree', |
| 11 | + 'Outline', |
| 12 | + 'TelescopePrompt', |
| 13 | + 'alpha', |
| 14 | + 'dashboard', |
| 15 | + 'lazygit', |
| 16 | + 'neo-tree', |
| 17 | + 'oil', |
| 18 | + 'prompt', |
| 19 | + 'toggleterm', |
| 20 | +} |
| 21 | + |
| 22 | +local excluded_filenames = { |
| 23 | + 'do-not-autosave-me.lua', |
| 24 | +} |
| 25 | + |
| 26 | +local included_filenames = { |
| 27 | + 'typst', |
| 28 | + 'tex', |
| 29 | +} |
| 30 | + |
| 31 | +local function save_condition(buf) |
| 32 | + if vim.tbl_contains(excluded_filetypes, vim.fn.getbufvar(buf, '&filetype')) or vim.tbl_contains(excluded_filenames, vim.fn.expand '%:t') then |
| 33 | + return false |
| 34 | + end |
| 35 | + if vim.tbl_contains(included_filenames, vim.fn.getbufvar(buf, '&filetype')) or vim.tbl_contains(included_filenames, vim.fn.expand '%:t') then |
| 36 | + return true |
| 37 | + end |
| 38 | + return false |
| 39 | +end |
| 40 | + |
| 41 | +return { |
| 42 | + { |
| 43 | + 'okuuva/auto-save.nvim', |
| 44 | + version = '^1.0.0', -- see https://devhints.io/semver, alternatively use '*' to use the latest tagged release |
| 45 | + cmd = 'ASToggle', -- optional for lazy loading on command |
| 46 | + event = { 'InsertLeave', 'TextChanged' }, -- optional for lazy loading on trigger events |
| 47 | + opts = { |
| 48 | + condition = save_condition, |
| 49 | + }, |
| 50 | + }, |
| 51 | +} |
0 commit comments