How to set codemirror mode for individual editor?

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

and do something like editor._language.reconfigure?

2 Likes

This is what I do in jupyterlab-lsp:

I think I would support a pull request which exposes methods allowing to read from and update the language compartment in CodeMirrorEditor.

1 Like

Great! This solves half of the problem, but how can I set “options” to the mode? You know, in CodeMirror 5 mode can be an object like {name: "javascript", json: true}). I think mimetype alone cannot specify these options.

2 Likes

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).

1 Like