From 64a6dbd5d8841a3153b6257ada3e5d46de195e4a Mon Sep 17 00:00:00 2001 From: albfan Date: Tue, 8 Dec 2015 13:40:10 +0100 Subject: [PATCH] Add bang option to SignifyToggleFold Without bang open folds on a new tab, with it on current buffer --- autoload/sy/fold.vim | 32 +++++++++++++++++++++++--------- doc/signify.txt | 8 ++++++++ plugin/signify.vim | 16 ++++++++-------- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/autoload/sy/fold.vim b/autoload/sy/fold.vim index ba4b3c1..1e653a7 100644 --- a/autoload/sy/fold.vim +++ b/autoload/sy/fold.vim @@ -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! diff --git a/doc/signify.txt b/doc/signify.txt index 95a4633..8e0035d 100644 --- a/doc/signify.txt +++ b/doc/signify.txt @@ -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 does on current buffer, +without it on new tab. + ------------------------------------------------------------------------------ *signify-:SignifyRefresh* > diff --git a/plugin/signify.vim b/plugin/signify.vim index 0b587e3..84acbb6 100644 --- a/plugin/signify.vim +++ b/plugin/signify.vim @@ -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() " Init: mappings {{{1