mirror of
https://github.com/tpope/vim-fugitive.git
synced 2025-11-15 14:53:51 -05:00
Encapsulate doautocmd <nomodeline>
This commit is contained in:
@@ -138,6 +138,16 @@ function! s:executable(binary) abort
|
|||||||
return s:executables[a:binary]
|
return s:executables[a:binary]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:DoAutocmd(cmd) abort
|
||||||
|
if v:version >= 704 || (v:version == 703 && has('patch442'))
|
||||||
|
return 'doautocmd <nomodeline>' . a:cmd
|
||||||
|
elseif &modelines > 0
|
||||||
|
return 'try|set modelines=0|doautocmd ' . a:cmd . '|finally|set modelines=' . &modelines . '|endtry'
|
||||||
|
else
|
||||||
|
return 'doautocmd ' . a:cmd
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
let s:nowait = v:version >= 704 ? '<nowait>' : ''
|
let s:nowait = v:version >= 704 ? '<nowait>' : ''
|
||||||
|
|
||||||
function! s:Map(mode, lhs, rhs, ...) abort
|
function! s:Map(mode, lhs, rhs, ...) abort
|
||||||
@@ -1869,7 +1879,7 @@ function! fugitive#FileWriteCmd(...) abort
|
|||||||
let amatch = a:0 ? a:1 : expand('<amatch>')
|
let amatch = a:0 ? a:1 : expand('<amatch>')
|
||||||
let autype = a:0 > 1 ? 'Buf' : 'File'
|
let autype = a:0 > 1 ? 'Buf' : 'File'
|
||||||
if exists('#' . autype . 'WritePre')
|
if exists('#' . autype . 'WritePre')
|
||||||
execute 'doautocmd ' . autype . 'WritePre ' . s:fnameescape(amatch)
|
execute s:DoAutocmd(autype . 'WritePre ' . s:fnameescape(amatch))
|
||||||
endif
|
endif
|
||||||
try
|
try
|
||||||
let [dir, commit, file] = s:DirCommitFile(amatch)
|
let [dir, commit, file] = s:DirCommitFile(amatch)
|
||||||
@@ -1887,7 +1897,7 @@ function! fugitive#FileWriteCmd(...) abort
|
|||||||
if !exec_error
|
if !exec_error
|
||||||
setlocal nomodified
|
setlocal nomodified
|
||||||
if exists('#' . autype . 'WritePost')
|
if exists('#' . autype . 'WritePost')
|
||||||
execute 'doautocmd ' . autype . 'WritePost ' . s:fnameescape(amatch)
|
execute s:DoAutocmd(autype . 'WritePost ' . s:fnameescape(amatch))
|
||||||
endif
|
endif
|
||||||
return ''
|
return ''
|
||||||
else
|
else
|
||||||
@@ -1898,8 +1908,6 @@ function! fugitive#FileWriteCmd(...) abort
|
|||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:nomodeline = (v:version >= 704 ? '<nomodeline>' : '')
|
|
||||||
|
|
||||||
function! fugitive#BufReadCmd(...) abort
|
function! fugitive#BufReadCmd(...) abort
|
||||||
let amatch = a:0 ? a:1 : expand('<amatch>')
|
let amatch = a:0 ? a:1 : expand('<amatch>')
|
||||||
try
|
try
|
||||||
@@ -2008,8 +2016,8 @@ function! fugitive#BufReadCmd(...) abort
|
|||||||
endtry
|
endtry
|
||||||
|
|
||||||
setlocal modifiable
|
setlocal modifiable
|
||||||
return 'silent doautocmd' . s:nomodeline .
|
return 'silent ' . s:DoAutocmd('BufReadPost') .
|
||||||
\ ' BufReadPost' . (modifiable ? '' : '|setl nomodifiable')
|
\ (modifiable ? '' : '|setl nomodifiable')
|
||||||
catch /^fugitive:/
|
catch /^fugitive:/
|
||||||
return 'echoerr ' . string(v:exception)
|
return 'echoerr ' . string(v:exception)
|
||||||
endtry
|
endtry
|
||||||
@@ -3729,12 +3737,12 @@ function! s:GrepSubcommand(line1, line2, range, bang, mods, args) abort
|
|||||||
redraw
|
redraw
|
||||||
call s:QuickfixCreate(listnr, {'title': (listnr < 0 ? ':Ggrep ' : ':Glgrep ') . s:fnameescape(args)})
|
call s:QuickfixCreate(listnr, {'title': (listnr < 0 ? ':Ggrep ' : ':Glgrep ') . s:fnameescape(args)})
|
||||||
let tempfile = tempname()
|
let tempfile = tempname()
|
||||||
if v:version >= 704 | exe 'silent doautocmd <nomodeline> QuickFixCmdPre ' (listnr < 0 ? 'Ggrep' : 'Glgrep') | endif
|
silent exe s:DoAutocmd('QuickFixCmdPre ' . (listnr < 0 ? 'Ggrep' : 'Glgrep'))
|
||||||
exe '!' . escape(s:UserCommand(dir, cmd + args), '%#!')
|
exe '!' . escape(s:UserCommand(dir, cmd + args), '%#!')
|
||||||
\ printf(&shellpipe . (&shellpipe =~# '%s' ? '' : ' %s'), s:shellesc(tempfile))
|
\ printf(&shellpipe . (&shellpipe =~# '%s' ? '' : ' %s'), s:shellesc(tempfile))
|
||||||
let list = map(readfile(tempfile), 's:GrepParseLine(prefix, name_only, dir, v:val)')
|
let list = map(readfile(tempfile), 's:GrepParseLine(prefix, name_only, dir, v:val)')
|
||||||
call s:QuickfixSet(listnr, list, 'a')
|
call s:QuickfixSet(listnr, list, 'a')
|
||||||
if v:version >= 704 | exe 'silent doautocmd <nomodeline> QuickFixCmdPost ' (listnr < 0 ? 'Ggrep' : 'Glgrep') | endif
|
silent exe s:DoAutocmd('QuickFixCmdPost ' . (listnr < 0 ? 'Ggrep' : 'Glgrep'))
|
||||||
if !has('gui_running')
|
if !has('gui_running')
|
||||||
redraw
|
redraw
|
||||||
endif
|
endif
|
||||||
@@ -4155,7 +4163,7 @@ function! fugitive#WriteCommand(line1, line2, range, bang, mods, arg, args) abor
|
|||||||
|
|
||||||
unlet! restorewinnr
|
unlet! restorewinnr
|
||||||
let zero = s:Generate(':0:'.file)
|
let zero = s:Generate(':0:'.file)
|
||||||
silent execute 'doautocmd' s:nomodeline 'BufWritePost' s:fnameescape(zero)
|
silent exe s:DoAutocmd('BufWritePost ' . s:fnameescape(zero))
|
||||||
for tab in range(1,tabpagenr('$'))
|
for tab in range(1,tabpagenr('$'))
|
||||||
for winnr in range(1,tabpagewinnr(tab,'$'))
|
for winnr in range(1,tabpagewinnr(tab,'$'))
|
||||||
let bufnr = tabpagebuflist(tab)[winnr-1]
|
let bufnr = tabpagebuflist(tab)[winnr-1]
|
||||||
@@ -4246,7 +4254,7 @@ function! s:Dispatch(bang, cmd, args) abort
|
|||||||
endif
|
endif
|
||||||
silent noautocmd make!
|
silent noautocmd make!
|
||||||
redraw!
|
redraw!
|
||||||
return 'call fugitive#Cwindow()|silent doautocmd ShellCmdPost'
|
return 'call fugitive#Cwindow()|silent ' . s:DoAutocmd('ShellCmdPost')
|
||||||
endif
|
endif
|
||||||
finally
|
finally
|
||||||
let [&l:mp, &l:efm, b:current_compiler] = [mp, efm, cc]
|
let [&l:mp, &l:efm, b:current_compiler] = [mp, efm, cc]
|
||||||
@@ -5847,12 +5855,7 @@ augroup END
|
|||||||
|
|
||||||
function! fugitive#Init() abort
|
function! fugitive#Init() abort
|
||||||
if exists('#User#FugitiveBoot')
|
if exists('#User#FugitiveBoot')
|
||||||
try
|
exe s:DoAutocmd('User FugitiveBoot')
|
||||||
let [save_mls, &modelines] = [&mls, 0]
|
|
||||||
doautocmd User FugitiveBoot
|
|
||||||
finally
|
|
||||||
let &mls = save_mls
|
|
||||||
endtry
|
|
||||||
endif
|
endif
|
||||||
let dir = s:Dir()
|
let dir = s:Dir()
|
||||||
if stridx(&tags, escape(dir, ', ')) == -1 && &tags !~# '\.git' && !exists('s:tags_warning')
|
if stridx(&tags, escape(dir, ', ')) == -1 && &tags !~# '\.git' && !exists('s:tags_warning')
|
||||||
@@ -5864,13 +5867,7 @@ function! fugitive#Init() abort
|
|||||||
echohl NONE
|
echohl NONE
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
try
|
exe s:DoAutocmd('User Fugitive')
|
||||||
let [save_mls, &modelines] = [&mls, 0]
|
|
||||||
call s:define_commands()
|
|
||||||
doautocmd User Fugitive
|
|
||||||
finally
|
|
||||||
let &mls = save_mls
|
|
||||||
endtry
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fugitive#is_git_dir(path) abort
|
function! fugitive#is_git_dir(path) abort
|
||||||
|
|||||||
Reference in New Issue
Block a user