vim-fold-cycle icon indicating copy to clipboard operation
vim-fold-cycle copied to clipboard

Add option to enhance `zo` to open next level of closed child

Open kiryph opened this issue 8 years ago • 3 comments

I like the built-in behavior of zc to close iteratively current fold, next parent fold and so forth. I would like to have a similar behavior for zo to open the current fold, the next child fold(s) and so forth.

What do you think about this?

kiryph avatar Apr 16 '17 16:04 kiryph

I could resolve this with your plugin as well.

nnoremap <silent><expr> zo foldclosed('.')==-1?
			\ ':execute "normal \<Plug>(fold-cycle-open)"<CR>':
			\ 'zo'

My remaining question is: how can I disable the periodic boundary condition, i.e. if everything is open, simply keep it this way?

P.S: And I have defined a similar command for zc:

nnoremap <silent><expr> zc foldclosed('.')==-1?
			\ ':execute "normal \<Plug>(fold-cycle-close)"<CR>':
			\ 'zc'

kiryph avatar Apr 16 '17 19:04 kiryph

Adding to your plugin the variable g:fold_cycle_enable_cycling

❯ git diff
diff --git a/autoload/fold_cycle.vim b/autoload/fold_cycle.vim
index df182ef..a975f78 100644
--- a/autoload/fold_cycle.vim
+++ b/autoload/fold_cycle.vim
@@ -330,7 +330,7 @@ function! fold_cycle#open() abort "{{{3
         call s:d_msg("opening fold :1")
         foldopen
         return
-    elseif s:max_closed_fold_level == s:fold_level
+    elseif s:max_closed_fold_level == s:fold_level && g:fold_cycle_enable_cycling
         call s:d_msg("closing all folds")
         call s:branch_close_all()
         return
@@ -358,11 +358,11 @@ function! fold_cycle#close() abort "{{{3
         return
     endif
 
-    if s:folded
+    if s:folded && g:fold_cycle_enable_cycling
         call s:d_msg("opening all folds: is folded")
             call s:open_branch()
         return
-    elseif s:max_open_fold_level == 0
+    elseif s:max_open_fold_level == 0 && g:fold_cycle_enable_cycling
         call s:d_msg("opening all folds: s:max_open_fold_level = 0")
             call s:open_branch()
         return
diff --git a/plugin/fold_cycle.vim b/plugin/fold_cycle.vim
index 2dcac4d..215c1ab 100644
--- a/plugin/fold_cycle.vim
+++ b/plugin/fold_cycle.vim
@@ -19,6 +19,7 @@ endif
 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 let g:fold_debug = get(g:, 'fold_cycle_debug', 0)
 let g:fold_cycle_default_mapping = get(g:, 'fold_cycle_default_mapping', 1)
+let g:fold_cycle_enable_cycling = get(g:, 'fold_cycle_enable_cycling', 1)
 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""}}}
 
 " MAPPINGS {{{

and setting its value to zero in my vimrc

" Advanced Recursive/Iterative Folding Commands zo,zc,zO,zC
" Note: use `za` for built-in`zc`
nnoremap <silent><expr> zO foldclosed('.')==-1?
			\ 'zczO':
			\ 'zv'
nnoremap <silent><expr> zC foldclosed('.')==-1?
			\ ':<C-u>call fold_cycle#close_all()<CR>':
			\ 'zC'
nnoremap <silent><expr> zo foldclosed('.')==-1?
			\ ':<C-u>let g:fold_cycle_enable_cycling=0<bar>call fold_cycle#open()<bar>let g:fold_cycle_enable_cycling=1 <CR>':
			\ 'zo'
nnoremap <silent><expr> zc foldclosed('.')==-1?
			\ ':<C-u>call fold_cycle#close()<CR>':
			\ 'zc'

Now all the mappings work as I wanted.

kiryph avatar Apr 16 '17 19:04 kiryph

I don't quite understand this at first glance. I'll leave this open as a reminder to take a look at it in the future

arecarn avatar Apr 18 '17 17:04 arecarn