From 7982d30f695a6082caec78517aa53f249b00c44a Mon Sep 17 00:00:00 2001 From: Dane Summers Date: Tue, 12 Feb 2013 09:06:45 -0500 Subject: [PATCH 1/8] Added documentation to the help message, and added a 'diffpatch' function of the main file with an old undo. --- autoload/gundo.py | 51 +++++++++++++++++++++++++++++++++++++++++----- autoload/gundo.vim | 9 ++++++++ 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/autoload/gundo.py b/autoload/gundo.py index 21d66f0..2fdb19a 100644 --- a/autoload/gundo.py +++ b/autoload/gundo.py @@ -13,6 +13,7 @@ import sys import time import vim +import tempfile # Mercurial's graphlog code -------------------------------------------------------- @@ -273,9 +274,13 @@ def _undo_to(n): INLINE_HELP = '''\ " Gundo for %s (%d) -" j/k - move between undo states -" p - preview diff of selected and current states -" - revert to selected state +" j/k - Move between undo states. +" P - Play current state to selected undo. +" d - Vert diffpatch of selected undo and current state. +" p - Diff of selected undo and current state. +" r - Diff of selected undo and prior undo. +" q - Quit! +" - Revert to selected state. ''' @@ -473,9 +478,43 @@ def GundoRenderPreview(): _goto_window_for_buffer_name('__Gundo__') +def GundoRenderPatchdiff(): + """ Call GundoRenderChangePreview and display a vert diffpatch with the + current file. """ + if GundoRenderChangePreview(): + # if there are no lines, do nothing (show a warning). + _goto_window_for_buffer_name('__Gundo_Preview__') + if vim.current.buffer[:] == ['']: + # restore the cursor position before exiting. + _goto_window_for_buffer_name('__Gundo__') + vim.command('unsilent echo "No difference between current file and undo number!"') + return False + + # quit out of gundo main screen + _goto_window_for_buffer_name('__Gundo__') + vim.command('quit') + + # save the __Gundo_Preview__ buffer to a temp file. + _goto_window_for_buffer_name('__Gundo_Preview__') + (handle,filename) = tempfile.mkstemp() + vim.command('silent! w %s' % (filename)) + # exit the __Gundo_Preview__ window + vim.command('quit') + # diff the temp file + vim.command('silent! vert diffpatch %s' % (filename)) + + # TODO set the buftype to temp or nonwritable or... + # move out of the patch file and into the original file. + #vim.command('normal il') + return True + return False + def GundoRenderChangePreview(): + """ Render the selected undo level with the current file. + Return True on success, False on failure. """ + if not _check_sanity(): - return + return False target_state = vim.eval('s:GundoGetTargetState()') @@ -483,7 +522,7 @@ def GundoRenderChangePreview(): # a buffer with no changes yet. if target_state == None: _goto_window_for_buffer_name('__Gundo__') - return + return False else: target_state = int(target_state) @@ -500,6 +539,8 @@ def GundoRenderChangePreview(): _goto_window_for_buffer_name('__Gundo__') + return True + # Gundo undo/redo def GundoRevert(): diff --git a/autoload/gundo.vim b/autoload/gundo.vim index 9a9e5f9..1dcc02a 100644 --- a/autoload/gundo.vim +++ b/autoload/gundo.vim @@ -114,6 +114,7 @@ function! s:GundoMapGraph()"{{{ nnoremap