diff --git a/plugin/minibufexpl.vim b/plugin/minibufexpl.vim index ae25b2d..c4786a6 100644 --- a/plugin/minibufexpl.vim +++ b/plugin/minibufexpl.vim @@ -1983,8 +1983,8 @@ endfunction " MRUCmp - compares tabs based on MRU order {{{ " function! MRUCmp(tab1, tab2) - let l:buf1 = str2nr(matchstr(a:tab1, '[0-9]\+')) - let l:buf2 = str2nr(matchstr(a:tab2, '[0-9]\+')) + let l:buf1 = GetBufferNumber(a:tab1) + let l:buf2 = GetBufferNumber(a:tab2) return index(s:MRUList, l:buf1) - index(s:MRUList, l:buf2) endfunction @@ -2007,8 +2007,8 @@ endfunction " NumberCmp - compares tabs based on buffer number {{{ " function! NumberCmp(tab1, tab2) - let l:buf1 = str2nr(matchstr(a:tab1, '[0-9]\+')) - let l:buf2 = str2nr(matchstr(a:tab2, '[0-9]\+')) + let l:buf1 = GetBufferNumber(a:tab1) + let l:buf2 = GetBufferNumber(a:tab2) return l:buf1 - l:buf2 endfunction @@ -2136,12 +2136,34 @@ function! QuitIfLastOpen() abort endif endfunction +" }}} +" GetBufferNumber - Get the buffer number from a formated string {{{ +" +function! GetBufferNumber(bufname) + call DEBUG('Entering GetBufferNumber()',10) + call DEBUG('The buffer name is '.a:bufname,9) + if !g:miniBufExplShowBufNumbers + " This is a bit ugly, but it works, unless we come up with a + " better way to get the key for a dictionary by its value. + let l:bufUniqNameDictKeys = keys(s:bufUniqNameDict) + let l:bufUniqNameDictValues = values(s:bufUniqNameDict) + let l:retv = l:bufUniqNameDictKeys[match(l:bufUniqNameDictValues,substitute(a:bufname,'\[*\([^\]]*\)\]*.*', '\1', ''))] + else + let l:retv = substitute(a:bufname,'\[*\([0-9]*\):[^\]]*\]*.*', '\1', '') + 0 + endif + call DEBUG('The buffer number is '.l:retv,9) + call DEBUG('Leaving GetBufferNumber()',10) + return str2nr(l:retv) +endfunction + " }}} " GetActiveBuffer {{{ " function! GetActiveBuffer() call DEBUG('Entering GetActiveBuffer()',10) - let l:bufNum = substitute(s:miniBufExplBufList,'\[\([0-9]*\):[^\]]*\][^\!]*!', '\1', '') + 0 + let l:bufStr = substitute(s:miniBufExplBufList,'.*\(\[[0-9]*:*[^\]]*\][^\!]*!\).*', '\1', '') + call DEBUG('Currently active buffer is '.l:bufStr,10) + let l:bufNum = GetBufferNumber(l:bufStr) call DEBUG('Currently active buffer is '.l:bufNum,10) call DEBUG('Leaving GetActiveBuffer()',10) return l:bufNum @@ -2172,26 +2194,17 @@ function! GetSelectedBuffer() let @" = "" normal ""yi[ if @" != "" - if !g:miniBufExplShowBufNumbers - " This is a bit ugly, but it works, unless we come up with a - " better way to get the key for a dictionary by its value. - let l:bufUniqNameDictKeys = keys(s:bufUniqNameDict) - let l:bufUniqNameDictValues = values(s:bufUniqNameDict) - let l:retv = l:bufUniqNameDictKeys[match(l:bufUniqNameDictValues,substitute(@",'[0-9]*:\(.*\)', '\1', ''))] - else - let l:retv = substitute(@",'\([0-9]*\):.*', '\1', '') + 0 - endif - let @" = l:save_reg - call DEBUG('Leaving GetSelectedBuffer()',10) - return l:retv + let l:retv = GetBufferNumber(@") else - let @" = l:save_reg - call DEBUG('Leaving GetSelectedBuffer()',10) - return -1 + let l:retv = -1 endif + let @" = l:save_reg let &report = l:save_rep let &showcmd = l:save_sc + + call DEBUG('Leaving GetSelectedBuffer()',10) + return l:retv endfunction " }}}