CodeMirror.extendMode("css",{commentStart:"/*",commentEnd:"*/",newlineAfterToken:function(e,t){return/^[;{}]$/.test(t)}}),CodeMirror.extendMode("javascript",{commentStart:"/*",commentEnd:"*/",newlineAfterToken:function(e,t,n,o){return this.jsonMode?/^[\[,{]$/.test(t)||/^}/.test(n):(";"!=t||!o.lexical||")"!=o.lexical.type)&&(/^[;{}]$/.test(t)&&!/^;/.test(n))}}),CodeMirror.extendMode("xml",{commentStart:"\x3c!--",commentEnd:"--\x3e",newlineAfterToken:function(e,t,n){return"tag"==e&&/>$/.test(t)||/^</.test(n)}}),CodeMirror.defineExtension("commentRange",function(e,t,n){var o=this,r=CodeMirror.innerMode(o.getMode(),o.getTokenAt(t).state).mode;o.operation(function(){if(e)o.replaceRange(r.commentEnd,n),o.replaceRange(r.commentStart,t),t.line==n.line&&t.ch==n.ch&&o.setCursor(t.line,t.ch+r.commentStart.length);else{var i=o.getRange(t,n),a=i.indexOf(r.commentStart),s=i.lastIndexOf(r.commentEnd);a>-1&&s>-1&&s>a&&(i=i.substr(0,a)+i.substring(a+r.commentStart.length,s)+i.substr(s+r.commentEnd.length)),o.replaceRange(i,t,n)}})}),CodeMirror.defineExtension("autoIndentRange",function(e,t){var n=this;this.operation(function(){for(var o=e.line;o<=t.line;o++)n.indentLine(o,"smart")})}),CodeMirror.defineExtension("autoFormatRange",function(e,t){function n(){c+="\n",m=!0,++d}for(var o=this,r=o.getMode(),i=o.getRange(e,t).split("\n"),a=CodeMirror.copyState(r,o.getTokenAt(e).state),s=o.getOption("tabSize"),c="",d=0,m=0==e.ch,l=0;l<i.length;++l){for(var f=new CodeMirror.StringStream(i[l],s);!f.eol();){var g=CodeMirror.innerMode(r,a),u=r.token(f,a),M=f.current();f.start=f.pos,m&&!/\S/.test(M)||(c+=M,m=!1),!m&&g.mode.newlineAfterToken&&g.mode.newlineAfterToken(u,M,f.string.slice(f.pos)||i[l+1]||"",g.state)&&n()}!f.pos&&r.blankLine&&r.blankLine(a),m||n()}o.operation(function(){o.replaceRange(c,e,t);for(var n=e.line+1,r=e.line+d;n<=r;++n)o.indentLine(n,"smart");o.setSelection(e,o.getCursor(!1))})});