Skip to content

Commit

Permalink
tlib#file#With(): Trigger BufRead autocommands
Browse files Browse the repository at this point in the history
  • Loading branch information
tomtom committed May 11, 2012
1 parent 3187967 commit c07af5a
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions autoload/tlib/file.vim
Expand Up @@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30.
" @Last Change: 2012-03-02.
" @Revision: 0.0.82
" @Last Change: 2012-03-23.
" @Revision: 0.0.106

if &cp || exists("loaded_tlib_file_autoload")
finish
Expand Down Expand Up @@ -97,22 +97,34 @@ endf
function! tlib#file#With(fcmd, bcmd, files, ...) "{{{3
" TLogVAR a:fcmd, a:bcmd, a:files
exec tlib#arg#Let([['world', {}]])
call tlib#autocmdgroup#Init()
augroup TLibFileRead
autocmd!
augroup END
for f in a:files
let bn = bufnr('^'.f.'$')
" TLogVAR f, bn
let bufloaded = bufloaded(bn)
let ok = 0
let s:bufread = ""
if bn != -1 && buflisted(bn)
if !empty(a:bcmd)
" TLogDBG a:bcmd .' '. bn
exec a:bcmd .' '. bn
let ok = 1
call s:SetScrollBind(world)
endif
else
if filereadable(f)
if !empty(a:fcmd)
" TLogDBG a:fcmd .' '. tlib#arg#Ex(f)
" exec a:fcmd .' '. escape(f, '%#\ ')
" exec a:fcmd .' '. escape(f, '%# ')
exec a:fcmd .' '. tlib#arg#Ex(f)
exec 'autocmd TLibFileRead BufRead' escape(f, ' ') 'let s:bufread=expand("<afile>:p")'
try
exec a:fcmd .' '. tlib#arg#Ex(f)
finally
exec 'autocmd! TLibFileRead BufRead'
endtry
let ok = 1
call s:SetScrollBind(world)
endif
else
Expand All @@ -121,7 +133,13 @@ function! tlib#file#With(fcmd, bcmd, files, ...) "{{{3
echohl NONE
endif
endif
" TLogVAR ok, bufloaded, &filetype
if empty(s:bufread) && ok && !bufloaded && empty(&filetype)
doautocmd BufRead
endif
endfor
augroup! TLibFileRead
unlet! s:bufread
" TLogDBG "done"
endf

Expand Down

0 comments on commit c07af5a

Please sign in to comment.