In JupyterLab 3.x and CodeMirror5, I could do

cell.inputArea.editorWidget.editor.setOption('mode', 'python')

to set the codemirror mode for an individual cell.

How can I do the same in JupyterLab 4.x and CodeMirror 6? I see some code like

edit.setOption('lineNumbers', false);

but not anything like `setOption(‘mode’). Should I follow

github.com

jupyterlab/jupyterlab/blob/897418f0f25ffbbee3aa06a62770a53246823f85/packages/codemirror/src/editor.ts#L610-L618

  • private _onMimeTypeChanged(): void {
  • // TODO: should we provide a hook for when the mode is done being set?
  • this._languages
  • .getLanguage(this._model.mimeType)
  • .then(language => {
  • this._editor.dispatch({
  • effects: this._language.reconfigure(language?.support ?? [])
  • // this will trigger a side effect of switching language by updating
  • // private language compartment (implementation detail).
  • editor.model.mimeType = mode;
  • Indeed. If this is just a single boolean as in your example, one could argue that this should be a separate MIME type which could then register its own CodeMirror language support (I think there already should be a JSON mime type though).

    But if you do have a valid use case for a more complex mode customization we should consider exposing the language compartment as previously mentioned (in which case lets move this discussion to GitHub).