From 60aaf2624c342eacf649ed471a467f739af9b504 Mon Sep 17 00:00:00 2001 From: Dani Hodovic Date: Tue, 7 Jun 2016 14:58:52 +0200 Subject: [PATCH] [Buffers] Use reltimefloat(reltime()) instead of localtime() (#152) * Nanoseconds instead of seconds for buffer timestmaps Fzf :Buffers uses a dictionary where it stores the last time accessed of the current buffers. This is used to sort the buffers. The timestamp is retrieved from a call to localtime() which returns the current second the buffer is accessed. However, fzf functions in such a way that before it enters the newly selected buffer, it enters the current buffer. Sometimes this causes the last two buffers to have the same timestamp. Repeatedly switching between two buffers yields inconsistent results. This commit fixes the issue by using seconds and microseconds from the bash call `date`. The buffers are now guaranteed to be sorted by last accessed. * Use reltime() instead of linux date This solution is better for compatability reasons. * Remove trailing whitespace --- autoload/fzf/vim.vim | 3 ++- plugin/fzf.vim | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim index aa27194..823f0cf 100644 --- a/autoload/fzf/vim.vim +++ b/autoload/fzf/vim.vim @@ -479,7 +479,8 @@ endfunction function! s:sort_buffers(...) let [b1, b2] = map(copy(a:000), 'get(g:fzf#vim#buffers, v:val, v:val)') - return b1 - b2 + " Using minus between a float and a number in a sort function causes an error + return b1 > b2 ? 1 : -1 endfunction function! fzf#vim#buffers(...) diff --git a/plugin/fzf.vim b/plugin/fzf.vim index 7e30bfe..f486f49 100644 --- a/plugin/fzf.vim +++ b/plugin/fzf.vim @@ -112,7 +112,7 @@ endif let g:fzf#vim#buffers = {} augroup fzf_buffers autocmd! - autocmd BufWinEnter,WinEnter * let g:fzf#vim#buffers[bufnr('')] = localtime() + autocmd BufWinEnter,WinEnter * let g:fzf#vim#buffers[bufnr('')] = reltimefloat(reltime()) autocmd BufDelete * silent! call remove(g:fzf#vim#buffers, expand('')) augroup END