diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 1ee3292..e703693 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -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 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 ' - 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(':p')) + autocmd BufReadPre * exe s:TempReadPre( expand(':p')) + autocmd BufReadPost * exe s:TempReadPost(expand(':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)