Make GundoToggle behave more sanely.
fixes issue 17
author |
Steve Losh <steve@stevelosh.com> |
date |
Tue, 09 Nov 2010 19:46:05 -0500 |
parents |
cbfa66a2be7a
|
children |
d3fdfa4918f5
|
branches/tags |
(none) |
files |
doc/gundo.txt plugin/gundo.vim site/index.html |
Changes
--- 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.
--- 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()
--- 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 @@
<ul>
<li>Add the <code>g:gundo_disable</code> setting.</li>
<li>Fix movement commands with counts in the graph.</li>
+ <li>
+ Make GundoToggle close the Gundo windows if they're
+ visible but not the current window, instead of
+ moving to them.
+ </li>
</ul>
</li>
<li>v1.0.0