function foldLevel(n, from, to) {
                if (n > 0) {
                    var i = from, range;
                    while (i < to) {
                        range = rf(cm, CodeMirror.Pos(i, 0));
                        if (range) {
                            //call fold level for the range just folded
                            foldLevel(n - 1, range.from.line + 1, range.to.line - 1);
                            cm.foldCode(CodeMirror.Pos(i, 0), null, "fold");
                            i = range.to.line + 1;
                        } else {
                            i++;
                        }
                    }
                }
            }
Folds the specified range. The descendants of any fold regions within the range are also folded up to
a level set globally in the `maxFoldLevel' preferences
@param {CodeMirror} cm the CodeMirror instance
@param {?number} start the line number for the beginning of the region to fold
@param {?number} end the line number for the end of the region to fold