Move select temp file configuration to BufReadPre
This allows the natural machinery to kick in rather than invoking FugitiveDetect() and fugitive#MapJumps() explicitly.
This commit is contained in:
parent
0a536ed5af
commit
cce9ca0933
@ -2071,38 +2071,41 @@ function! s:TempState(...) abort
|
||||
return get(s:temp_files, s:cpath(fnamemodify(a:0 ? a:1 : @%, ':p')), {})
|
||||
endfunction
|
||||
|
||||
function! s:SetupTemp(file) abort
|
||||
function! s:TempReadPre(file) abort
|
||||
if has_key(s:temp_files, s:cpath(a:file))
|
||||
let dict = s:temp_files[s:cpath(a:file)]
|
||||
setlocal nomodeline
|
||||
setlocal bufhidden=delete nobuflisted
|
||||
setlocal buftype=nowrite
|
||||
if has_key(dict, 'modifiable')
|
||||
let &l:modifiable = dict.modifiable
|
||||
endif
|
||||
if len(dict.dir)
|
||||
let b:git_dir = dict.dir
|
||||
call extend(b:, {'fugitive_type': 'temp'}, 'keep')
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:TempReadPost(file) abort
|
||||
if has_key(s:temp_files, s:cpath(a:file))
|
||||
let dict = s:temp_files[s:cpath(a:file)]
|
||||
if has_key(dict, 'filetype') && dict.filetype !=# &l:filetype
|
||||
let &l:filetype = dict.filetype
|
||||
endif
|
||||
setlocal foldmarker=<<<<<<<,>>>>>>>
|
||||
setlocal bufhidden=delete nobuflisted
|
||||
setlocal buftype=nowrite
|
||||
setlocal nomodeline
|
||||
if empty(mapcheck('q', 'n'))
|
||||
nnoremap <buffer> <silent> q :<C-U>bdelete<Bar>echohl WarningMsg<Bar>echo "Temp file q is deprecated in favor of the built-in <Lt>C-W>q"<Bar>echohl NONE<CR>
|
||||
endif
|
||||
exe 'nnoremap <buffer> <silent>' s:nowait "gq :<C-U>bdelete<CR>"
|
||||
if getline(1) !~# '^diff '
|
||||
setlocal nomodifiable
|
||||
endif
|
||||
if len(dict.dir)
|
||||
let b:git_dir = dict.dir
|
||||
call extend(b:, {'fugitive_type': 'temp'}, 'keep')
|
||||
call FugitiveDetect(a:file)
|
||||
if &filetype ==# 'git'
|
||||
call fugitive#MapJumps()
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return ''
|
||||
endfunction
|
||||
|
||||
augroup fugitive_temp
|
||||
autocmd!
|
||||
autocmd BufNewFile,BufReadPost * exe s:SetupTemp(expand('<amatch>:p'))
|
||||
autocmd BufReadPre * exe s:TempReadPre( expand('<amatch>:p'))
|
||||
autocmd BufReadPost * exe s:TempReadPost(expand('<amatch>:p'))
|
||||
augroup END
|
||||
|
||||
" Section: :Git
|
||||
@ -3926,7 +3929,7 @@ function! s:OpenExec(cmd, mods, args, ...) abort
|
||||
\ (&shell =~# 'csh' ? ' >& ' . temp : ' > ' . temp . ' 2>&1')
|
||||
redraw!
|
||||
let temp = s:Resolve(temp)
|
||||
let s:temp_files[s:cpath(temp)] = { 'dir': dir, 'filetype': 'git' }
|
||||
let s:temp_files[s:cpath(temp)] = { 'dir': dir, 'filetype': 'git', 'modifiable': get(readfile(temp, 1), '') =~# '^diff ' }
|
||||
if a:cmd ==# 'edit'
|
||||
call s:BlurStatus()
|
||||
endif
|
||||
@ -4645,7 +4648,7 @@ function! s:BlameCommand(line1, line2, range, count, bang, mods, reg, arg, args)
|
||||
return s:BlameCommit(edit, get(readfile(temp), 0, ''), bufnr(''))
|
||||
else
|
||||
let temp = s:Resolve(temp)
|
||||
let s:temp_files[s:cpath(temp)] = {'dir': s:Dir(), 'filetype': 'fugitiveblame', 'args': cmd}
|
||||
let s:temp_files[s:cpath(temp)] = {'dir': s:Dir(), 'filetype': 'fugitiveblame', 'args': cmd, 'modifiable': 0}
|
||||
for winnr in range(winnr('$'),1,-1)
|
||||
if getwinvar(winnr, '&scrollbind')
|
||||
call setwinvar(winnr, '&scrollbind', 0)
|
||||
|
Loading…
Reference in New Issue
Block a user