Typically your beautify function would be external to Ace; most editing packages use js-beautify or something else. So the exact answer depends on your specific setup. To implement it:
var selectedText = editor.getCopyText();
var range = editor.selection.getRange();
var beautifiedText = yourBeautifyFunction(selectedText);
editor.getSession().replace(range,beautifiedText);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…