Handle folding of nested defs correctly

With the current folding algorithm, a function definition nested at the top of another function causes the whole outer function to be folded in with the nested function. See https://github.com/klen/python-mode/issues/489 for an example. This changeset solves that problem.