!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}((function(e){"use strict";function r(r){return function(n,t){var i=t.line,o=n.getLine(i);function l(r){for(var l,f=t.ch,u=0;;){var s=f<=0?-1:o.lastIndexOf(r[0],f-1);if(-1!=s){if(1==u&&s<t.ch)break;if(l=n.getTokenTypeAt(e.Pos(i,s+1)),!/^(comment|string)/.test(l))return{ch:s+1,tokenType:l,pair:r};f=s-1}else{if(1==u)break;u=1,f=o.length}}}function f(r){var t,o,l=1,f=n.lastLine(),u=r.ch;e:for(var s=i;s<=f;++s)for(var a=n.getLine(s),c=s==i?u:0;;){var d=a.indexOf(r.pair[0],c),g=a.indexOf(r.pair[1],c);if(d<0&&(d=a.length),g<0&&(g=a.length),(c=Math.min(d,g))==a.length)break;if(n.getTokenTypeAt(e.Pos(s,c+1))==r.tokenType)if(c==d)++l;else if(!--l){t=s,o=c;break e}++c}return null==t||i==t?null:{from:e.Pos(i,u),to:e.Pos(t,o)}}for(var u=[],s=0;s<r.length;s++){var a=l(r[s]);a&&u.push(a)}for(u.sort((function(e,r){return e.ch-r.ch})),s=0;s<u.length;s++){var c=f(u[s]);if(c)return c}return null}}e.registerHelper("fold","brace",r([["{","}"],["[","]"]])),e.registerHelper("fold","brace-paren",r([["{","}"],["[","]"],["(",")"]])),e.registerHelper("fold","import",(function(r,n){function t(n){if(n<r.firstLine()||n>r.lastLine())return null;var t=r.getTokenAt(e.Pos(n,1));if(/\S/.test(t.string)||(t=r.getTokenAt(e.Pos(n,t.end+1))),"keyword"!=t.type||"import"!=t.string)return null;for(var i=n,o=Math.min(r.lastLine(),n+10);i<=o;++i){var l=r.getLine(i).indexOf(";");if(-1!=l)return{startCh:t.end,end:e.Pos(i,l)}}}var i,o=n.line,l=t(o);if(!l||t(o-1)||(i=t(o-2))&&i.end.line==o-1)return null;for(var f=l.end;;){var u=t(f.line+1);if(null==u)break;f=u.end}return{from:r.clipPos(e.Pos(o,l.startCh+1)),to:f}})),e.registerHelper("fold","include",(function(r,n){function t(n){if(n<r.firstLine()||n>r.lastLine())return null;var t=r.getTokenAt(e.Pos(n,1));return/\S/.test(t.string)||(t=r.getTokenAt(e.Pos(n,t.end+1))),"meta"==t.type&&"#include"==t.string.slice(0,8)?t.start+8:void 0}var i=n.line,o=t(i);if(null==o||null!=t(i-1))return null;for(var l=i;null!=t(l+1);)++l;return{from:e.Pos(i,o+1),to:r.clipPos(e.Pos(l))}}))}));