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

customization of folds #28

Open
nnako opened this issue Feb 6, 2020 · 1 comment
Open

customization of folds #28

nnako opened this issue Feb 6, 2020 · 1 comment

Comments

@nnako
Copy link

nnako commented Feb 6, 2020

Hi,

I like this project. Just moved away from simpylfold.

BACKGROUND

I was wondering if something like customization was possible using vim-anyfold. Please have a look at the two pictures attached to this message. The first screenshot shows the editor without folds:

anyfold__customize_folds__01_current

You see four "blocks" of code all preceded with a characteristic form of comment (three hashes in a row and the comment text restricted to the 2nd row, at least for Python code). This specific format is intended to be different from the "normal" line comments, as they kind of are on a different level and relate rather to a block than to a line of code or the inner program structures (for, if,...). Now, I would like to always keep these "block comments" visible, regardless on which indentation level they are written. Folds of this type should start with one of these block comments and end just before the next block comment (or the end of the file / function / ... ). See the next picture for clarification of the outcome:

anyfold__customize_folds__02_goal

This modified screenshot shows the editor scope after applying the fold method on the specifically designed block comments. So, the developer can concentrate on the block comments alone and is free to step into deeper levels of the code as he wishes.

QUESTION

Is there something like a mechanism to specify a language-specific regular expression statement (e.g. ^[\s]*#[\s]*[\r\n]+[\s]*#[\s]*[a-zA-z0-9]+[\s]*[\r\n]+[\s]*#) matching the very specific form of a block comment? So that folds can be realized between these block comments?

HINTS

If there is nothing like this possible at the moment, I would be glad for any developer who could give me some hints where to start implementing this feature myself. I hope, this would be possible starting off with the current code base.

Any Ideas?

Thanks.
Nnako

@pseewald
Copy link
Owner

pseewald commented Feb 7, 2020

I'm glad that you like this project - there is not yet a customization mechanism, but I agree this would be a highly useful feature. Do you want to combine the folds defined by this plugin with your custom folds or do you want to completely override the default folds? Overriding the default folds would be certainly easier and I assume for the moment that this is what you want.

You can implement custom folds by replacing this function. This function is used to store in a list b:anyfold_ind_actual the actual indents for each line. Your new alternative function should increase the list value when a line is encountered that defines a new block (and otherwise reuse the value of the previous line).

For debugging, use let g:anyfold_debug = 1, then you can use F8 to inspect the value of b:anyfold_ind_actual for a specific line.

I hope that my hints are helpful.

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

No branches or pull requests

2 participants