Prevent bad modeline from blocking a :split

Closes https://github.com/tpope/vim-fugitive/issues/1136
This commit is contained in:
Tim Pope
2018-12-23 16:54:27 -05:00
parent 38c6acf27a
commit baee3bbfe8

View File

@@ -1345,7 +1345,6 @@ function! s:ReplaceCmd(cmd, ...) abort
endif
let temp = s:Resolve(temp)
let fn = expand('%:p')
silent exe 'doau BufReadPre '.s:fnameescape(fn)
silent exe 'keepalt file '.temp
let modelines = &modelines
try
@@ -1365,7 +1364,6 @@ function! s:ReplaceCmd(cmd, ...) abort
if s:cpath(fnamemodify(bufname('$'), ':p'), temp)
silent execute 'bwipeout '.bufnr('$')
endif
silent exe 'doau BufReadPost '.s:fnameescape(fn)
endtry
endfunction
@@ -1377,6 +1375,7 @@ function! fugitive#BufReadStatus() abort
let b:fugitive_display_format = b:fugitive_display_format % 2
let b:fugitive_type = 'index'
try
silent doautocmd BufReadPre
let cmd = [fnamemodify(amatch, ':h')]
setlocal noro ma nomodeline
if s:cpath(fnamemodify($GIT_INDEX_FILE !=# '' ? $GIT_INDEX_FILE : b:git_dir . '/index', ':p')) !=# s:cpath(amatch)
@@ -1446,6 +1445,7 @@ function! fugitive#BufReadStatus() abort
nnoremap <buffer> . : <C-R>=<SID>fnameescape(<SID>StatusCfile())<CR><Home>
nnoremap <buffer> <silent> g? :help fugitive-:Gstatus<CR>
nnoremap <buffer> <silent> <F1> :help fugitive-:Gstatus<CR>
return 'silent doautocmd BufReadPost'
catch /^fugitive:/
return 'echoerr v:errmsg'
endtry
@@ -1521,7 +1521,7 @@ function! fugitive#BufReadCmd(...) abort
unlet b:fugitive_type
if rev =~# '^:\d:'
let &readonly = !filewritable(dir . '/index')
return 'silent doautocmd BufNewFile '.s:fnameescape(amatch)
return 'silent doautocmd BufNewFile'
else
setlocal readonly nomodifiable
return 'echo ' . string(error)
@@ -1544,6 +1544,7 @@ function! fugitive#BufReadCmd(...) abort
setlocal endofline
try
silent doautocmd BufReadPre
if b:fugitive_type ==# 'tree'
let b:fugitive_display_format = b:fugitive_display_format % 2
if b:fugitive_display_format
@@ -1584,17 +1585,12 @@ function! fugitive#BufReadCmd(...) abort
call s:ReplaceCmd([dir, 'ls-files', '--stage'])
elseif b:fugitive_type ==# 'blob'
call s:ReplaceCmd([dir, 'cat-file', b:fugitive_type, rev])
setlocal nomodeline
endif
finally
keepjumps call setpos('.',pos)
setlocal nomodified noswapfile
if rev !~# '^:.:'
setlocal nomodifiable
else
let &modifiable = b:fugitive_type !=# 'tree'
endif
let &readonly = !&modifiable || !filewritable(dir . '/index')
let modifiable = rev =~# '^:.:' && b:fugitive_type !=# 'tree'
let &readonly = !modifiable || !filewritable(dir . '/index')
if &bufhidden ==# ''
setlocal bufhidden=delete
endif
@@ -1607,7 +1603,8 @@ function! fugitive#BufReadCmd(...) abort
endif
endtry
return ''
return 'silent doautocmd' . (v:version >= 704 ? ' <nomodeline>' : '') .
\ ' BufReadPost' . (modifiable ? '' : '|setl nomodifiable')
catch /^fugitive:/
return 'echoerr v:errmsg'
endtry