Add bang option to SignifyToggleFold

Without bang open folds on a new tab, with it on current buffer
This commit is contained in:
albfan 2015-12-08 13:40:10 +01:00
parent 2033f3ce4e
commit 64a6dbd5d8
3 changed files with 39 additions and 17 deletions

View File

@ -32,29 +32,43 @@ function! SignifyFoldText()
endfunction
" Function: #do {{{1
function! sy#fold#do() abort
function! sy#fold#do(bang) abort
if !exists('b:sy')
echomsg 'signify: I cannot detect any changes!'
return
endif
if empty(a:bang)
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()
let g:old_fdm=&foldmethod
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
endfunction
function! sy#fold#disable() "abort
let &foldmethod=g:old_fdm
try
normal zE
catch
endtry
if empty(get(g:, 'old_fdm', '')) && get(g:, 'signify_fold')
tabclose
else
let &foldmethod=g:old_fdm
try
normal zE
catch
endtry
endif
let g:signify_fold = 0
endfunction
@ -76,11 +90,11 @@ function! s:get_lines() abort
endfunction
" Function: #fold_toggle {{{1
function! sy#fold#toggle() abort
function! sy#fold#toggle(bang) abort
if get(g:, 'signify_fold')
call sy#fold#disable()
else
call sy#fold#do()
call sy#fold#do(a:bang)
endif
redraw!

View File

@ -323,6 +323,14 @@ Toggle the plugin for the current buffer only.
<
Toggle line highlighting for lines containing changes.
------------------------------------------------------------------------------
*signify-:SignifyToggleFold*
>
:SignifyToggleFold
<
Toggle folding for lines without changes. Using <bang> does on current buffer,
without it on new tab.
------------------------------------------------------------------------------
*signify-:SignifyRefresh*
>

View File

@ -38,14 +38,14 @@ augroup END
" Init: commands {{{1
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 SignifyRefresh call sy#util#refresh_windows()
command! -nargs=0 -bar SignifyToggle call sy#toggle()
command! -nargs=0 -bar SignifyToggleHighlight call sy#highlight#line_toggle()
command! -nargs=0 -bar SignifyToggleFold call sy#fold#toggle()
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 SignifyRefresh call sy#util#refresh_windows()
command! -nargs=0 -bar SignifyToggle call sy#toggle()
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