doc.attachCodeMirror(cm) is the API.