Unify FileReadCmd autocommands

This commit is contained in:
Tim Pope
2018-07-17 17:13:49 -04:00
parent 0717396aa2
commit 792154e45d
2 changed files with 11 additions and 9 deletions

View File

@@ -2785,17 +2785,19 @@ function! fugitive#BufReadStatus() abort
endtry endtry
endfunction endfunction
function! fugitive#FileRead() abort function! fugitive#FileReadCmd(...) abort
let [dir, rev] = s:DirRev(expand('<amatch>')) let amatch = a:0 ? a:1 : expand('<amatch>')
let [dir, rev] = s:DirRev(amatch)
let line = a:0 > 1 ? a:2 : line("'[")
if empty(dir) if empty(dir)
return "noautocmd '[read <amatch>" return 'noautocmd ' . line . 'read ' . s:fnameescape(amatch)
endif endif
if rev !~# ':' if rev !~# ':'
let cmd = fugitive#Prepare(dir, 'log', '--pretty=format:%B', '-1', rev) let cmd = fugitive#Prepare(dir, 'log', '--pretty=format:%B', '-1', rev)
else else
let cmd = fugitive#Prepare(dir, 'cat-file', '-p', rev) let cmd = fugitive#Prepare(dir, 'cat-file', '-p', rev)
endif endif
return "'[read !" . escape(cmd, '!#%') return line . 'read !' . escape(cmd, '!#%')
endfunction endfunction
function! fugitive#BufReadIndex() abort function! fugitive#BufReadIndex() abort

View File

@@ -179,11 +179,11 @@ augroup fugitive
\ read <amatch> | \ read <amatch> |
\ 1delete | \ 1delete |
\ endif \ endif
autocmd FileReadCmd fugitive://**//[0-3]/** exe fugitive#FileRead() autocmd BufReadCmd fugitive://*//[0-3]/* exe fugitive#BufReadIndex()
autocmd BufReadCmd fugitive://**//[0-3]/** exe fugitive#BufReadIndex() autocmd BufWriteCmd fugitive://*//[0-3]/* exe fugitive#BufWriteIndex()
autocmd BufWriteCmd fugitive://**//[0-3]/** exe fugitive#BufWriteIndex() autocmd BufReadCmd fugitive://*//[0-9a-f][0-9a-f]* exe fugitive#BufReadObject()
autocmd BufReadCmd fugitive://**//[0-9a-f][0-9a-f]* exe fugitive#BufReadObject() autocmd FileReadCmd fugitive://*//* exe fugitive#FileReadCmd()
autocmd FileReadCmd fugitive://**//[0-9a-f][0-9a-f]* exe fugitive#FileRead() autocmd SourceCmd fugitive://*//* nested exe fugitive#SourceCmd()
autocmd User Flags call Hoist('buffer', function('FugitiveStatusline')) autocmd User Flags call Hoist('buffer', function('FugitiveStatusline'))
augroup END augroup END