How to find the currently loaded mode (syntax) in the Ace editor?

Well, as the title says - how do you know if the current loaded mode is in the Ace editor?

editor.getSession (). getMode () does not actually return anything that I can use - I looked at the returned objects but found nothing.

editor.getTheme () returns me a line that I can use - it just seems funny if they didn’t do the same for the mode

+5
source share
2 answers

To get the name of the mode you are using:

editor.getSession().getMode().$id
+5
source

I tried to answer Hugeen and experienced an error undefinedas reported by Lorefnon. This is what worked for me:

// get the editor instance
var editor = ace.edit('editorid');

// get the current mode
var mode = editor.session.$modeId;

// modeid returns the full string (ace/mode/html), cut to the mode name only
mode = mode.substr(mode.lastIndexOf('/') + 1);

Hope this helps someone!

+2
source

All Articles