Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to enhance zo to open next level of closed child #6

Open
kiryph opened this issue Apr 16, 2017 · 3 comments
Open

Add option to enhance zo to open next level of closed child #6

kiryph opened this issue Apr 16, 2017 · 3 comments

Comments

@kiryph
Copy link

kiryph commented Apr 16, 2017

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
Copy link
Author

kiryph commented Apr 16, 2017

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
Copy link
Author

kiryph commented Apr 16, 2017

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 kiryph closed this as completed Apr 16, 2017
@arecarn
Copy link
Owner

arecarn commented Apr 18, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants