Finding end of function

Hi,

I’d like to know if there’s a good way to find the end of a function.

The background is that I’m currently hacking on source code browser. I’d like to display only single functions, I know where they start and wondered if I can use CodeMirror itself to find the line where the functions ends.

I tried it with looping through the lines and getting the information about the indentation with getStateAfter(), but it doesn’t seems to contain enough information to determine whether the end of the function is reached (and of course the indentation might be wrong). Are there better ways?

Cheers,
Volker

Depends entirely on the language. You might be able to use matching braces or so. But of course, code that’s being edited might contain conflicting information (missing braces, odd indentation)

I expect the code to be without syntax errors. I thought already about using the findMatchingBracket() for languages that use brackets to start and end a function body. For Python I can use indentation instead as a valid syntax also means valid indentation.

Thanks for the reply.

I ended up using CodeMirror.fold.auto() from the fold addon.