9

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.

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
alfredodeza
  • 5,058
  • 4
  • 35
  • 44

1 Answers1

14

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.

Xavier T.
  • 40,509
  • 10
  • 68
  • 97
  • Absolutely correct. Most of the times I marvel at VIM docs (:help foo) but in cases like this - where I'm not sure how to search for it) it sucks. Thanks for the quick response! – alfredodeza Feb 01 '11 at 14:50
  • 1
    @alfredodeza : I am not a Vim script expert, but I got the feeling that most (if not all?) of the syntax and functions are available from `eval.txt`. So in doubt you might want to start looking in that (very long) help file and do a quick search on your problem. That's what I did to answer your question. – Xavier T. Feb 01 '11 at 14:53