File tree Expand file tree Collapse file tree 3 files changed +32
-3
lines changed
Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,6 @@ This is a work in progress
66
77TODO:
88
9- - periodic saving
109- tab-scoped sessions
1110- documentation
1211- make filepaths relative so sessions are portable
Original file line number Diff line number Diff line change 11local M = {}
22
33local default_config = {
4+ autosave = {
5+ enabled = false ,
6+ -- How often to save (in seconds)
7+ interval = 60 ,
8+ -- Notify when autosaved
9+ notify = true ,
10+ },
411 buffers = {
512 -- Only save buffers with these buftypes
613 buftypes = { " " , " acwrite" , " help" },
@@ -64,11 +71,30 @@ local default_config = {
6471 extensions = {},
6572}
6673
74+ local autosave_timer
6775M .setup = function (config )
76+ local resession = require (" resession" )
6877 local newconf = vim .tbl_deep_extend (" force" , default_config , config )
6978 for k , v in pairs (newconf ) do
7079 M [k ] = v
7180 end
81+ if autosave_timer then
82+ autosave_timer :close ()
83+ autosave_timer = nil
84+ end
85+ if M .autosave .enabled then
86+ autosave_timer = vim .loop .new_timer ()
87+ timer = vim .loop .new_timer ()
88+ timer :start (
89+ M .autosave .interval * 1000 ,
90+ M .autosave .interval * 1000 ,
91+ vim .schedule_wrap (function ()
92+ if resession .get_current () then
93+ resession .save (nil , { notify = M .autosave .notify })
94+ end
95+ end )
96+ )
97+ end
7298end
7399
74100--- @return string
Original file line number Diff line number Diff line change 191191
192192local function close_everything ()
193193 for _ , bufnr in ipairs (vim .api .nvim_list_bufs ()) do
194- vim .api .nvim_buf_delete (bufnr , { force = true })
194+ if vim .bo [bufnr ].buflisted then
195+ vim .api .nvim_buf_delete (bufnr , { force = true })
196+ end
195197 end
196198 vim .cmd (" silent! tabonly" )
197199 vim .cmd (" silent! only" )
@@ -283,7 +285,9 @@ M.load = function(name, opts)
283285 for k , v in pairs (data .global .options ) do
284286 vim .o [k ] = v
285287 end
286- if not opts .detach then
288+ if opts .detach then
289+ current_session = nil
290+ else
287291 current_session = name
288292 end
289293end
You can’t perform that action at this time.
0 commit comments