From 82678cbdeb152ff871aa1fcdbd17bb437603c9b4 Mon Sep 17 00:00:00 2001 From: Steve Losh Date: Sat, 9 Oct 2010 11:47:09 -0400 Subject: [PATCH] Hello there, preview pane. --- plugin/gundo.vim | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/plugin/gundo.vim b/plugin/gundo.vim index 2c7ec66..cafe9fe 100644 --- a/plugin/gundo.vim +++ b/plugin/gundo.vim @@ -34,7 +34,9 @@ function! s:GundoMoveUp() call cursor(0, idx2 + 1) endif - call s:GundoRenderPreview() + let target_line = matchstr(getline("."), '\v\[[0-9]+\]') + let target_num = matchstr(target_line, '\v[0-9]+') + call s:GundoRenderPreview(target_num) endfunction function! s:GundoMoveDown() @@ -49,7 +51,9 @@ function! s:GundoMoveDown() call cursor(0, idx2 + 1) endif - call s:GundoRenderPreview() + let target_line = matchstr(getline("."), '\v\[[0-9]+\]') + let target_num = matchstr(target_line, '\v[0-9]+') + call s:GundoRenderPreview(target_num) endfunction "}}} @@ -101,6 +105,9 @@ function! s:GundoToggle() call s:GundoOpenPreview() exe bufwinnr(g:gundo_target_n) . "wincmd w" GundoRender + let target_line = matchstr(getline("."), '\v\[[0-9]+\]') + let target_num = matchstr(target_line, '\v[0-9]+') + call s:GundoRenderPreview(target_num) endif endfunction @@ -110,6 +117,7 @@ function! s:GundoMarkPreviewBuffer() setlocal noswapfile setlocal buflisted setlocal nomodifiable + setlocal filetype=diff endfunction function! s:GundoMarkBuffer() @@ -603,16 +611,35 @@ endfunction "}}} "{{{ Preview Rendering -function! s:GundoRenderPreview() +function! s:GundoRenderPreview(target) python << ENDPYTHON -import vim +import difflib _goto_window_for_buffer(vim.eval('g:gundo_target_n')) root, nodes = make_nodes(entries) current = changenr(nodes) -print current +target_n = int(vim.eval('a:target')) +node_after = [node for node in nodes if node.n == target_n][0] +node_before = node_after.parent + +vim.command('silent undo %d' % node_before.n) +before = vim.current.buffer[:] +vim.command('silent undo %d' % node_after.n) +after = vim.current.buffer[:] +vim.command('silent undo %d' % current) + +_goto_window_for_buffer_name('__Gundo_Preview__') +vim.command('setlocal modifiable') + +diff = list(difflib.unified_diff(before, after, node_before.n, node_after.n)) +vim.current.buffer[:] = diff + +vim.command('setlocal nomodifiable') + +_goto_window_for_buffer_name('__Gundo__') + ENDPYTHON endfunction "}}}