diff --git a/autoload/dpp/min.vim b/autoload/dpp/min.vim index 2063f86..861b0b6 100644 --- a/autoload/dpp/min.vim +++ b/autoload/dpp/min.vim @@ -1,3 +1,22 @@ +function dpp#min#load_state(path) abort + if !('#dpp'->exists()) + call dpp#min#_init() + endif + if g:dpp#_is_sudo | return 1 | endif + let g:dpp#_base_path = a:path->expand() + + const state = printf('%s/state_%s.vim', g:dpp#_base_path, g:dpp#_progname) + if !(state->filereadable()) | return 1 | endif + try + execute 'source' state->fnameescape() + catch + if v:exception !=# 'Cache loading error' + call dpp#util#_error('Loading state error: ' .. v:exception) + endif + call dpp#util#_clear_state() + return 1 + endtry +endfunction function dpp#min#_init() abort let g:dpp#_cache_version = 1 let g:dpp#_plugins = {} @@ -14,7 +33,7 @@ function dpp#min#_init() abort autocmd! augroup END endfunction -function! dpp#min#_load_cache_raw(vimrcs=[]) abort +function dpp#min#_load_cache_raw(vimrcs=[]) abort let g:dpp#_vimrcs = a:vimrcs const cache = printf('%s/cache_%s.vim', g:dpp#_base_path, g:dpp#_progname) const time = cache->getftime() @@ -26,22 +45,3 @@ function! dpp#min#_load_cache_raw(vimrcs=[]) abort return has('nvim') ? cache->readfile()->json_decode() \ : cache->readfile()[0]->js_decode() endfunction -function! dpp#min#load_state(path) abort - if !('#dpp'->exists()) - call dpp#min#_init() - endif - if g:dpp#_is_sudo | return 1 | endif - let g:dpp#_base_path = a:path->expand() - - const state = printf('%s/state_%s.vim', g:dpp#_base_path, g:dpp#_progname) - if !(state->filereadable()) | return 1 | endif - try - execute 'source' state->fnameescape() - catch - if v:exception !=# 'Cache loading error' - call dpp#util#_error('Loading state error: ' .. v:exception) - endif - call dpp#util#_clear_state() - return 1 - endtry -endfunction diff --git a/autoload/dpp/util.vim b/autoload/dpp/util.vim index d9718de..6806ae9 100644 --- a/autoload/dpp/util.vim +++ b/autoload/dpp/util.vim @@ -144,7 +144,7 @@ function s:tsort_impl(target, mark, sorted) abort call add(a:sorted, a:target) endfunction -function! dpp#util#_clear_state() abort +function dpp#util#_clear_state() abort const base = g:dpp#_base_path for cache in (base .. '/state_*.vim')->glob(v:true, v:true) \ + (base .. '/cache_*')->glob(v:true, v:true)