shada.vim 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. if exists('g:loaded_shada_plugin')
  2. finish
  3. endif
  4. let g:loaded_shada_plugin = 1
  5. augroup ShaDaCommands
  6. autocmd!
  7. autocmd BufReadCmd *.shada,*.shada.tmp.[a-z]
  8. \ :if !empty(v:cmdarg)|throw '++opt not supported'|endif
  9. \ |call setline('.', shada#get_strings(readfile(expand('<afile>'),'b')))
  10. \ |setlocal filetype=shada
  11. autocmd FileReadCmd *.shada,*.shada.tmp.[a-z]
  12. \ :if !empty(v:cmdarg)|throw '++opt not supported'|endif
  13. \ |call append("'[", shada#get_strings(readfile(expand('<afile>'), 'b')))
  14. autocmd BufWriteCmd *.shada,*.shada.tmp.[a-z]
  15. \ :if !empty(v:cmdarg)|throw '++opt not supported'|endif
  16. \ |if writefile(shada#get_binstrings(getline(1, '$')),
  17. \expand('<afile>'), 'b') == 0
  18. \ | let &l:modified = (expand('<afile>') is# bufname(+expand('<abuf>'))
  19. \? 0
  20. \: stridx(&cpoptions, '+') != -1)
  21. \ |endif
  22. autocmd FileWriteCmd *.shada,*.shada.tmp.[a-z]
  23. \ :if !empty(v:cmdarg)|throw '++opt not supported'|endif
  24. \ |call writefile(
  25. \shada#get_binstrings(getline(min([line("'["), line("']")]),
  26. \max([line("'["), line("']")]))),
  27. \expand('<afile>'),
  28. \'b')
  29. autocmd FileAppendCmd *.shada,*.shada.tmp.[a-z]
  30. \ :if !empty(v:cmdarg)|throw '++opt not supported'|endif
  31. \ |call writefile(
  32. \shada#get_binstrings(getline(min([line("'["), line("']")]),
  33. \max([line("'["), line("']")]))),
  34. \expand('<afile>'),
  35. \'ab')
  36. autocmd SourceCmd *.shada,*.shada.tmp.[a-z]
  37. \ :execute 'rshada' fnameescape(expand('<afile>'))
  38. augroup END