I think this should be `editor = atom.workspace.getActiveEditor()` instead.