Skip to content

Commit

Permalink
Allow one Extradite buffer per tab page
Browse files Browse the repository at this point in the history
Rather than only one Extradite for Vim instance.

For this convert g:extradite_bufnr to t:extradite_bufnr and change
all checks to check for the existence of t:extradite_bufnr first.
The later check was put into the ExtraditeIsActiveInTab() function.
  • Loading branch information
xaizek committed Nov 27, 2013
1 parent d6fe9a7 commit 84c7123
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions plugin/extradite.vim
Expand Up @@ -21,12 +21,11 @@ autocmd User Fugitive command! -buffer -bang Extradite :execute s:Extradite(<ban
nnoremap <silent> <Plug>ExtraditeClose :<C-U>call <SID>ExtraditeClose()<CR>
autocmd Syntax extradite call s:ExtraditeSyntax()
let g:extradite_bufnr = -1

function! s:Extradite(bang) abort

" if we are open, close.
if g:extradite_bufnr >= 0
if s:ExtraditeIsActiveInTab()
call <SID>ExtraditeClose()
return
endif
Expand Down Expand Up @@ -60,7 +59,7 @@ function! s:Extradite(bang) abort
autocmd BufLeave <buffer> hi! link CursorLine NONE
autocmd BufLeave <buffer> hi! link Cursor NONE
call s:ExtraditeDiffToggle()
let g:extradite_bufnr = bufnr('')
let t:extradite_bufnr = bufnr('')
silent doautocmd User Extradite
return ''
catch /^extradite:/
Expand Down Expand Up @@ -111,7 +110,7 @@ function! s:ExtraditeLoadCommitData(bang, base_file_name, template_cmd, ...) abo
throw v:errmsg
endif

if g:extradite_bufnr >= 0
if s:ExtraditeIsActiveInTab()
edit
else
if a:bang
Expand Down Expand Up @@ -147,8 +146,8 @@ endfunction
" Closes the file log and returns the selected `commit:path`
function! s:ExtraditeClose() abort

if (g:extradite_bufnr >= 0)
let filelog_winnr = bufwinnr(g:extradite_bufnr)
if s:ExtraditeIsActiveInTab()
let filelog_winnr = bufwinnr(t:extradite_bufnr)
exe 'keepjumps '.filelog_winnr.'wincmd w'
else
return
Expand All @@ -164,10 +163,15 @@ function! s:ExtraditeClose() abort
if logged_winnr >= 0
exe 'keepjumps '.logged_winnr.'wincmd w'
endif
let g:extradite_bufnr = -1
let t:extradite_bufnr = -1
return rev
endfunction

" Checks whether there is an Extradite buffer opened in the current tab page
function! s:ExtraditeIsActiveInTab() abort
return exists('t:extradite_bufnr') && t:extradite_bufnr >= 0
endfunction

function! s:ExtraditeJump(cmd) abort
let rev = s:ExtraditeClose()
if a:cmd == 'tabedit'
Expand Down

0 comments on commit 84c7123

Please sign in to comment.