# HG changeset patch # User Steve Losh # Date 1289349965 18000 # Node ID b58795eee108240da117bc10cd807d74122bb4cd # Parent cbfa66a2be7a84eba7117f8a605c46fed46c7cf4 Make GundoToggle behave more sanely. fixes issue 17 diff -r cbfa66a2be7a -r b58795eee108 doc/gundo.txt --- a/doc/gundo.txt Thu Nov 04 19:44:28 2010 -0400 +++ b/doc/gundo.txt Tue Nov 09 19:46:05 2010 -0500 @@ -190,6 +190,8 @@ Development version * Add the g:gundo_disable setting. * 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. v1.0.0 * Initial stable release. diff -r cbfa66a2be7a -r b58795eee108 plugin/gundo.vim --- a/plugin/gundo.vim Thu Nov 04 19:44:28 2010 -0400 +++ b/plugin/gundo.vim Tue Nov 09 19:46:05 2010 -0500 @@ -390,7 +390,7 @@ def _check_sanity(): '''Check to make sure we're not crazy. - + Does the following things: * Make sure the target buffer still exists. @@ -500,6 +500,14 @@ endif endfunction"}}} +function! s:GundoIsVisible()"{{{ + if bufwinnr(bufnr("__Gundo__")) != -1 || bufwinnr(bufnr("__Gundo_Preview__")) != -1 + return 1 + else + return 0 + endif +endfunction"}}} + "}}} "{{{ Gundo buffer settings @@ -663,29 +671,21 @@ exe bufwinnr(g:gundo_target_n) . "wincmd w" endfunction"}}} +function! s:GundoOpen()"{{{ + call s:GundoOpenPreview() + exe bufwinnr(g:gundo_target_n) . "wincmd w" + + call s:GundoRenderGraph() + call s:GundoRenderPreview() +endfunction"}}} + function! s:GundoToggle()"{{{ - if expand('%') == "__Gundo__" + if s:GundoIsVisible() call s:GundoClose() else - 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_f = @% - endif - - call s:GundoOpenPreview() - exe bufwinnr(g:gundo_target_n) . "wincmd w" - GundoRender - - call s:GundoRenderPreview() + let g:gundo_target_n = bufnr('') + let g:gundo_target_f = @% + call s:GundoOpen() endif endfunction"}}} @@ -702,7 +702,7 @@ call s:GundoRevert() endif endfunction"}}} - + "}}} "{{{ Gundo movement @@ -770,7 +770,7 @@ target = (vim.eval('g:gundo_target_f'), int(vim.eval('g:gundo_target_n'))) header = (INLINE_HELP % target).splitlines() - vim.command('GundoOpenGraph') + vim.command('call s:GundoOpenGraph()') vim.command('setlocal modifiable') vim.current.buffer[:] = (header + result) vim.command('setlocal nomodifiable') @@ -867,6 +867,7 @@ node_after = nmap[target_state] node_before = node_after.parent + vim.command('call s:GundoOpenPreview()') _output_preview_text(_generate_preview_diff(current, node_before, node_after)) _goto_window_for_buffer_name('__Gundo__') @@ -958,7 +959,6 @@ "}}} "{{{ Misc -command! -nargs=0 GundoOpenGraph call s:GundoOpenGraph() command! -nargs=0 GundoToggle call s:GundoToggle() command! -nargs=0 GundoRenderGraph call s:GundoRenderGraph() autocmd BufNewFile __Gundo__ call s:GundoSettingsGraph() diff -r cbfa66a2be7a -r b58795eee108 site/index.html --- a/site/index.html Thu Nov 04 19:44:28 2010 -0400 +++ b/site/index.html Tue Nov 09 19:46:05 2010 -0500 @@ -332,6 +332,11 @@
  • v1.0.0