Skip to content

Commit 2d4e242

Browse files
committed
add auto-save.nvim for tex and typst
1 parent 98f88fe commit 2d4e242

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

lazy-lock.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"LuaSnip": { "branch": "master", "commit": "458560534a73f7f8d7a11a146c801db00b081df0" },
3+
"auto-save.nvim": { "branch": "main", "commit": "5fbcaac0a2698c87a9a1bd2083cb6949505cca12" },
34
"auto-session": { "branch": "main", "commit": "d27a29f5754e3a8b8d89a4069814e53ac583e951" },
45
"blink.cmp": { "branch": "main", "commit": "bae4bae0eedd1fa55f34b685862e94a222d5c6f8" },
56
"conform.nvim": { "branch": "master", "commit": "973f3cb73887d510321653044791d7937c7ec0fa" },

lua/custom/plugins/auto-save.lua

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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

Comments
 (0)