diff --git a/autoload/gitgutter/diff.vim b/autoload/gitgutter/diff.vim index 24142a2..3737d00 100644 --- a/autoload/gitgutter/diff.vim +++ b/autoload/gitgutter/diff.vim @@ -289,31 +289,11 @@ endfunction function! s:write_buffer(bufnr, file) - let _write = &write - set write - - " Write specified buffer (which may not be the current buffer) to buff_file. - " There doesn't seem to be a clean way to write a buffer that isn't the current - " to a file; we have to switch to it, write it, then switch back. - let current_buffer = bufnr('') - execute 'noautocmd buffer' a:bufnr - - " Writing the whole buffer resets the '[ and '] marks and also the - " 'modified' flag (if &cpoptions includes '+'). These are unwanted - " side-effects so we save and restore the values ourselves. - let modified = getbufvar(a:bufnr, "&mod") - let op_mark_start = getpos("'[") - let op_mark_end = getpos("']") - - execute 'keepalt noautocmd silent write!' a:file - - call setbufvar(a:bufnr, "&mod", modified) - call setpos("'[", op_mark_start) - call setpos("']", op_mark_end) - - execute 'noautocmd buffer' current_buffer - - let &write = _write + let bufcontents = getbufline(a:bufnr, 1, '$') + if getbufvar(a:bufnr, '&fileformat') ==# 'dos' + call map(bufcontents, 'v:val."\r"') + endif + call writefile(bufcontents, a:file) endfunction