diff --git a/autoload/sy/fold.vim b/autoload/sy/fold.vim index 257aacd..35028d8 100644 --- a/autoload/sy/fold.vim +++ b/autoload/sy/fold.vim @@ -31,21 +31,62 @@ function! SignifyFoldText() return left . fill . right endfunction -" Function: #do {{{1 -function! sy#fold#do() abort +" Function: #dispatch {{{1 +function! sy#fold#dispatch(do_tab) abort + if a:do_tab + call sy#fold#enable(1) + else + call sy#fold#toggle() + endif +endfunction + +" Function: #enable {{{1 +function! sy#fold#enable(do_tab) abort if !exists('b:sy') echomsg 'signify: I cannot detect any changes!' return endif - tabedit % + 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() - set foldmethod=expr - set foldlevel=0 + setlocal foldexpr=SignifyFoldExpr(v:lnum) + setlocal foldtext=SignifyFoldText() + setlocal foldmethod=expr + setlocal foldlevel=0 +endfunction + +" Function: #disable {{{1 +function! sy#fold#disable() abort + let &l:foldmethod = w:sy_folded.method + let &l:foldtext = w:sy_folded.text + normal! zv +endfunction + +" Function: #toggle {{{1 +function! sy#fold#toggle() abort + if exists('w:sy_folded') + call sy#fold#disable() + if w:sy_folded.method == 'manual' + loadview + endif + unlet w:sy_folded + else + let w:sy_folded = { 'method': &foldmethod, 'text': &foldtext } + if &foldmethod == 'manual' + let old_vop = &viewoptions + mkview + let &viewoptions = old_vop + endif + call sy#fold#enable(0) + endif + + redraw! + call sy#start() endfunction " Function: s:get_lines {{{1 @@ -64,6 +105,7 @@ function! s:get_lines() abort return reverse(lines) endfunction +" }}} " Function: s:get_levels {{{1 function! s:get_levels(lines) abort diff --git a/doc/signify.txt b/doc/signify.txt index 95a4633..03582f6 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* > @@ -333,7 +341,7 @@ Refresh signs in all windows. ------------------------------------------------------------------------------ *signify-:SignifyFold* > - :SignifyFold + :SignifyFold[!] < Open the current buffer in a new tabpage and set |'foldexpr'| so that only changed lines with their surrounding context are unfolded. @@ -344,6 +352,9 @@ The |foldtext| will be set so that the left side shows the first line in the fold and the right side shows something like "50 [1]" which whereas "50" stands for the number of folded lines and the "1" is the foldlevel. +If [!] is given, Sy will do the same without opening an extra tabpage. Another +":SignifyFold!" will toggle back to the previous settings. + See |folds| to learn more about folding. ------------------------------------------------------------------------------ diff --git a/plugin/signify.vim b/plugin/signify.vim index addae89..8a5440c 100644 --- a/plugin/signify.vim +++ b/plugin/signify.vim @@ -38,13 +38,13 @@ 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 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 -bang SignifyFold call sy#fold#dispatch(1) +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() " Init: mappings {{{1