Splynx
Splynx

Reputation: 823

How do I find currently loaded mode (syntax) in Ace Editor?

Well as the title says - how do I find out what the currently loaded mode is in Ace Editor?

editor.getSession().getMode() does not really return anything I can use - have looked through the objects returned somewhat - but could not find anything.

editor.getTheme() returns a string to me that I can use however - just seems funny if they did not do somewhat the same for mode

Upvotes: 7

Views: 2430

Answers (4)

Matt
Matt

Reputation: 87

In Ace v1.32.7:

mode = editor.getOption('mode')
console.log(mode)

prints

ace/mode/javascript

Upvotes: 0

Danial
Danial

Reputation: 1614

The clean way to get this without any somersaults:

var mode = editor.session.mode;

Upvotes: 0

Ricketts
Ricketts

Reputation: 5213

I tried Hugeen's answer and experienced the undefined error just like lorefnon reported. 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 that helps someone!

Upvotes: 4

Hugeen
Hugeen

Reputation: 1330

To retrieve the name of the mode you use:

editor.getSession().getMode().$id

Upvotes: 8

Related Questions