diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index f096770..dfbbfd2 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2077,7 +2077,7 @@ function! s:SetupTemp(file) abort setlocal buftype=nowrite setlocal nomodeline if empty(mapcheck('q', 'n')) - nnoremap q :bdelete + nnoremap q :bdeleteechohl WarningMsgecho "Temp file q is deprecated in favor of the built-in C-W>q"echohl NONE endif exe 'nnoremap ' s:nowait "gq :bdelete" if getline(1) !~# '^diff ' @@ -4568,9 +4568,30 @@ function! s:linechars(pattern) abort return chars endfunction -function! s:BlameCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort - if exists('b:fugitive_blamed_bufnr') +function! s:BlameLeave() abort + let bufwinnr = bufwinnr(get(b:, 'fugitive_blamed_bufnr', -1)) + if bufwinnr > 0 + let bufnr = bufnr('') + exe bufwinnr . 'wincmd w' + return bufnr . 'bdelete' + endif + return '' +endfunction + +function! s:BlameQuit() abort + let cmd = s:BlameLeave() + if empty(cmd) return 'bdelete' + elseif len(s:DirCommitFile(@%)[1]) + return cmd . '|Gedit' + else + return cmd + endif +endfunction + +function! s:BlameCommand(line1, line2, range, count, bang, mods, reg, arg, args) abort + if exists('b:fugitive_blame_arguments') + return substitute(s:BlameLeave(), '^$', 'bdelete', '') endif exe s:DirCheck() try @@ -4656,18 +4677,17 @@ function! s:BlameCommand(line1, line2, range, count, bang, mods, reg, arg, args) setlocal norelativenumber endif execute "vertical resize ".(s:linechars('.\{-\}\ze\s\+\d\+)')+1) - let nowait = v:version >= 704 ? '' : '' nnoremap :help fugitive-:Gblame nnoremap g? :help fugitive-:Gblame - if empty(mapcheck('q', 'n')) - nnoremap q :exe substitute(bufwinnr(b:fugitive_blamed_bufnr).' wincmd w'.bufnr('').'bdelete','^-1','','') + if mapcheck('q', 'n') =~# '^$\|bdelete' + nnoremap q :exe BlameQuit()echohl WarningMsgecho ":Gblame q is deprecated in favor of gq"echohl NONE endif - exe 'nnoremap ' s:nowait "gq :exe substitute(bufwinnr(b:fugitive_blamed_bufnr).' wincmd w'.bufnr('').'bdeleteif expand(''%:p'') =~# ''^fugitive:[\\/][\\/]''Geditendif','^-1','','')" - nnoremap :exe BlameCommit("exe 'norm gq'edit") + exe 'nnoremap ' s:nowait "gq :exe BlameQuit()" + nnoremap :exe BlameCommit("exe BlameLeave()edit") nnoremap - :exe BlameJump('') nnoremap P :exe BlameJump('^'.v:count1) nnoremap ~ :exe BlameJump('~'.v:count1) - nnoremap i :exe BlameCommit("exe 'norm q'edit") + nnoremap i :exe BlameCommit("exe BlameLeave()edit") nnoremap o :exe BlameCommit((&splitbelow ? "botright" : "topleft")." split") nnoremap O :exe BlameCommit("tabedit") nnoremap p :exe Open((&splitbelow ? "botright" : "topleft").' pedit', 0, '', matchstr(getline('.'), '\x\+'), [matchstr(getline('.'), '\x\+')])