diff options
| author | nsfisis <nsfisis@gmail.com> | 2021-11-19 22:28:06 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2021-11-19 22:28:06 +0900 |
| commit | ed4b5f69144ee6f93e0c7059b3676c230cbce581 (patch) | |
| tree | d5a7ff65fe56c75d6589f00cc9de49dee5d48db5 /.config/vim/my/autoload/autosave.vim | |
| parent | 0d4a7fe77275a40996a710b673e58b4d2d78a8f4 (diff) | |
| download | dotfiles-ed4b5f69144ee6f93e0c7059b3676c230cbce581.tar.gz dotfiles-ed4b5f69144ee6f93e0c7059b3676c230cbce581.tar.zst dotfiles-ed4b5f69144ee6f93e0c7059b3676c230cbce581.zip | |
vim: make vim XDG-Base-Directory-aware
Diffstat (limited to '.config/vim/my/autoload/autosave.vim')
| -rw-r--r-- | .config/vim/my/autoload/autosave.vim | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/.config/vim/my/autoload/autosave.vim b/.config/vim/my/autoload/autosave.vim new file mode 100644 index 0000000..0c34d0e --- /dev/null +++ b/.config/vim/my/autoload/autosave.vim @@ -0,0 +1,70 @@ +scriptencoding utf-8 + + + +if !exists('g:autosave_interval_ms') + let g:autosave_interval_ms = 10 * 1000 +endif + +if !exists('g:autosave_silent') + let g:autosave_silent = v:true +endif + + + +function! autosave#handler(timer_id) abort + if !&modified + return + endif + if &readonly + return + endif + if &buftype !=# '' + return + endif + if expand('%') ==# '' + return + endif + + if !g:autosave_silent + echohl Comment + echo 'Auto-saving...' + echohl None + endif + + silent! write + + if !g:autosave_silent + echohl Comment + echo 'Saved.' + echohl None + endif +endfunction + + +function! autosave#enable() abort + if has('+timers') + echohl Error + echo "Feature '+timers' not available." + echohl None + return + endif + if exists('b:autosave_timer') + return + endif + + let b:autosave_timer = timer_start( + \ g:autosave_interval_ms, + \ 'autosave#handler', + \ { 'repeat': -1 }) +endfunction + + +function! autosave#disable() abort + if !exists('b:autosave_timer') + return + endif + + call timer_stop('b:autosave_timer') + unlet b:autosave_timer +endfunction |
