Question

I'm writing some folding functions and I am at a point where I need to check if the current line is actually a fold.

The reason for this is because it is a custom fold method that depends on searching/matching certain lines.

For example, if the current line is folded and looks like:

-FOO------------------------

If you do something like:

getline('.')

You would basically get FOO so there is no way (that I know of) to know if I am at a fold or not.

Is there a helper function for this?

I would think it would have to be something like:

is_folded('.')

I could probably mess with the foldtext to assign a special title for the fold but I want to avoid this.

Was it helpful?

Solution

From :help eval.txt

foldclosed({lnum})

The result is a Number. If the line {lnum} is in a closed fold, the result is the number of the first line in that fold. If the line {lnum} is not in a closed fold, -1 is returned.

You can check for a given line if it returns -1 or a line number, you can probably implement your isfolded() function this way.

If you are looking for Vim script function or feature , it is a good idea to start by searching in eval.txt which contains lots of relevant information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top