Refactor a tiny bit and add some TODOs.
This commit is contained in:
parent
5c1bc7dfe9
commit
b00fdf08bc
@ -25,6 +25,7 @@ endif
|
|||||||
function! s:GundoMove(direction)
|
function! s:GundoMove(direction)
|
||||||
let start_line = getline('.')
|
let start_line = getline('.')
|
||||||
|
|
||||||
|
" If we're in between two nodes we move by one to get back on track.
|
||||||
if stridx(start_line, '[') == -1
|
if stridx(start_line, '[') == -1
|
||||||
let distance = 1
|
let distance = 1
|
||||||
else
|
else
|
||||||
@ -33,6 +34,7 @@ function! s:GundoMove(direction)
|
|||||||
|
|
||||||
let target_n = line('.') + (distance * a:direction)
|
let target_n = line('.') + (distance * a:direction)
|
||||||
|
|
||||||
|
" Bound the movement to the graph.
|
||||||
if target_n <= 4
|
if target_n <= 4
|
||||||
call cursor(5, 0)
|
call cursor(5, 0)
|
||||||
elseif target_n >= line('$')
|
elseif target_n >= line('$')
|
||||||
@ -42,6 +44,8 @@ function! s:GundoMove(direction)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
|
|
||||||
|
" Move to the node, whether it's an @ or an o
|
||||||
let idx1 = stridx(line, '@')
|
let idx1 = stridx(line, '@')
|
||||||
let idx2 = stridx(line, 'o')
|
let idx2 = stridx(line, 'o')
|
||||||
if idx1 != -1
|
if idx1 != -1
|
||||||
@ -58,6 +62,7 @@ endfunction
|
|||||||
|
|
||||||
"{{{ Buffer/Window Management
|
"{{{ Buffer/Window Management
|
||||||
function! s:GundoResizeBuffers(backto)
|
function! s:GundoResizeBuffers(backto)
|
||||||
|
" This sucks and doesn't work. TODO: Fix it.
|
||||||
exe bufwinnr(bufwinnr('__Gundo__')) . "wincmd w"
|
exe bufwinnr(bufwinnr('__Gundo__')) . "wincmd w"
|
||||||
exe "vertical resize " . g:gundo_width
|
exe "vertical resize " . g:gundo_width
|
||||||
exe bufwinnr(bufwinnr('__Gundo_Preview__')) . "wincmd w"
|
exe bufwinnr(bufwinnr('__Gundo_Preview__')) . "wincmd w"
|
||||||
@ -94,18 +99,31 @@ endfunction
|
|||||||
|
|
||||||
function! s:GundoToggle()
|
function! s:GundoToggle()
|
||||||
if expand('%') == "__Gundo__"
|
if expand('%') == "__Gundo__"
|
||||||
|
" TODO: Add some sanity checks here.
|
||||||
quit
|
quit
|
||||||
exe bufwinnr(bufnr('__Gundo_Preview__')) . "wincmd w"
|
exe bufwinnr(bufnr('__Gundo_Preview__')) . "wincmd w"
|
||||||
quit
|
quit
|
||||||
exe bufwinnr(g:gundo_target_n) . "wincmd w"
|
exe bufwinnr(g:gundo_target_n) . "wincmd w"
|
||||||
else
|
else
|
||||||
if expand('%') != "__Gundo_Preview__"
|
if expand('%') != "__Gundo_Preview__"
|
||||||
|
" Record the previous buffer number.
|
||||||
|
"
|
||||||
|
" This sucks because we're not getting the window number, and there
|
||||||
|
" may be more than one window viewing the same buffer, so we might
|
||||||
|
" go back to the wrong one.
|
||||||
|
"
|
||||||
|
" Unfortunately window numbers change as we open more windows.
|
||||||
|
"
|
||||||
|
" TODO: Figure out how to fix this.
|
||||||
let g:gundo_target_n = bufnr('')
|
let g:gundo_target_n = bufnr('')
|
||||||
let g:gundo_target_f = @%
|
let g:gundo_target_f = @%
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call s:GundoOpenPreview()
|
call s:GundoOpenPreview()
|
||||||
exe bufwinnr(g:gundo_target_n) . "wincmd w"
|
exe bufwinnr(g:gundo_target_n) . "wincmd w"
|
||||||
GundoRender
|
GundoRender
|
||||||
|
|
||||||
|
" TODO: Move these lines into RenderPreview
|
||||||
let target_line = matchstr(getline("."), '\v\[[0-9]+\]')
|
let target_line = matchstr(getline("."), '\v\[[0-9]+\]')
|
||||||
let target_num = matchstr(target_line, '\v[0-9]+')
|
let target_num = matchstr(target_line, '\v[0-9]+')
|
||||||
call s:GundoRenderPreview(target_num)
|
call s:GundoRenderPreview(target_num)
|
||||||
@ -119,6 +137,7 @@ function! s:GundoMarkPreviewBuffer()
|
|||||||
setlocal buflisted
|
setlocal buflisted
|
||||||
setlocal nomodifiable
|
setlocal nomodifiable
|
||||||
setlocal filetype=diff
|
setlocal filetype=diff
|
||||||
|
" TODO: Set foldmethod?
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:GundoMarkBuffer()
|
function! s:GundoMarkBuffer()
|
||||||
@ -549,7 +568,10 @@ def _make_nodes(alts, nodes, parent=None):
|
|||||||
_make_nodes(alt['alt'], nodes, p)
|
_make_nodes(alt['alt'], nodes, p)
|
||||||
p = node
|
p = node
|
||||||
|
|
||||||
def make_nodes(entries):
|
def make_nodes():
|
||||||
|
ut = vim.eval('undotree()')
|
||||||
|
entries = ut['entries']
|
||||||
|
|
||||||
root = Node(0, None, False, 0)
|
root = Node(0, None, False, 0)
|
||||||
nodes = []
|
nodes = []
|
||||||
_make_nodes(entries, nodes, root)
|
_make_nodes(entries, nodes, root)
|
||||||
@ -570,10 +592,7 @@ function! s:GundoRender()
|
|||||||
python << ENDPYTHON
|
python << ENDPYTHON
|
||||||
|
|
||||||
def GundoRender():
|
def GundoRender():
|
||||||
ut = vim.eval('undotree()')
|
root, nodes = make_nodes()
|
||||||
entries = ut['entries']
|
|
||||||
|
|
||||||
root, nodes = make_nodes(entries)
|
|
||||||
|
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
node.children = [n for n in nodes if n.parent == node]
|
node.children = [n for n in nodes if n.parent == node]
|
||||||
@ -622,10 +641,7 @@ import difflib
|
|||||||
def GundoRenderPreview():
|
def GundoRenderPreview():
|
||||||
_goto_window_for_buffer(vim.eval('g:gundo_target_n'))
|
_goto_window_for_buffer(vim.eval('g:gundo_target_n'))
|
||||||
|
|
||||||
ut = vim.eval('undotree()')
|
root, nodes = make_nodes()
|
||||||
entries = ut['entries']
|
|
||||||
|
|
||||||
root, nodes = make_nodes(entries)
|
|
||||||
current = changenr(nodes)
|
current = changenr(nodes)
|
||||||
|
|
||||||
target_n = int(vim.eval('a:target'))
|
target_n = int(vim.eval('a:target'))
|
||||||
@ -637,13 +653,16 @@ def GundoRenderPreview():
|
|||||||
else:
|
else:
|
||||||
vim.command('silent undo %d' % node_before.n)
|
vim.command('silent undo %d' % node_before.n)
|
||||||
before = vim.current.buffer[:]
|
before = vim.current.buffer[:]
|
||||||
|
|
||||||
vim.command('silent undo %d' % node_after.n)
|
vim.command('silent undo %d' % node_after.n)
|
||||||
after = vim.current.buffer[:]
|
after = vim.current.buffer[:]
|
||||||
|
|
||||||
vim.command('silent undo %d' % current)
|
vim.command('silent undo %d' % current)
|
||||||
|
|
||||||
_goto_window_for_buffer_name('__Gundo_Preview__')
|
_goto_window_for_buffer_name('__Gundo_Preview__')
|
||||||
vim.command('setlocal modifiable')
|
vim.command('setlocal modifiable')
|
||||||
|
|
||||||
|
# TODO: Make some nice dates from Node.time to give to difflib.
|
||||||
diff = list(difflib.unified_diff(before, after, node_before.n, node_after.n))
|
diff = list(difflib.unified_diff(before, after, node_before.n, node_after.n))
|
||||||
vim.current.buffer[:] = diff
|
vim.current.buffer[:] = diff
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user