How do I use beautify in Ace Editor?

1.21 gigawatts picture 1.21 gigawatts · Aug 2, 2015 · Viewed 21k times · Source

I've found the beautify extension in Ace editor but I don't see any examples of how to use it. Here's what I have so far:

var beautiful = ace.require("ace/ext/beautify");
beautiful.beautify();

but I get the error:

Result of expression 'e' [undefined] is not an object.

Answer

1.21 gigawatts picture 1.21 gigawatts · Aug 2, 2015

It looks like this works:

var beautify = ace.require("ace/ext/beautify"); // get reference to extension
var editor = ace.edit("editor"); // get reference to editor
beautify.beautify(editor.session);

It requires that you pass in the Ace Editor session as the first parameter. In my original question I did not pass in any variables and that was throwing an error.

Note: It did not work well which were mentioned on the extensions release notes. It was not working well enough to use.