Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorry miss clicked because of brain fart #114

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 57 additions & 25 deletions plugin/minibufexpl.vim
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,14 @@ function! <SID>VimEnterHandler()

if g:miniBufExplAutoStart && t:miniBufExplAutoUpdate == 1
\ && (t:skipEligibleBuffersCheck == 1 || <SID>HasEligibleBuffers() == 1)
call <SID>StartExplorer(bufnr("%"))

" VimEnter event will be triggered after a session is loaded, if there is
" already a MBE window, we need to update it at this point.
if <SID>FindWindow('-MiniBufExplorer-', 1) == -1
call <SID>StartExplorer(bufnr("%"))
else
call <SID>UpdateExplorer(bufnr("%"))
endif

" Let the MBE open in the new tab
let s:TabsMBEState = 1
Expand Down Expand Up @@ -1542,10 +1549,13 @@ function! <SID>BuildBufferList(curBufNum)
call add(l:tabList, l:tab)
endfor

if t:miniBufExplSortBy == "name"
call sort(l:tabList, "<SID>NameCmp")
elseif t:miniBufExplSortBy == "mru"
if t:miniBufExplSortBy == "mru"
call sort(l:tabList, "<SID>MRUCmp")
elseif t:miniBufExplSortBy == "name"
call sort(l:tabList, "<SID>NameCmp")
else
" Sort by buffer number by default
call sort(l:tabList, "<SID>NumberCmp")
endif

let l:miniBufExplBufList = ''
Expand Down Expand Up @@ -1976,6 +1986,15 @@ function! <SID>UpdateBufferStateDict(bufNum,deleted)
call <SID>DEBUG('Leaving UpdateBufferStateDict()',10)
endfunction

" }}}
" MRUCmp - compares tabs based on MRU order {{{
"
function! <SID>MRUCmp(tab1, tab2)
let l:buf1 = <SID>GetBufferNumber(a:tab1)
let l:buf2 = <SID>GetBufferNumber(a:tab2)
return index(s:MRUList, l:buf1) - index(s:MRUList, l:buf2)
endfunction

" }}}
" NameCmp - compares tabs based on filename {{{
"
Expand All @@ -1992,12 +2011,12 @@ function! <SID>NameCmp(tab1, tab2)
endfunction

" }}}
" MRUCmp - compares tabs based on MRU order {{{
" NumberCmp - compares tabs based on buffer number {{{
"
function! <SID>MRUCmp(tab1, tab2)
let l:buf1 = str2nr(matchstr(a:tab1, '[0-9]\+'))
let l:buf2 = str2nr(matchstr(a:tab2, '[0-9]\+'))
return index(s:MRUList, l:buf1) - index(s:MRUList, l:buf2)
function! <SID>NumberCmp(tab1, tab2)
let l:buf1 = <SID>GetBufferNumber(a:tab1)
let l:buf2 = <SID>GetBufferNumber(a:tab2)
return l:buf1 - l:buf2
endfunction

" }}}
Expand Down Expand Up @@ -2124,12 +2143,34 @@ function! <SID>QuitIfLastOpen() abort
endif
endfunction

" }}}
" GetBufferNumber - Get the buffer number from a formated string {{{
"
function! <SID>GetBufferNumber(bufname)
call <SID>DEBUG('Entering GetBufferNumber()',10)
call <SID>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 <SID>DEBUG('The buffer number is '.l:retv,9)
call <SID>DEBUG('Leaving GetBufferNumber()',10)
return str2nr(l:retv)
endfunction

" }}}
" GetActiveBuffer {{{
"
function! <SID>GetActiveBuffer()
call <SID>DEBUG('Entering GetActiveBuffer()',10)
let l:bufNum = substitute(s:miniBufExplBufList,'\[\([0-9]*\):[^\]]*\][^\!]*!', '\1', '') + 0
let l:bufStr = substitute(s:miniBufExplBufList,'.*\(\[[0-9]*:*[^\]]*\][^\!]*!\).*', '\1', '')
call <SID>DEBUG('Currently active buffer is '.l:bufStr,10)
let l:bufNum = <SID>GetBufferNumber(l:bufStr)
call <SID>DEBUG('Currently active buffer is '.l:bufNum,10)
call <SID>DEBUG('Leaving GetActiveBuffer()',10)
return l:bufNum
Expand Down Expand Up @@ -2160,26 +2201,17 @@ function! <SID>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 <SID>DEBUG('Leaving GetSelectedBuffer()',10)
return l:retv
let l:retv = <SID>GetBufferNumber(@")
else
let @" = l:save_reg
call <SID>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 <SID>DEBUG('Leaving GetSelectedBuffer()',10)
return l:retv
endfunction

" }}}
Expand Down