def MundoGetTargetState(): """ Get the current undo number that mundo is at. """ util._goto_window_for_buffer_name("__Mundo__") target_line = vim.eval("getline('.')") matches = re.match("^.* \[([0-9]+)\] .*$", target_line) if matches: return int(matches.group(1)) return 0
def GundoGetTargetState(): """ Get the current undo number that gundo is at. """ util._goto_window_for_buffer_name('__Mundo__') target_line = vim.eval("getline('.')") matches = re.match('^.* \[([0-9]+)\] .*$', target_line) if matches: return int(matches.group(1)) return 0
def MundoRenderChangePreview(): """ Render the selected undo level with the current file. Return True on success, False on failure. """ if not _check_sanity(): return vim.command("call s:MundoOpenPreview()") util._output_preview_text(MundoGetChangesForLine()) util._goto_window_for_buffer_name("__Mundo__") return True
def GundoRenderChangePreview(): """ Render the selected undo level with the current file. Return True on success, False on failure. """ if not _check_sanity(): return vim.command('call s:GundoOpenPreview()') util._output_preview_text(GundoGetChangesForLine()) util._goto_window_for_buffer_name('__Mundo__') return True
def MundoRenderPatchdiff(): """ Call MundoRenderChangePreview and display a vert diffpatch with the current file. """ if MundoRenderChangePreview(): # if there are no lines, do nothing (show a warning). util._goto_window_for_buffer_name("__Mundo_Preview__") if vim.current.buffer[:] == [""]: # restore the cursor position before exiting. util._goto_window_for_buffer_name("__Mundo__") vim.command('unsilent echo "No difference between current file and undo number!"') return False # quit out of mundo main screen util._goto_window_for_buffer_name("__Mundo__") vim.command("quit") # save the __Mundo_Preview__ buffer to a temp file. util._goto_window_for_buffer_name("__Mundo_Preview__") (handle, filename) = tempfile.mkstemp() vim.command("silent! w %s" % (filename)) # exit the __Mundo_Preview__ window vim.command("bdelete") # diff the temp file vim.command("silent! keepalt vert diffpatch %s" % (filename)) vim.command("set buftype=nofile bufhidden=delete") return True return False
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). util._goto_window_for_buffer_name('__Mundo_Preview__') if vim.current.buffer[:] == ['']: # restore the cursor position before exiting. util._goto_window_for_buffer_name('__Mundo__') vim.command( 'unsilent echo "No difference between current file and undo number!"' ) return False # quit out of gundo main screen util._goto_window_for_buffer_name('__Mundo__') vim.command('quit') # save the __Mundo_Preview__ buffer to a temp file. util._goto_window_for_buffer_name('__Mundo_Preview__') (handle, filename) = tempfile.mkstemp() vim.command('silent! w %s' % (filename)) # exit the __Mundo_Preview__ window vim.command('bdelete') # diff the temp file vim.command('silent! keepalt vert diffpatch %s' % (filename)) vim.command('set buftype=nofile bufhidden=delete') return True return False
def MundoGetChangesForLine(): if not _check_sanity(): return False target_state = MundoGetTargetState() # 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: util._goto_window_for_buffer_name("__Mundo__") return False else: target_state = int(target_state) util._goto_window_for_buffer(vim.eval("g:mundo_target_n")) nodes, nmap = nodesData.make_nodes() node_after = nmap[target_state] node_before = nmap[nodesData.current()] return nodesData.change_preview_diff(node_before, node_after)
def GundoGetChangesForLine(): if not _check_sanity(): return False target_state = 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: util._goto_window_for_buffer_name('__Mundo__') return False else: target_state = int(target_state) util._goto_window_for_buffer(vim.eval('g:mundo_target_n')) nodes, nmap = nodesData.make_nodes() node_after = nmap[target_state] node_before = nmap[nodesData.current()] return nodesData.change_preview_diff(node_before, node_after)
def MundoRenderPreview(): if not _check_sanity(): return target_state = MundoGetTargetState() # 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: util._goto_window_for_buffer_name("__Mundo__") return else: target_state = int(target_state) util._goto_window_for_buffer(vim.eval("g:mundo_target_n")) nodes, nmap = nodesData.make_nodes() node_after = nmap[target_state] node_before = node_after.parent vim.command("call s:MundoOpenPreview()") util._output_preview_text(nodesData.preview_diff(node_before, node_after)) util._goto_window_for_buffer_name("__Mundo__")
def GundoRenderPreview(): if not _check_sanity(): return target_state = 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: util._goto_window_for_buffer_name('__Mundo__') return else: target_state = int(target_state) util._goto_window_for_buffer(vim.eval('g:mundo_target_n')) nodes, nmap = nodesData.make_nodes() node_after = nmap[target_state] node_before = node_after.parent vim.command('call s:GundoOpenPreview()') util._output_preview_text(nodesData.preview_diff(node_before, node_after)) util._goto_window_for_buffer_name('__Mundo__')
def GundoMatch(down): """ Jump to the next node that matches the current pattern. If there is a next node, search from the next node to the end of the list of changes. Stop on a match. """ if not _check_sanity(): return # save the current window number (should be the navigation window) # then generate the undo nodes, and then go back to the current window. util._goto_window_for_buffer(vim.eval('g:mundo_target_n')) nodes, nmap = nodesData.make_nodes() total = len(nodes) - 1 util._goto_window_for_buffer_name('__Mundo__') curline = int(vim.eval("line('.')")) gundo_node = GundoGetTargetState() found_version = -1 if total > 0: therange = range(gundo_node - 1, -1, -1) if down < 0: therange = range(gundo_node + 1, total + 1) for version in therange: util._goto_window_for_buffer_name('__Mundo__') undochanges = nodesData.preview_diff(nmap[version].parent, nmap[version]) # Look thru all of the changes, ignore the first two b/c those are the # diff timestamp fields (not relevent): for change in undochanges[3:]: match_index = vim.eval( 'match("%s",@/)' % change.replace("\\", "\\\\").replace('"', '\\"')) # only consider the matches that are actual additions or # subtractions if int(match_index) >= 0 and (change.startswith('-') or change.startswith('+')): found_version = version break # found something, lets get out of here: if found_version != -1: break util._goto_window_for_buffer_name('__Mundo__') if found_version >= 0: GundoMove(found_version, 1, False)
def MundoMatch(down): """ Jump to the next node that matches the current pattern. If there is a next node, search from the next node to the end of the list of changes. Stop on a match. """ if not _check_sanity(): return # save the current window number (should be the navigation window) # then generate the undo nodes, and then go back to the current window. util._goto_window_for_buffer(vim.eval("g:mundo_target_n")) nodes, nmap = nodesData.make_nodes() total = len(nodes) - 1 util._goto_window_for_buffer_name("__Mundo__") curline = int(vim.eval("line('.')")) mundo_node = MundoGetTargetState() found_version = -1 if total > 0: therange = range(mundo_node - 1, -1, -1) if down < 0: therange = range(mundo_node + 1, total + 1) for version in therange: util._goto_window_for_buffer_name("__Mundo__") undochanges = nodesData.preview_diff(nmap[version].parent, nmap[version]) # Look thru all of the changes, ignore the first two b/c those are the # diff timestamp fields (not relevent): for change in undochanges[3:]: match_index = vim.eval('match("%s",@/)' % change.replace("\\", "\\\\").replace('"', '\\"')) # only consider the matches that are actual additions or # subtractions if int(match_index) >= 0 and (change.startswith("-") or change.startswith("+")): found_version = version break # found something, lets get out of here: if found_version != -1: break util._goto_window_for_buffer_name("__Mundo__") if found_version >= 0: MundoMove(found_version, 1, False)