aboutsummaryrefslogtreecommitdiffhomepage
path: root/.config/nvim/my/autoload/autosave.vim
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2021-11-27 21:59:34 +0900
committernsfisis <nsfisis@gmail.com>2021-11-27 22:38:54 +0900
commit17975ffc46cc18ca49304b4780f20a5b0b91e4ca (patch)
tree00295b01bb6e92d32564fe205f5e1c7a3abca0b6 /.config/nvim/my/autoload/autosave.vim
parent318a31846d20cc80de090adee201de14965bf545 (diff)
downloaddotfiles-17975ffc46cc18ca49304b4780f20a5b0b91e4ca.tar.gz
dotfiles-17975ffc46cc18ca49304b4780f20a5b0b91e4ca.tar.zst
dotfiles-17975ffc46cc18ca49304b4780f20a5b0b91e4ca.zip
vim: minimize .vimrc
Diffstat (limited to '.config/nvim/my/autoload/autosave.vim')
-rw-r--r--.config/nvim/my/autoload/autosave.vim70
1 files changed, 70 insertions, 0 deletions
diff --git a/.config/nvim/my/autoload/autosave.vim b/.config/nvim/my/autoload/autosave.vim
new file mode 100644
index 0000000..2773460
--- /dev/null
+++ b/.config/nvim/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') && !has('nvim')
+ 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