Monday, February 2, 2015

Re: How to preserve manually defined folds when switching to expr within a session?



2015-02-02 21:43 GMT+03:00 Bao Niu <niubao56@gmail.com>:
I use a plugin that uses expr foldmethod. From time to time I want the flexibility to manually define my folds. I just switch to manual by:
setlocal foldmethod=manual
and all those foldlevels calculated by the expr is still there, which is perfect!

However, when later on I want to use that expr mode to fold some newly added content up again, there seems no easy way. If just switch back by:
setlocal foldmethod=expr
I'd lose all my manually defined foldlevels! Is there a way to preserve my manually defined folds when switching back to expr?

I am wondering how you imagine the implemenatation. When you switch expr->manual it can just compute folds once using &foldexpr and save them as if you did add them manually, this is easy. When you switch to expr it is defined to compute folds based on &foldexpr… and &foldexpr neither knows nor should care about your manual folds. What should Vim do if you defined a first level fold on lines 1-6 and &foldexpr computed to a first level fold on lines 3-9?

If you can answer this question you can write your own wrapper command that will

1. save your folds (check out functions with names starting with `fold` in eval.txt);
2. save &foldexpr;
3. set &foldexpr to your function which will do something with &foldexpr output and manual folds saved on the previous step;
4. set &foldmethod.

And a wrapper command which will save expr folds prior to switching expr->manual because Vim does not save information about which fold was defined where, so that the above wrapper can save only *your* folds.
 

Thanks.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment