There is a function called autoFormatRange
editor.autoFormatRange(range.from, range.to);
This snippet from CodeMirror Group may be what you need:
function autoFormat() { var totalLines = editor.lineCount(); var totalChars = editor.getTextArea().value.length; editor.autoFormatRange({line:0, ch:0}, {line:totalLines, ch:totalChars}); }
http://codemirror.net/2/demo/formatting.html
source share