mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-12-08 21:14:53 +08:00
Press escape to background :Git to preview window
This can one day hopefully be generalized to handle --paginate, but for now, leave it as undocumented experiment.
This commit is contained in:
@@ -2365,7 +2365,9 @@ endfunction
|
|||||||
function! s:TempReadPost(file) abort
|
function! s:TempReadPost(file) abort
|
||||||
if has_key(s:temp_files, s:cpath(a:file))
|
if has_key(s:temp_files, s:cpath(a:file))
|
||||||
let dict = s:temp_files[s:cpath(a:file)]
|
let dict = s:temp_files[s:cpath(a:file)]
|
||||||
|
if !has_key(dict, 'job')
|
||||||
setlocal nobuflisted
|
setlocal nobuflisted
|
||||||
|
endif
|
||||||
if get(dict, 'filetype', '') ==# 'git'
|
if get(dict, 'filetype', '') ==# 'git'
|
||||||
call fugitive#MapJumps()
|
call fugitive#MapJumps()
|
||||||
endif
|
endif
|
||||||
@@ -2414,7 +2416,7 @@ function! s:AskPassArgs(dir) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:RunJobs() abort
|
function! s:RunJobs() abort
|
||||||
return exists('*job_start') || exists('*jobstart')
|
return (exists('*job_start') || exists('*jobstart')) && exists('*bufwinid')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:RunSave(state) abort
|
function! s:RunSave(state) abort
|
||||||
@@ -2430,6 +2432,10 @@ function! s:RunFinished(state, ...) abort
|
|||||||
if get(a:state, 'filetype', '') ==# 'git' && first =~# '\<\([[:upper:][:digit:]_-]\+(\d\+)\).*\1'
|
if get(a:state, 'filetype', '') ==# 'git' && first =~# '\<\([[:upper:][:digit:]_-]\+(\d\+)\).*\1'
|
||||||
let a:state.filetype = 'man'
|
let a:state.filetype = 'man'
|
||||||
endif
|
endif
|
||||||
|
if !has_key(a:state, 'capture_bufnr')
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call fugitive#ReloadStatus(a:state, 1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:RunEdit(state, tmp, job) abort
|
function! s:RunEdit(state, tmp, job) abort
|
||||||
@@ -2479,6 +2485,38 @@ function! s:RunReceive(state, tmp, type, job, data, ...) abort
|
|||||||
endif
|
endif
|
||||||
let a:tmp.echo .= data
|
let a:tmp.echo .= data
|
||||||
endif
|
endif
|
||||||
|
let line_count = a:tmp.line_count
|
||||||
|
let a:tmp.line_count += len(lines) - 1
|
||||||
|
if !has_key(a:state, 'capture_bufnr') || !bufloaded(a:state.capture_bufnr)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call remove(lines, -1)
|
||||||
|
try
|
||||||
|
call setbufvar(a:state.capture_bufnr, '&modifiable', 1)
|
||||||
|
if !line_count && len(lines) > 1000
|
||||||
|
let first = remove(lines, 0, 999)
|
||||||
|
call setbufline(a:state.capture_bufnr, 1, first)
|
||||||
|
redraw
|
||||||
|
call setbufline(a:state.capture_bufnr, 1001, lines)
|
||||||
|
else
|
||||||
|
call setbufline(a:state.capture_bufnr, line_count + 1, lines)
|
||||||
|
endif
|
||||||
|
call setbufvar(a:state.capture_bufnr, '&modifiable', 0)
|
||||||
|
if !getwinvar(bufwinid(a:state.capture_bufnr), '&previewwindow')
|
||||||
|
" no-op
|
||||||
|
elseif exists('*win_execute')
|
||||||
|
call win_execute(bufwinid(a:state.capture_bufnr), '$')
|
||||||
|
else
|
||||||
|
let winnr = bufwinnr(a:state.capture_bufnr)
|
||||||
|
if winnr > 0
|
||||||
|
let old_winnr = winnr()
|
||||||
|
exe 'noautocmd' winnr.'wincmd w'
|
||||||
|
$
|
||||||
|
exe 'noautocmd' old_winnr.'wincmd w'
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
catch
|
||||||
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:RunExit(state, tmp, job, exit_status) abort
|
function! s:RunExit(state, tmp, job, exit_status) abort
|
||||||
@@ -2496,6 +2534,19 @@ function! s:RunClose(state, tmp, job, ...) abort
|
|||||||
let noeol = substitute(substitute(a:tmp.err, "\r$", '', ''), ".*\r", '', '') . a:tmp.out
|
let noeol = substitute(substitute(a:tmp.err, "\r$", '', ''), ".*\r", '', '') . a:tmp.out
|
||||||
call writefile([noeol], a:state.file, 'ba')
|
call writefile([noeol], a:state.file, 'ba')
|
||||||
call remove(a:state, 'job')
|
call remove(a:state, 'job')
|
||||||
|
if has_key(a:state, 'capture_bufnr') && bufloaded(a:state.capture_bufnr)
|
||||||
|
if len(noeol)
|
||||||
|
call setbufvar(a:state.capture_bufnr, '&modifiable', 1)
|
||||||
|
call setbufline(a:state.capture_bufnr, a:tmp.line_count + 1, [noeol])
|
||||||
|
call setbufvar(a:state.capture_bufnr, '&eol', 0)
|
||||||
|
call setbufvar(a:state.capture_bufnr, '&modifiable', 0)
|
||||||
|
endif
|
||||||
|
call setbufvar(a:state.capture_bufnr, '&modified', 0)
|
||||||
|
call setbufvar(a:state.capture_bufnr, '&buflisted', 0)
|
||||||
|
if a:state.filetype !=# getbufvar(a:state.capture_bufnr, '&filetype', '')
|
||||||
|
call setbufvar(a:state.capture_bufnr, '&filetype', a:state.filetype)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
if !has_key(a:state, 'exit_status')
|
if !has_key(a:state, 'exit_status')
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@@ -2552,13 +2603,31 @@ function! s:RunWait(state, tmp, job, ...) abort
|
|||||||
if peek != 0 && !(has('win32') && peek == 128)
|
if peek != 0 && !(has('win32') && peek == 128)
|
||||||
let c = getchar()
|
let c = getchar()
|
||||||
let c = type(c) == type(0) ? nr2char(c) : c
|
let c = type(c) == type(0) ? nr2char(c) : c
|
||||||
if c ==# "\<C-D>"
|
if c ==# "\<C-D>" || c ==# "\<Esc>"
|
||||||
let a:state.closed_in = 1
|
let a:state.closed_in = 1
|
||||||
if type(a:job) ==# type(0)
|
if type(a:job) ==# type(0)
|
||||||
call chanclose(a:job, 'stdin')
|
call chanclose(a:job, 'stdin')
|
||||||
else
|
else
|
||||||
call ch_close_in(a:job)
|
call ch_close_in(a:job)
|
||||||
endif
|
endif
|
||||||
|
let can_pedit = exists('*setbufline')
|
||||||
|
for winnr in range(1, winnr('$'))
|
||||||
|
if getwinvar(winnr, '&previewwindow') && getbufvar(winbufnr(winnr), '&modified')
|
||||||
|
let can_pedit = 0
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
if can_pedit
|
||||||
|
if has_key(a:tmp, 'echo')
|
||||||
|
call remove(a:tmp, 'echo')
|
||||||
|
endif
|
||||||
|
call writefile(['fugitive: aborting edit due to background operation.'], a:state.file . '.exit')
|
||||||
|
exe (&splitbelow ? 'botright' : 'topleft') 'silent pedit ++ff=unix' fnameescape(a:state.file)
|
||||||
|
let a:state.capture_bufnr = bufnr(a:state.file)
|
||||||
|
call setbufvar(a:state.capture_bufnr, '&modified', 1)
|
||||||
|
let finished = 0
|
||||||
|
redraw!
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
call s:RunSend(a:job, c)
|
call s:RunSend(a:job, c)
|
||||||
if !a:state.pty
|
if !a:state.pty
|
||||||
@@ -2601,13 +2670,26 @@ if !exists('s:resume_queue')
|
|||||||
endif
|
endif
|
||||||
function! fugitive#Resume() abort
|
function! fugitive#Resume() abort
|
||||||
while len(s:resume_queue)
|
while len(s:resume_queue)
|
||||||
|
if s:resume_queue[0][2] isnot# ''
|
||||||
try
|
try
|
||||||
call call('s:RunWait', remove(s:resume_queue, 0))
|
call call('s:RunWait', remove(s:resume_queue, 0))
|
||||||
endtry
|
endtry
|
||||||
|
endif
|
||||||
endwhile
|
endwhile
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:RunBufDelete(bufnr) abort
|
function! s:RunBufDelete(bufnr) abort
|
||||||
|
let state = s:TempState(bufname(+a:bufnr))
|
||||||
|
if has_key(state, 'job')
|
||||||
|
try
|
||||||
|
if type(state.job) == type(0)
|
||||||
|
call jobstop(state.job)
|
||||||
|
else
|
||||||
|
call job_stop(state.job)
|
||||||
|
endif
|
||||||
|
catch
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
if has_key(s:edit_jobs, a:bufnr) |
|
if has_key(s:edit_jobs, a:bufnr) |
|
||||||
call add(s:resume_queue, remove(s:edit_jobs, a:bufnr))
|
call add(s:resume_queue, remove(s:edit_jobs, a:bufnr))
|
||||||
call feedkeys(":redraw!|call delete(" . string(s:resume_queue[-1][0].file . '.edit') .
|
call feedkeys(":redraw!|call delete(" . string(s:resume_queue[-1][0].file . '.edit') .
|
||||||
@@ -2617,7 +2699,7 @@ endfunction
|
|||||||
|
|
||||||
augroup fugitive_job
|
augroup fugitive_job
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufDelete * call s:RunBufDelete(expand('<abuf>'))
|
autocmd BufDelete * call s:RunBufDelete(+expand('<abuf>'))
|
||||||
autocmd VimLeave *
|
autocmd VimLeave *
|
||||||
\ for s:jobbuf in keys(s:edit_jobs) |
|
\ for s:jobbuf in keys(s:edit_jobs) |
|
||||||
\ call writefile(['Aborting edit due to Vim exit.'], s:edit_jobs[s:jobbuf][0].file . '.exit') |
|
\ call writefile(['Aborting edit due to Vim exit.'], s:edit_jobs[s:jobbuf][0].file . '.exit') |
|
||||||
@@ -2782,6 +2864,7 @@ function! fugitive#Command(line1, line2, range, bang, mods, arg) abort
|
|||||||
let args = s:AskPassArgs(dir) + args
|
let args = s:AskPassArgs(dir) + args
|
||||||
endif
|
endif
|
||||||
let tmp = {
|
let tmp = {
|
||||||
|
\ 'line_count': 0,
|
||||||
\ 'err': '',
|
\ 'err': '',
|
||||||
\ 'out': '',
|
\ 'out': '',
|
||||||
\ 'echo': '',
|
\ 'echo': '',
|
||||||
|
|||||||
Reference in New Issue
Block a user