From 0fa73f93475d1f22917ecde7f6c393fe86774869 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Fri, 1 Aug 2014 15:27:52 +1000 Subject: [PATCH] Add SwitchBuffer(bufNum) and map to MBEbs This is mostly to support such mappings as nmap 1 :MBEbs1 but do nothing for/in ignored buffers/windows. Signed-off-by: Olivier Mehani --- plugin/minibufexpl.vim | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/plugin/minibufexpl.vim b/plugin/minibufexpl.vim index e2b3348..f4ac604 100644 --- a/plugin/minibufexpl.vim +++ b/plugin/minibufexpl.vim @@ -96,6 +96,9 @@ endif if !exists(':MBEbw') command! -bang -nargs=* MBEbw call DeleteBuffer(1,''=='!',) endif +if !exists(':MBEbs') + command! -bang -nargs=* MBEbs call SwitchBuffer() +endif if !exists(':MBEbun') command! -bang -nargs=* MBEbun call DeleteBuffer(2,''=='!',) endif @@ -1341,6 +1344,48 @@ function! CycleBuffer(forward,...) let s:MRUEnable = 1 endfunction +" }}} +" SwitchBuffer {{{ +" +" Select a buffer by its number if it is not ignored +" +" Useful for mapping such as follows +" nmap 1 :MBEbs1 +" nmap 2 :MBEbs2 +" nmap 3 :MBEbs3 +" nmap 4 :MBEbs4 +" nmap 5 :MBEbs5 +" nmap 6 :MBEbs6 +" nmap 7 :MBEbs7 +" nmap 8 :MBEbs8 +" nmap 9 :MBEbs9 +" nmap 0 :MBEbs0 +" +" a:bufNum +" number of the buffer to select +" +function! SwitchBuffer(bufNum,...) + call DEBUG('Entering SwitchBuffer('.a:bufNum.')',10) + if IsBufferIgnored(bufnr('%')) == 1 + echo 'Current buffer is ignored, not switching.' + return + endif + + let l:bufNum = a:bufNum + 0 + + if IsBufferIgnored(l:bufNum) == 1 + echo 'Buffer '.l:bufNum.' is not selectable!' + return + endif + + call DEBUG('Selecting buffer '.a:bufNum,5) + let l:moveCmd = 'b! '.l:bufNum + + " Change buffer (keeping track of before and after buffers) + exec l:moveCmd + + call DEBUG('Leaving SwitchBuffer()',10) +endfunction " }}} " DeleteBuffer {{{ "