From b35ebd872076f037d3a96db958942ec3e4578bd8 Mon Sep 17 00:00:00 2001 From: Shingo Kawamura Date: Sun, 6 Nov 2016 18:13:23 +0900 Subject: [PATCH] Add storage#cnewer() --- autoload/storage.vim | 23 +++++++++++++++++++++-- plugin/storage.vim | 5 +++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/autoload/storage.vim b/autoload/storage.vim index 0742706..5a9987b 100644 --- a/autoload/storage.vim +++ b/autoload/storage.vim @@ -39,7 +39,8 @@ function! storage#write(cmd, dict, path) abort finally silent execute 'edit' fnameescape(a:path) endtry - " expected to be still 'modified' if storage#put_cmd failed + " NOTE: + " Expected to be still 'modified' if storage#put_cmd failed setlocal nomodified let &hidden = current_hidden endfunction @@ -49,11 +50,29 @@ function! storage#open_quickfix(ls_result) abort let &errorformat = storage#errorformat() let ls_result_array = split(a:ls_result, "\n") call map(ls_result_array, 'storage#errorformatted_string(v:val)') - cgete join(ls_result_array, "\n") + cgetexpr join(ls_result_array, "\n") copen + try + " NOTE: + " This 'colder' is required to prevent from throwing 'E925 Current quickfix was changed' error. + " Because above 'cgetexpr' creates new quickfix, and current quickfix is changed. + " See http://github.com/vim/vim/blob/0a9046fbcb33770517ab0220b8100c4494bddab2/src/quickfix.c#L2275-L2276 + colder + let g:storage_vim_required_cnewer = 1 + catch + echo '' + endtry let &errorformat = current_errorformat endfunction +function! storage#cnewer() abort + if g:storage_vim_required_cnewer == 1 + cnewer + let g:storage_vim_required_cnewer = 0 + echo '' + endif +endfunction + function! storage#last_string(str) abort let last_index = strchars(a:str) - 1 return a:str[last_index] diff --git a/plugin/storage.vim b/plugin/storage.vim index dcea7de..85e8835 100644 --- a/plugin/storage.vim +++ b/plugin/storage.vim @@ -14,9 +14,14 @@ if !exists('g:storage_vim_dict') let g:storage_vim_dict = {} endif +if !exists('g:storage_vim_required_cnewer') + let g:storage_vim_required_cnewer = 0 +endif + augroup storage autocmd! autocmd BufReadCmd,FileReadCmd s3://* call storage#read(g:storage_vim_cmd, @%, g:storage_vim_dict) + autocmd TextChanged * call storage#cnewer() autocmd BufWriteCmd,FileWriteCmd s3://* call storage#write(g:storage_vim_cmd, g:storage_vim_dict, @%) augroup END