Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 40 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,50 @@ It is also possible to pass a pattern to a trigger event, if you only want to ex

The `condition` field of the configuration allows the user to exclude **auto-save** from saving specific buffers.

Here is an example that disables auto-save for specified file types:
Here is an example that disables auto-save for specified file types and specific
filenames:

```lua
{
condition = function(buf)
local filetype = vim.fn.getbufvar(buf, "&filetype")
-- some recommended exclusions. you can use `:lua print(vim.bo.filetype)` to
-- get the filetype string of the current buffer
local excluded_filetypes = {
-- this one is especially useful if you use neovim as a commit message editor
"gitcommit",
-- most of these are usually set to non-modifiable, which prevents autosaving
-- by default, but it doesn't hurt to be extra safe.
"NvimTree",
"Outline",
"TelescopePrompt",
"alpha",
"dashboard",
"lazygit",
"neo-tree",
"oil",
"prompt",
"toggleterm",
}

-- don't save for `sql` file types
if vim.list_contains({ "sql" }, filetype) then
return false
end
return true
local excluded_filenames = {
"do-not-autosave-me.lua"
}

local save_condition = function(buf)
local fn = vim.fn
local utils = require("auto-save.utils.data")

if
utils.not_in(fn.getbufvar(buf, "&filetype"), excluded_filetypes)
and utils.not_in(fn.expand("%:t"), excluded_filenames)
then
return true -- met condition(s), can save
end
return false -- can't save
end
Comment thread
abeforgit marked this conversation as resolved.
Outdated


-- in your config table
{
condition = save_condition
}
```

Expand Down