From baee3bbfe87784985a410924a2b3a0008d6b8424 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 23 Dec 2018 16:54:27 -0500 Subject: [PATCH] Prevent bad modeline from blocking a :split Closes https://github.com/tpope/vim-fugitive/issues/1136 --- autoload/fugitive.vim | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 49a7fd4..e0ce9b3 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -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 . : =fnameescape(StatusCfile()) nnoremap g? :help fugitive-:Gstatus nnoremap :help fugitive-:Gstatus + 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 ? ' ' : '') . + \ ' BufReadPost' . (modifiable ? '' : '|setl nomodifiable') catch /^fugitive:/ return 'echoerr v:errmsg' endtry