From d16683449ce401cafe727ee940de0dfea430b7be Mon Sep 17 00:00:00 2001 From: Steve Losh Date: Wed, 20 Oct 2010 21:34:49 -0400 Subject: [PATCH] Factor out the "get target state" functionality into its own function. --- plugin/gundo.vim | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/plugin/gundo.vim b/plugin/gundo.vim index 0b913e9..9e13199 100644 --- a/plugin/gundo.vim +++ b/plugin/gundo.vim @@ -459,6 +459,12 @@ def changenr(nodes): ENDPYTHON "}}} +"{{{ Gundo utility functions +function! s:GundoGetTargetState() + let target_line = matchstr(getline("."), '\v\[[0-9]+\]') + return matchstr(target_line, '\v[0-9]+') +endfunction"}}} + "{{{ Gundo buffer settings function! s:GundoMapGraph()"{{{ @@ -525,7 +531,7 @@ endfunction"}}} "}}} -"{{{ Buffer/window management +"{{{ Gundo buffer/window management function! s:GundoResizeBuffers(backto)"{{{ exe bufwinnr(bufnr('__Gundo__')) . "wincmd w" @@ -626,15 +632,14 @@ function! s:GundoToggle()"{{{ GundoRender " TODO: Move these lines into RenderPreview - let target_line = matchstr(getline("."), '\v\[[0-9]+\]') - let target_num = matchstr(target_line, '\v[0-9]+') + let target_num = s:GundoGetTargetState() call s:GundoRenderPreview(target_num) endif endfunction"}}} "}}} -"{{{ Mouse handling +"{{{ Gundo mouse handling function! s:GundoMouseDoubleClick()"{{{ let start_line = getline('.') @@ -648,7 +653,7 @@ endfunction"}}} "}}} -"{{{ Movement +"{{{ Gundo movement function! s:GundoMove(direction)"{{{ let start_line = getline('.') @@ -680,14 +685,13 @@ function! s:GundoMove(direction)"{{{ call cursor(0, idx2 + 1) endif - let target_line = matchstr(getline("."), '\v\[[0-9]+\]') - let target_num = matchstr(target_line, '\v[0-9]+') + let target_num = s:GundoGetTargetState() call s:GundoRenderPreview(target_num) endfunction"}}} "}}} -"{{{ Rendering +"{{{ Gundo rendering function! s:GundoRenderGraph()"{{{ python << ENDPYTHON @@ -817,11 +821,10 @@ endfunction"}}} "}}} -"{{{ Undo/redo commands +"{{{ Gundo undo/redo function! s:GundoRevert()"{{{ - let target_line = matchstr(getline("."), '\v\[[0-9]+\]') - let target_num = matchstr(target_line, '\v[0-9]+') + let target_num = s:GundoGetTargetState() let back = bufwinnr(g:gundo_target_n) exe back . "wincmd w" python << ENDPYTHON @@ -832,8 +835,7 @@ ENDPYTHON endfunction"}}} function! s:GundoPlayTo()"{{{ - let target_line = matchstr(getline("."), '\v\[[0-9]+\]') - let target_num = matchstr(target_line, '\v[0-9]+') + let target_num = s:GundoGetTargetState() let back = bufwinnr(g:gundo_target_n) exe back . "wincmd w" normal zR