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
endfunction
function! fugitive#FileRead() abort
let [dir, rev] = s:DirRev(expand('<amatch>'))
function! fugitive#FileReadCmd(...) abort
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)
return "noautocmd '[read <amatch>"
return 'noautocmd ' . line . 'read ' . s:fnameescape(amatch)
endif
if rev !~# ':'
let cmd = fugitive#Prepare(dir, 'log', '--pretty=format:%B', '-1', rev)
else
let cmd = fugitive#Prepare(dir, 'cat-file', '-p', rev)
endif
return "'[read !" . escape(cmd, '!#%')
return line . 'read !' . escape(cmd, '!#%')
endfunction
function! fugitive#BufReadIndex() abort

View File

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