File tree Expand file tree Collapse file tree 3 files changed +31
-5
lines changed
Expand file tree Collapse file tree 3 files changed +31
-5
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ A replacement for `:mksession` with a better API
55This is a work in progress
66
77TODO:
8- - autosave on quit
98- periodic saving
109- tab-scoped sessions
1110- hooks for plugins
Original file line number Diff line number Diff line change 11local M = {}
22
33local default_config = {
4+ -- Set this to save a session automatically when quitting vim
5+ -- Can be a string or a function that returns a string
6+ autosave_name = false ,
47 buffers = {
58 buftypes = { " " , " acwrite" , " help" },
69 options = { " buflisted" },
@@ -9,10 +12,25 @@ local default_config = {
912}
1013
1114M .setup = function (config )
15+ local resession = require (" resession" )
1216 local newconf = vim .tbl_deep_extend (" force" , default_config , config )
1317 for k , v in pairs (newconf ) do
1418 M [k ] = v
1519 end
20+
21+ local autosave_group = vim .api .nvim_create_augroup (" ResessionAutosave" , { clear = true })
22+ if newconf .autosave_name then
23+ vim .api .nvim_create_autocmd (" VimLeave" , {
24+ group = autosave_group ,
25+ callback = function ()
26+ local name = newconf .autosave_name
27+ if type (name ) == " function" then
28+ name = name ()
29+ end
30+ resession .save (name )
31+ end ,
32+ })
33+ end
1634end
1735
1836return M
Original file line number Diff line number Diff line change 11local M = {}
22
33local pending_config
4+
5+ local function do_setup ()
6+ if pending_config then
7+ require (" resession.config" ).setup (pending_config )
8+ pending_config = nil
9+ end
10+ end
11+
412M .setup = function (config )
513 pending_config = config or {}
14+ -- We have to complete the setup if we're autosaving
15+ if pending_config .autosave_name then
16+ do_setup ()
17+ end
618end
719
820--- @param name string
164176for k , v in pairs (M ) do
165177 if type (v ) == " function" and k ~= " setup" then
166178 M [k ] = function (...)
167- if pending_config then
168- require (" resession.config" ).setup (pending_config )
169- pending_config = nil
170- end
179+ do_setup ()
171180 return v (... )
172181 end
173182 end
You can’t perform that action at this time.
0 commit comments