                         m = mark.find()
                         if m.from.line != m.to.line
                             mark.clear()
-                            @mark_cell_start(line)
+                            @mark_cell_start(cm, line)
                 flagstring = x.slice(37, x.length-1)
                 mark = cm.findMarksAt({line:line, ch:1})[0]
                 # It's possible mark isn't defined above, in case of some weird file corruption (say


            if x[0] == MARKERS.cell
                marks = cm.findMarksAt({line:line, ch:1})
                if marks.length == 0
                    @mark_cell_start(line)
                else
                    first = true
                    for mark in marks

                    )()


    mark_cell_start: (cm, line) =>
        # Assuming the proper text is in the document for a new cell at this line,
        # mark it as such. This hides control codes and places a cell separation
        # element, which may be clicked to create a new cell.
        if line >= cm.lineCount()-1
            # If at bottom, insert blank lines.
            cm.replaceRange("\n\n\n", {line:line+1, ch:0})
