Skip to content

Commit

Permalink
Fix some leftover issues with auto-resetting
Browse files Browse the repository at this point in the history
There doesn't seem to be a way to close the other buffer as well -- ends
up in a segfault. For now, it's best to just reset the buffer and make
saving it safe.
  • Loading branch information
AndrewRadev committed Nov 14, 2012
1 parent 0746d28 commit c07c7c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
18 changes: 16 additions & 2 deletions autoload/linediff/differ.vim
Expand Up @@ -16,6 +16,7 @@ function! linediff#differ#New(sign_name, sign_number)
\ 'Init': function('linediff#differ#Init'),
\ 'IsBlank': function('linediff#differ#IsBlank'),
\ 'Reset': function('linediff#differ#Reset'),
\ 'CloseAndReset': function('linediff#differ#CloseAndReset'),
\ 'Lines': function('linediff#differ#Lines'),
\ 'Indent': function('linediff#differ#Indent'),
\ 'CreateDiffBuffer': function('linediff#differ#CreateDiffBuffer'),
Expand Down Expand Up @@ -65,6 +66,13 @@ function! linediff#differ#Reset() dict
let self.is_blank = 1
endfunction

" Closes the diff buffer and resets. The two actions are separate to avoid
" problems with closing already closed buffers.
function! linediff#differ#CloseAndReset() dict
call self.CloseDiffBuffer()
call self.Reset()
endfunction

" Extracts the relevant lines from the original buffer and returns them as a
" list.
function! linediff#differ#Lines() dict
Expand Down Expand Up @@ -134,17 +142,22 @@ endfunction
" update the other differ's data, provided a few conditions are met. See
" linediff#differ#PossiblyUpdateOtherDiffer() for details.
function! linediff#differ#UpdateOriginalBuffer() dict
if self.IsBlank()
return
endif

let saved_diff_buffer_view = winsaveview()
let new_lines = getbufline('%', 0, '$')

" Switch to the original buffer, delete the relevant lines, add the new
" ones, switch back to the diff buffer.
set bufhidden=hide
call linediff#util#SwitchBuffer(self.original_buffer)
let saved_view = winsaveview()
let saved_original_buffer_view = winsaveview()
call cursor(self.from, 1)
exe "normal! ".(self.to - self.from + 1)."dd"
call append(self.from - 1, new_lines)
call winrestview(saved_view)
call winrestview(saved_original_buffer_view)
call linediff#util#SwitchBuffer(self.diff_buffer)
set bufhidden=wipe

Expand All @@ -158,6 +171,7 @@ function! linediff#differ#UpdateOriginalBuffer() dict
call self.SetupSigns()

call self.PossiblyUpdateOtherDiffer(new_line_count - line_count)
call winrestview(saved_diff_buffer_view)
endfunction

" If the other differ originates from the same buffer and it's located below
Expand Down
11 changes: 4 additions & 7 deletions plugin/linediff.vim
Expand Up @@ -37,19 +37,16 @@ endfunction

command! LinediffReset call s:LinediffReset()
function! s:LinediffReset()
call s:differ_one.CloseDiffBuffer()
call s:differ_one.Reset()

call s:differ_two.CloseDiffBuffer()
call s:differ_two.Reset()
call s:differ_one.CloseAndReset()
call s:differ_two.CloseAndReset()
endfunction

function! s:PerformDiff()
call s:differ_one.CreateDiffBuffer("tabedit")
autocmd BufUnload <buffer> silent call s:differ_one.Reset()
autocmd BufUnload <buffer> silent call s:differ_one.Reset() | silent call s:differ_two.Reset()

call s:differ_two.CreateDiffBuffer("rightbelow vsplit")
autocmd BufUnload <buffer> silent call s:differ_two.Reset()
autocmd BufUnload <buffer> silent call s:differ_two.Reset() | silent call s:differ_one.Reset()

wincmd t " move to the first diff buffer

Expand Down

0 comments on commit c07c7c6

Please sign in to comment.