--- a/doc/gundo.txt Tue Nov 09 20:56:24 2010 -0500
+++ b/doc/gundo.txt Tue Nov 09 21:13:21 2010 -0500
@@ -96,6 +96,10 @@
Pressing enter on a state (or double clicking on it) will revert the contents
of the file to match that state.
+You can use p on a state to make the preview window show the diff between
+your current state and the selected state, instead of a preview of what the
+selected state changed.
+
Pressing P while on a state will initiate "play to" mode targeted at that
state. This will replay all the changes between your current state and the
target, with a slight pause after each change. It's mostly useless, but can be
@@ -192,6 +196,8 @@
* Fix movement commands with counts in the graph.
* Make GundoToggle close the Gundo windows if they're visible but not the
current window, instead of moving to them.
+ * Add the 'p' mapping to preview the result of reverting to the selected
+ state.
v1.0.0
* Initial stable release.
--- a/plugin/gundo.vim Tue Nov 09 20:56:24 2010 -0500
+++ b/plugin/gundo.vim Tue Nov 09 21:13:21 2010 -0500
@@ -55,6 +55,8 @@
let g:gundo_right = 0
endif"}}}
+let s:inline_help_length = 6
+
"}}}
"{{{ Mercurial's graphlog code
@@ -427,7 +429,8 @@
INLINE_HELP = '''\
" Gundo for %s [%d]
" j/k - move between undo states
-" <cr> - revert to that state
+" p - preview diff of selected and current states
+" <cr> - revert to selected state
'''
ENDPYTHON
@@ -518,6 +521,7 @@
nnoremap <script> <silent> <buffer> k :call <sid>GundoMove(-1)<CR>
nnoremap <script> <silent> <buffer> gg gg:call <sid>GundoMove(1)<CR>
nnoremap <script> <silent> <buffer> P :call <sid>GundoPlayTo()<CR>
+ nnoremap <script> <silent> <buffer> p :call <sid>GundoRenderChangePreview()<CR>
nnoremap <script> <silent> <buffer> q :call <sid>GundoClose()<CR>
cabbrev <script> <silent> <buffer> q call <sid>GundoClose()
cabbrev <script> <silent> <buffer> quit call <sid>GundoClose()
@@ -719,8 +723,8 @@
let target_n = line('.') + (distance * a:direction)
" Bound the movement to the graph.
- if target_n <= 4
- call cursor(5, 0)
+ if target_n <= s:inline_help_length - 1
+ call cursor(s:inline_help_length, 0)
else
call cursor(target_n, 0)
endif
@@ -797,6 +801,26 @@
return list(difflib.unified_diff(before_lines, after_lines,
before_name, after_name,
before_time, after_time))
+
+def _generate_change_preview_diff(current, node_before, node_after):
+ _goto_window_for_buffer(vim.eval('g:gundo_target_n'))
+
+ _undo_to(node_before.n)
+ before_lines = vim.current.buffer[:]
+
+ _undo_to(node_after.n)
+ after_lines = vim.current.buffer[:]
+
+ before_name = node_before.n or 'Original'
+ before_time = node_before.time and _fmt_time(node_before.time) or ''
+ after_name = node_after.n or 'Original'
+ after_time = node_after.time and _fmt_time(node_after.time) or ''
+
+ _undo_to(current)
+
+ return list(difflib.unified_diff(before_lines, after_lines,
+ before_name, after_name,
+ before_time, after_time))
ENDPYTHON
"}}}
@@ -880,6 +904,40 @@
ENDPYTHON
endfunction"}}}
+function! s:GundoRenderChangePreview()"{{{
+python << ENDPYTHON
+def GundoRenderChangePreview():
+ if not _check_sanity():
+ return
+
+ target_state = vim.eval('s:GundoGetTargetState()')
+
+ # Check that there's an undo state. There may not be if we're talking about
+ # a buffer with no changes yet.
+ if target_state == None:
+ _goto_window_for_buffer_name('__Gundo__')
+ return
+ else:
+ target_state = int(target_state)
+
+ _goto_window_for_buffer(vim.eval('g:gundo_target_n'))
+
+ nodes, nmap = make_nodes()
+ current = changenr(nodes)
+
+ node_after = nmap[target_state]
+ node_before = nmap[current]
+ print node_after, node_before
+
+ vim.command('call s:GundoOpenPreview()')
+ _output_preview_text(_generate_change_preview_diff(current, node_before, node_after))
+
+ _goto_window_for_buffer_name('__Gundo__')
+
+GundoRenderChangePreview()
+ENDPYTHON
+endfunction"}}}
+
"}}}
"{{{ Gundo undo/redo
--- a/site/index.html Tue Nov 09 20:56:24 2010 -0500
+++ b/site/index.html Tue Nov 09 21:13:21 2010 -0500
@@ -203,6 +203,12 @@
</p>
<p>
+ You can use p on a state to make the preview window show the diff between
+ your current state and the selected state, instead of a preview of what the
+ selected state changed.
+ </p>
+
+ <p>
Pressing <code>P</code> while on a state will initiate "play to" mode targeted at that
state. This will replay all the changes between your current state and the
target, with a slight pause after each change. It's mostly useless, but can be