Refactoring

This commit is contained in:
Marco Hinz 2015-12-08 22:19:46 +01:00
parent 64a6dbd5d8
commit a0e061a5cf
2 changed files with 31 additions and 44 deletions

View File

@ -31,45 +31,44 @@ function! SignifyFoldText()
return left . fill . right
endfunction
" Function: #do {{{1
function! sy#fold#do(bang) abort
" Function: #enable {{{1
function! sy#fold#enable(do_tab) abort
if !exists('b:sy')
echomsg 'signify: I cannot detect any changes!'
return
endif
if empty(a:bang)
if a:do_tab
tabedit %
endif
let [s:context0, s:context1] = get(g:, 'signify_fold_context', [3, 8])
let s:levels = s:get_levels(s:get_lines())
set foldexpr=SignifyFoldExpr(v:lnum)
set foldtext=SignifyFoldText()
if empty(a:bang)
if ! empty(get(g:, 'old_fdm', ''))
unlet g:old_fdm
endif
else
let g:old_fdm=&foldmethod
endif
set foldmethod=expr
set foldlevel=0
let g:signify_fold = 1
setlocal foldexpr=SignifyFoldExpr(v:lnum)
setlocal foldtext=SignifyFoldText()
setlocal foldmethod=expr
setlocal foldlevel=0
endfunction
function! sy#fold#disable() "abort
if empty(get(g:, 'old_fdm', '')) && get(g:, 'signify_fold')
tabclose
" Function: #disable {{{1
function! sy#fold#disable() abort
let &l:foldmethod = w:sy_fdm
normal! zO
endfunction
" Function: #toggle {{{1
function! sy#fold#toggle(do_tab) abort
if exists('w:sy_fdm')
call sy#fold#disable()
unlet w:sy_fdm
else
let &foldmethod=g:old_fdm
try
normal zE
catch
endtry
let w:sy_fdm = &foldmethod
call sy#fold#enable(a:do_tab)
endif
let g:signify_fold = 0
redraw!
call sy#start()
endfunction
" Function: s:get_lines {{{1
@ -88,18 +87,6 @@ function! s:get_lines() abort
return reverse(lines)
endfunction
" Function: #fold_toggle {{{1
function! sy#fold#toggle(bang) abort
if get(g:, 'signify_fold')
call sy#fold#disable()
else
call sy#fold#do(a:bang)
endif
redraw!
call sy#start()
endfunction
" }}}
" Function: s:get_levels {{{1

View File

@ -41,11 +41,11 @@ augroup END
command! -nargs=0 -bar SignifyDebug call sy#debug#list_active_buffers()
command! -nargs=0 -bar SignifyDebugDiff call sy#debug#verbose_diff_cmd()
command! -nargs=0 -bar SignifyDebugUnknown call sy#repo#debug_detection()
command! -nargs=0 -bar SignifyFold call sy#fold#do()
command! -nargs=0 -bar SignifyFold call sy#fold#enable(1)
command! -nargs=0 -bar SignifyRefresh call sy#util#refresh_windows()
command! -nargs=0 -bar SignifyToggle call sy#toggle()
command! -nargs=0 -bar SignifyToggleFold call sy#fold#toggle(0)
command! -nargs=0 -bar SignifyToggleHighlight call sy#highlight#line_toggle()
command! -nargs=0 -bar -bang SignifyToggleFold call sy#fold#toggle(<q-bang>)
" Init: mappings {{{1