//> This file is part of Ymacs, an Emacs-like editor for the Web //> http://www.ymacs.org/ //> //> Copyright (c) 2009-2010, Mihai Bazon, Dynarch.com. All rights reserved. //> //> Redistribution and use in source and binary forms, with or without //> modification, are permitted provided that the following conditions are //> met: //> //> * Redistributions of source code must retain the above copyright //> notice, this list of conditions and the following disclaimer. //> //> * Redistributions in binary form must reproduce the above copyright //> notice, this list of conditions and the following disclaimer in //> the documentation and/or other materials provided with the //> distribution. //> //> * Neither the name of Dynarch.com nor the names of its contributors //> may be used to endorse or promote products derived from this //> software without specific prior written permission. //> //> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER “AS IS” AND ANY //> EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE //> IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR //> PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE //> FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR //> CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF //> SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //> INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN //> CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) //> ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF //> THE POSSIBILITY OF SUCH DAMAGE. DEFINE_CLASS("Ymacs",DlLayout,function(a,b,c){a.DEFAULT_EVENTS=["onBufferSwitch","onCreateBuffer","onDeleteBuffer"],a.DEFAULT_ARGS={buffers:["buffers",null],frames:["frames",null],cf_lineNumbers:["lineNumbers",false],_focusable:["focusable",true]},a.FIXARGS=function(a){a.buffers||(a.buffers=[]),a.frames||(a.frames=[])},a.CONSTRUCT=function(){this.buffers.foreach(function(a){a.ymacs=this},this),this.killRing=[],this.killMasterOfRings=[],this.progress={},this.minibuffer=this.createBuffer({hidden:true,isMinibuffer:true}),this.minibuffer.cmd("minibuffer_mode"),this.minibuffer_frame=this.createFrame({isMinibuffer:true,buffer:this.minibuffer,hidden:true,highlightCurrentLine:false,className:"Ymacs_Minibuffer"}),this.buffers.length==0&&this.createBuffer();var a=this.createFrame({buffer:this.buffers[0]});this.packWidget(this.minibuffer_frame,{pos:"bottom"}),this.packWidget(a,{pos:"top",fill:"*"}),this.setActiveFrame(a),a._redrawCaret()},b.pushToKillRing=function(a,b){b?this.killRing.unshift(a):this.killRing.push(a)},b.killRingToMaster=function(){this.killRing.length&&(this.killMasterOfRings.length==0||this.killMasterOfRings.peek().join("")!=this.killRing.join(""))&&this.killMasterOfRings.push(this.killRing),this.killRing=[]},b.killRingText=function(){return this.killRing.join("")},b.rotateKillRing=function(a){a?(this.killMasterOfRings.push(this.killRing),this.killRing=this.killMasterOfRings.shift()):(this.killMasterOfRings.unshift(this.killRing),this.killRing=this.killMasterOfRings.pop())},b.getBuffer=function(a){a instanceof Ymacs_Buffer||(a=this.buffers.grep_first(function(b){return b.name==a}));return a},b.killBuffer=function(a){a=this.getBuffer(a),this.callHooks("onDeleteBuffer",a),this.buffers.length>1?this.getActiveBuffer()===a&&this.switchToNextBuffer():this.switchToBuffer(this.createBuffer()),this.buffers.remove(a),a.destroy()},b.renameBuffer=function(a,b){a=this.getBuffer(a),a.name=b,a.callHooks("onProgressChange")},b._do_switchToBuffer=function(a){this.getActiveFrame().setBuffer(a),this.callHooks("onBufferSwitch",a)},b.switchToBuffer=function(a){var b=this.getBuffer(a),c=this.buffers;b||(b=this.createBuffer({name:a})),c.remove(b),c.unshift(b),this._do_switchToBuffer(b);return b},b.switchToNextBuffer=function(a){var b=this.buffers;if(b.length>1){var c=b.shift();b.push(c),this._do_switchToBuffer(b[0])}},b.switchToPreviousBuffer=function(a){var b=this.buffers;if(b.length>1){var c=b.pop();b.unshift(c),this._do_switchToBuffer(c)}},b.getNextBuffer=function(a,b){b==null&&(b=1);var c=this.buffers;return c[c.rotateIndex(c.find(a)+b)]},b.getPrevBuffer=function(a,b){b==null&&(b=1);var c=this.buffers;return c[c.rotateIndex(c.find(a)-b)]},b.getBufferFrames=function(a){a=this.getBuffer(a);return this.frames.grep(function(b){return b.buffer===a})},b.createBuffer=function(a){a||(a={}),Object.merge(a,{ymacs:this});var b=new Ymacs_Buffer(a);a.hidden||this.buffers.push(b),this.callHooks("onCreateBuffer",b);return b},b.createFrame=function(a){a||(a={}),Object.merge(a,{ymacs:this});var b=new Ymacs_Frame(a);a.hidden||this.frames.unshift(b),b.addEventListener("onDestroy",function(a){this.frames.remove(a)}.$(this,b));return b},b.keepOnlyFrame=function(a){if(this.frames.length>1){var b=a.parent;while(b.parent!=this)b=b.parent;this.replaceWidget(b,a),b.destroy(),this.setActiveFrame(a),this.doLayout()}},b.deleteFrame=function(a){if(this.frames.length>1){var b=a.parent,d=b.children().grep_first(function(b){return b instanceof DlLayout||b instanceof Ymacs_Frame&&b!==a});b.parent.replaceWidget(b,d),b.destroy();try{c.walk(d.getElement(),function(a){if((a=DlWidget.getFromElement(a))&&a instanceof Ymacs_Frame)throw a})}catch(a){if(!(a instanceof Ymacs_Frame))throw a;d=a}this.setActiveFrame(d),this.doLayout()}},b.focusOtherFrame=function(){this.setActiveFrame(this.frames[0])},b.focus=function(){a.BASE.focus.apply(this,arguments),this.frames.peek().focus()},b.setActiveFrame=function(a,b){if(!a.isMinibuffer){var c=this.getActiveFrame();c&&c.delClass("Ymacs_Frame-active"),this.frames.remove(a),this.frames.push(a)}b||a.focus()},b.getActiveFrame=function(){return this.frames.peek()},b.getActiveBuffer=function(){var a=this.getActiveFrame();return a?a.buffer:this.buffers.peek()},b.setColorTheme=function(a){this.delClass(/Ymacs-Theme-[^\s]*/g),a instanceof Array||(a=[a]),a.foreach(function(a){this.addClass("Ymacs-Theme-"+a)},this)},b.getFrameInDirection=function(a,b,d){d||(d=this.getActiveFrame());var e=d.getCaretElement();b||(b=c.getPos(e)),b.sz||(b.sz=c.getOuterSize(e));var f=this.frames.mergeSort(function(a,b){return a.getPos().x-b.getPos().x}),g=this.frames.mergeSort(function(a,b){return a.getPos().y-b.getPos().y});return this["_get_frameInDir_"+a](f,g,b,d)};function d(a,b){if(a.length>0){var c=a.peek().getPos().x,d=[a.pop()];while(a.length>0&&a.peek().getPos().x==c)d.push(a.pop());return d.minElement(function(a){return Math.abs(b.y-a.getPos().y-a.getSize().y/2)})}}function e(a,b){if(a.length>0){var c=a.peek().getPos().y,d=[a.pop()];while(a.length>0&&a.peek().getPos().y==c)d.push(a.pop());return d.minElement(function(a){return Math.abs(b.x-a.getPos().x-a.getSize().x/2)})}}b._get_frameInDir_left=function(a,b,c,e){a=a.grep(function(a){var b=a.getPos(),d=a.getSize();return a!==e&&b.xc.y});return d(a,c)},b._get_frameInDir_right=function(a,b,c,e){a.reverse(),a=a.grep(function(a){var b=a.getPos(),d=a.getSize();return a!==e&&b.x>c.x&&b.y-c.sz.y<=c.y&&b.y+d.y>c.y});return d(a,c)},b._get_frameInDir_up=function(a,b,c,d){b=b.grep(function(a){var b=a.getPos(),e=a.getSize();return a!==d&&b.yc.x});return e(b,c)},b._get_frameInDir_down=function(a,b,c,d){b.reverse(),b=b.grep(function(a){var b=a.getPos(),e=a.getSize();return a!==d&&b.y>c.y&&b.x-c.sz.x<=c.x&&b.x+e.x>c.x});return e(b,c)};function f(){if(!(window.localStorage&&window.localStorage.getItem))throw new Ymacs_Exception("Local storage facility not available in this browser")}b.ls_get=function(){f();return DlJSON.decode(localStorage.getItem(".ymacs")||"{}",true)},b.ls_set=function(a){f(),localStorage.setItem(".ymacs",DlJSON.encode(a))},b.ls_getFileContents=function(a,b){var c=this.ls_getFileDirectory(a),d=c.other,e;d.length==1&&(e=c.dir[d[0]]);if(e==null&&!b)throw new Ymacs_Exception("File not found");return e},b.ls_getFileDirectory=function(a,b){var c,d=c=this.ls_get();a=a.replace(/^[~\x2f]+/,"").split(/\x2f+/);var e=[],f=[];while(a.length>0){var g=a.shift();d.hasOwnProperty(g)&&typeof d[g]!="string"?(d=d[g],e.push(g)):f.push(g)}if(b){var h=b=="file"?1:0;while(f.length>h)d=d[f.shift()]={};this.ls_set(c)}return{store:c,dir:d,path:e,other:f}}}),function(){for(var a={},b=65;b<=90;++b)a[b]=[b,b+32];a[32]=[32,32];var c=[16,17,18,20,144].toHash(true),d=[[49,33],[50,64],[51,35],[52,36],[53,37],[54,94],[55,38],[56,42],[57,40],[48,41]],e=[48,49,50,51,52,53,54,55,56,57].toHash(function(a,b){return d[b]}),f=[[59,58],[61,43],[44,60],[45,95],[46,62],[47,63],[96,126],[91,123],[92,124],[93,125],[39,34]],g=(is_gecko?[59,61,188,109,190,191,192,219,220,221,222]:is_opera?[59,61,44,45,46,47,96,91,92,93,39]:[186,187,188,189,190,191,192,219,220,221,222]).toHash(function(a,b){return f[b]}),h=[37,38,39,40].toHash(true),i=[45,46,36,35,33,34,112,113,114,115,116,117,118,119,120,121,122,123].toHash(true);function j(b,c){var d=a[b]||e[b]||g[b];return d?c?d[1]:d[0]:null}window.KEYBOARD_INSANITY={letters:a,modifiers:c,digits:e,symbols:g,arrows:h,specials:i,getCharCode:j}}(),window.Ymacs_Regexp=function(){var a={};function b(a){a instanceof RegExp&&(a=a.toString());var b=a.lastIndexOf("/"),c="";c=a.substr(b+1),a=a.substring(1,b);return{pattern:a,flags:c}}return{search_backward:function(c){var d=c.toString(),e=a[d];e||(c=b(d),c.flags=c.flags.replace(/g/g,"")+"g",a[d]=e=new RegExp("([^]*)("+c.pattern+")",c.flags)),e.lastIndex=0;return e}}}(),DEFINE_CLASS("Ymacs_Frame",DlContainer,function(a,b,c){var d=300,e=DlException.stopEventBubbling,f=c.createElement("div",null,{className:"line",innerHTML:"
"}),g=225;a.DEFAULT_EVENTS=["onPointChange"],a.DEFAULT_ARGS={highlightCurrentLine:["highlightCurrentLine",true],buffer:["buffer",null],ymacs:["ymacs",null],isMinibuffer:["isMinibuffer",false],_focusable:["focusable",true],_fillParent:["fillParent",true]},a.CONSTRUCT=function(){this.__blinkCaret=this.__blinkCaret.$(this),this.__caretId=Dynarch.ID(),this.redrawModelineWithTimer=this.redrawModeline.clearingTimeout(0,this),this.getElement().innerHTML=h,this.addEventListener({onDestroy:this._on_destroy,onFocus:this._on_focus,onBlur:this._on_blur,onMouseDown:this._on_mouseDown,onKeyDown:this._on_keyDown,onKeyPress:this._on_keyPress,onKeyUp:this._on_keyUp,onResize:this._on_resize}),this._dragSelectCaptures={onMouseOver:e,onMouseOut:e,onMouseEnter:e,onMouseLeave:e,onMouseMove:n.$(this),onMouseUp:o.$(this)},this._bufferEvents={onLineChange:this._on_bufferLineChange.$(this),onInsertLine:this._on_bufferInsertLine.$(this),onDeleteLine:this._on_bufferDeleteLine.$(this),onPointChange:this._on_bufferPointChange.$(this),onResetCode:this._on_bufferResetCode.$(this),onOverwriteMode:this._on_bufferOverwriteMode.$(this),onProgressChange:this._on_bufferProgressChange.$(this),beforeInteractiveCommand:this._on_bufferBeforeInteractiveCommand.$(this),afterInteractiveCommand:this._on_bufferAfterInteractiveCommand.$(this),onOverlayDelete:this._on_bufferOverlayDelete.$(this)},this._moreBufferEvents={onMessage:this._on_bufferMessage.$(this),onOverlayChange:this._on_bufferOverlayChange.$(this),afterInteractiveCommand:this.ensureCaretVisible.$(this)};var a=this.buffer;this.buffer=null,a&&this.setBuffer(a),!this.isMinibuffer&&this.ymacs.cf_lineNumbers&&this.toggleLineNumbers()};var h=String.buffer("
","
","
","
").get();b.focus=function(b){a.BASE.focus.call(this),b instanceof Function&&(this.removeEventListener("onBlur",this.__exitFocusHandler),this.addEventListener("onBlur",this.__exitFocusHandler=function(){b.call(this.buffer)?this.removeEventListener("onBlur",this.__exitFocusHandler):this.focus.delayed(2,this,null)}))},b.blur=function(b){b&&this.removeEventListener("onBlur",this.__exitFocusHandler),a.BASE.blur.call(this)},b.getOverlaysContainer=function(){return this.getElement().firstChild},b.getModelineElement=function(){return this.getElement().childNodes[1]},b.getContentElement=function(){return this.getElement().firstChild.firstChild},b.getCaretElement=function(){return document.getElementById(this.__caretId)},b.getLineDivElement=function(a){return this.getContentElement().childNodes[a]||null},b.ensureCaretVisible=function(){this._redrawCaret();var a=this.getCaretElement();if(a){var b=this.getOverlaysContainer(),c=this.getLineDivElement(this.buffer._rowcol.row),d=c.offsetTop+c.offsetHeight-(b.scrollTop+b.clientHeight);d>0?b.scrollTop+=d:(d=c.offsetTop-b.scrollTop)<0&&(b.scrollTop+=d),(d=a.offsetLeft+a.offsetWidth-(b.scrollLeft+b.clientWidth))>0?b.scrollLeft+=d:(d=a.offsetLeft-b.scrollLeft)<0&&(b.scrollLeft+=d)}},b.setBuffer=function(a){this.buffer&&(this.caretMarker&&!this.isMinibuffer&&(this.caretMarker.destroy(),this.caretMarker=null),this.buffer.removeEventListener(this._bufferEvents),this.buffer.removeEventListener(this._moreBufferEvents)),(this.buffer=a)&&(this.buffer.addEventListener(this._bufferEvents),this.focusInside()&&a.addEventListener(this._moreBufferEvents),this.isMinibuffer?this.caretMarker=a.caretMarker:this.caretMarker=a.createMarker(a.caretMarker.getPosition()),this._redrawBuffer(),this._redrawCaret(true),this.centerOnCaret())},b.centerOnCaret=function(){this.centerOnLine(this.buffer._rowcol.row)},b.centerOnLine=function(a){var b=this.getLineDivElement(a),c=this.getOverlaysContainer();c.scrollTop=Math.round(b.offsetTop-c.clientHeight/2+b.offsetHeight/2)},b.setModelineContent=function(a){this.getModelineElement().innerHTML=a},b.deleteOtherFrames=function(){this.ymacs.keepOnlyFrame(this)},b.deleteFrame=function(){this.ymacs.deleteFrame(this)},b.vsplit=function(a){a==null&&(a="50%");var b=this.parent,c=this.ymacs.createFrame({buffer:this.buffer}),d=new DlLayout,e=new DlResizeBar({widget:this,keepPercent:true,horiz:true,className:"Ymacs-splitbar-horiz"});this._resizeBar&&(this._resizeBar._widget=d),this._resizeBar=e,b.replaceWidget(this,d),d.packWidget(this,{pos:"top",fill:a}),d.packWidget(e,{pos:"top"}),d.packWidget(c,{pos:"top",fill:"*"}),b.__doLayout(),c.centerOnCaret()},b.hsplit=function(a){a==null&&(a="50%");var b=this.parent,c=this.ymacs.createFrame({buffer:this.buffer}),d=new DlLayout,e=new DlResizeBar({widget:this,keepPercent:true,className:"Ymacs-splitbar-vert"});this._resizeBar&&(this._resizeBar._widget=d),this._resizeBar=e,b.replaceWidget(this,d),d.packWidget(this,{pos:"left",fill:a}),d.packWidget(e,{pos:"left"}),d.packWidget(c,{pos:"left",fill:"*"}),b.__doLayout(),c.centerOnCaret()},b.toggleLineNumbers=function(){this.condClass(this.__lineNumbers=!this.__lineNumbers,"Ymacs-line-numbers")};function i(a,b,c){if(/^br$/i.test(a.firstChild.tagName)){a.insertBefore(c,a.firstChild);return c}var d=0,e={};function f(a){for(var g=a.firstChild;g;g=g.nextSibling)if(g.nodeType==3){var h=g.length;if(d+h>b){var i=b-d,j=g.splitText(i);a.insertBefore(c,j);throw e}if(d+h==b){a.insertBefore(c,g.nextSibling);throw e}d+=h}else g.nodeType==1&&f(g)}try{f(a)}catch(a){if(a===e)return c;throw a}}b.setMarkerAtPos=function(a,b){a.tagName||(a=this.getLineDivElement(a));if(a)return i(a,b,c.createElement("span"))},b.__restartBlinking=function(){this.__stopBlinking(),this.focusInside()&&(this.__caretTimer=setTimeout(this.__blinkCaret,2*g))},b.__stopBlinking=function(){clearTimeout(this.__caretTimer),this.__showCaret()},b.__blinkCaret=function(){c.condClass(this.getCaretElement(),this.BLINKING=!this.BLINKING,"Ymacs-caret"),this.__caretTimer=setTimeout(this.__blinkCaret,g)},b.__showCaret=function(){c.addClass(this.getCaretElement(),"Ymacs-caret")},b._unhoverLine=function(){this.__hoverLine!=null&&(c.delClass(this.getLineDivElement(this.__hoverLine),"Ymacs-current-line"),this.__hoverLine=null)},b._redrawCaret=function(a){var b=this.ymacs.getActiveFrame()===this;if(!(!a&&!b)){b&&!this.isMinibuffer&&this.caretMarker.setPosition(this.buffer.caretMarker.getPosition());var d=this.buffer._rowcol;this.highlightCurrentLine&&(this._unhoverLine(),c.addClass(this.getLineDivElement(d.row),"Ymacs-current-line"),this.__hoverLine=d.row),this.__prevCaretLine!=null&&this._on_bufferLineChange(this.__prevCaretLine),this.__prevCaretLine!=d.row&&(this.__prevCaretLine=d.row,this._on_bufferLineChange(d.row)),b&&this.__restartBlinking(),this.callHooks("onPointChange",d.row,d.col),this.redrawModelineWithTimer(d)}},b._getLineHTML=function(a){var b=this.buffer.formatLineHTML(a,this.caretMarker),c=b.indexOf("Ymacs-caret'>");c>=0&&(b=b.substr(0,c+12)+" id='"+this.__caretId+"'"+b.substr(c+12));return b},b._redrawBuffer=function(){this.setContent(this.buffer.code.map(function(a,b){return this._getLineHTML(b).htmlEmbed("div","line")},this).join(""))},b.coordinatesToRowCol=function(a,b){function c(a,d){if(a==d)return a;var f=Math.floor((a+d)/2),g=e.getLineDivElement(f),h=g.offsetTop,i=h+g.offsetHeight-1;if(i");b.line1==b.line2?f("
 
"):(f("
 
"),b.line2-b.line1>1&&f("
"),f("
 
")),f("");return f.get()},b.getOverlaysCount=function(){return this.getOverlaysContainer().childNodes.length-1},b._on_bufferOverlayChange=function(a,b,d){var e=this.getOverlayHTML(a,b);if(e){e=c.createFromHtml(e);var f=this.getOverlaysContainer(),g=!d&&$(this.getOverlayId(a));g?f.replaceChild(e,g):f.appendChild(e)}},b._on_bufferOverlayDelete=function(a,b,d){c.trash($(this.getOverlayId(a)))},b._on_destroy=function(){this.setBuffer(null),this.__stopBlinking()},b._on_focus=function(){window.focus(),this.ymacs.setActiveFrame(this,true),this.addClass("Ymacs_Frame-active"),this.isMinibuffer||this.buffer.cmd("goto_char",this.caretMarker.getPosition()),this.buffer.addEventListener(this._moreBufferEvents),this.__restartBlinking()},b._on_blur=function(){this.isMinibuffer||this.caretMarker.setPosition(this.buffer.caretMarker.getPosition()),this.buffer.removeEventListener(this._moreBufferEvents),this.__stopBlinking()};var j=0,k=null,l=null;function m(){j=null}b._on_mouseDown=function(a){clearTimeout(k),j++,k=m.delayed(d),this.__restartBlinking();var b=a.computePos(this.getContentElement()),c=this.coordinatesToRowCol(b.x,b.y),f=this.buffer;f.clearTransientMark(),f.cmd("goto_char",f._rowColToPosition(c.row,c.col)),f.callInteractively("keyboard_quit"),j==1?(f.ensureTransientMark(),DlEvent.captureGlobals(this._dragSelectCaptures)):j==2?(f.cmd("backward_word"),f.cmd("forward_word_mark")):j==3?(f.cmd("beginning_of_line"),f.cmd("end_of_line_mark")):j==4&&(f.cmd("backward_paragraph"),f.cmd("forward_whitespace"),f.cmd("beginning_of_line"),f.cmd("forward_paragraph_mark")),e()};function n(a){var b=a.computePos(this.getContentElement()),c=this.coordinatesToRowCol(b.x,b.y);this.buffer.cmd("goto_char",this.buffer._rowColToPosition(c.row,c.col)),this.buffer.ensureTransientMark(),this.ensureCaretVisible()}function o(a){DlEvent.releaseGlobals(this._dragSelectCaptures)}b._on_keyDown=function(a){if(!is_gecko){var b=window.KEYBOARD_INSANITY,c=a.keyCode;c in b.modifiers&&e();if((c in b.letters||c in b.digits||c in b.symbols)&&!(a.ctrlKey||a.altKey))return;a.charCode=b.getCharCode(c,a.shiftKey),a.charCode&&(a.keyCode=0),this.buffer._handleKeyEvent(a)&&e()}},b._on_keyPress=function(a){is_gecko||(a.keyCode=0),this.buffer._handleKeyEvent(a)&&e()},b._on_keyUp=function(a){},b._on_resize=function(){this.centerOnCaret.delayed(1,this)}}),DEFINE_CLASS("Ymacs_Message_Popup",DlPopup,function(a,b){a.FIXARGS=function(a){a.autolink=a.focusable=false,a.zIndex=5e3}}),DEFINE_CLASS("Ymacs_Text_Properties",DlEventProxy,function(a,b){a.DEFAULT_EVENTS=["onChange"],a.DEFAULT_ARGS={buffer:["buffer",null]},a.CONSTRUCT=b.reset=function(){this.props=[]},b.insertLine=function(a){this.props.lengthb.length&&c.splice(b.length,c.length)},b.addLineProps=function(a,b,c,d,e){var f=this.props,g,h=false;if(b";if(!d||d.length==0)return b.htmlEscape()}else{if(b=="")return" ";if(!d||d.length==0){if(c===b.length)return b.htmlEscape()+" ";return b.substr(0,c).htmlEscape()+""+b.charAt(c).htmlEscape()+""+b.substr(c+1).htmlEscape()}}var e=0,f=b.length,g=null,h,i="",j;while(e"),i+=""):!h&&g&&(i+=""),g=h;switch(j=b.charAt(e)){case"<":i+="<";break;case">":i+=">";break;case"&":i+="&";break;default:i+=j}++e}g&&(i+=""),e===c&&(i+=" ");return i}});function Ymacs_Exception(a){this.message=a}(function(){window.Ymacs_Interactive=function(a,b){if(arguments.length==1)b=a,a=null;else{var c;b instanceof Function||(c=b,b=arguments[2],b.ymacsDoc=c)}b.ymacsInteractive=true;if(a instanceof Function)b.ymacsGetArgs=a;else if(a!=null){if(!(a instanceof Array)){var d=/^[\^\@\*]+/.exec(a);d&&(d=d[0],a=a.substr(d.length),d.indexOf("^")>=0&&(b.ymacsMarkExtend=true),d.indexOf("*")>=0&&(b.ymacsWarnReadonly=true),d.indexOf("@")>=0&&(b.ymacsSelectFrame=true)),a&&(a=a.split(/\n+/))}if(a){var e,f=function(){e.append(Array.$(arguments));return this.callInteractively(b,e,true)};while(a.length>0)f=A(a.pop(),function(a){e.append(Array.$(arguments,1)),a.call(this)}.$(null,f));b.ymacsCallInteractively=function(){e=[];return f.call(this)}}}return b},window.Ymacs_Interactive_X=function(a){return Ymacs_Interactive("p",function(b){b==null&&(b=1),b.times(a,this)})};var a=function(){};a.toString=function(){return""},a.empty=true;function b(a){var b=this.getPrefixArg(true);b&&(a=b+" "+a),this.cmd("minibuffer_prompt",a)}function c(a,c){b.call(this,a),this.cmd("minibuffer_read_function",c)}function d(a,c){b.call(this,a),this.cmd("minibuffer_read_buffer",c)}function e(a,c){b.call(this,a),this.cmd("minibuffer_read_buffer",c)}function f(a,b){}function g(a,c){b.call(this,a),this.cmd("minibuffer_read_command",c)}function h(a,b){b.call(this,this.point())}function i(a,b){}function j(a,b){b.call(this,null)}function k(a,b){}function l(a,b){}function m(a,b){b.call(this,this.markMarker.getPosition())}function n(a,c){b.call(this,a),this.cmd("minibuffer_read_string",null,c)}function o(a,c){b.call(this,a),this.cmd("minibuffer_read_number",c)}function p(a,b){var c=parseInt(this.getPrefixArg(),10);isNaN(c)?o.call(this,a,b):b.call(this,c)}function q(a,b){var c=parseInt(this.getPrefixArg(),10);isNaN(c)&&(c=null),b.call(this,c)}function r(b,c){(b=this.getPrefixArg())===""&&(b=a),c.call(this,b)}function s(a,b){var c=this.getRegion();b.call(this,c.begin,c.end)}function t(a,b){}function u(a,c){b.call(this,a),this.cmd("minibuffer_read_variable",c)}function v(a,c){b.call(this,a),this.cmd("minibuffer_read_existing_file",c)}function w(a,c){b.call(this,a),this.cmd("minibuffer_read_file",c)}function x(a,c){b.call(this,a),this.cmd("minibuffer_read_file_or_directory",c)}function y(a,c){b.call(this,a),this.cmd("minibuffer_read_directory",c)}var z={a:c,b:d,B:e,c:f,C:g,d:h,e:i,i:j,k:k,K:l,m:m,M:n,n:o,N:p,p:q,P:r,r:s,s:n,U:t,v:u,f:v,F:w,G:x,D:y};function A(a,b){var c=a.charAt(0);a=a.substr(1);return z[c].$(null,a,b)}})(),DEFINE_CLASS("Ymacs_Buffer",DlEventProxy,function(a,b){a.DEFAULT_EVENTS=["onLineChange","onInsertLine","onDeleteLine","onPointChange","onResetCode","onMessage","onOverwriteMode","onOverlayChange","onOverlayDelete","beforeInteractiveCommand","afterInteractiveCommand","beforeRedraw","afterRedraw","finishedEvent","onProgressChange","onTextInsert","onTextDelete"],a.DEFAULT_ARGS={name:["name","*scratch*"],_code:["code",null],ymacs:["ymacs",null],tokenizer:["tokenizer",null],isMinibuffer:["isMinibuffer",false]};var c={case_fold_search:true,line_movement_requested_col:0,fill_column:78,tab_width:8,indent_level:8,syntax_word:{test:g},syntax_word_dabbrev:{test:h},syntax_paragraph_sep:/\n\s*\n/g};function d(a,b){if(typeof a=="string"){b===undefined?delete this[a]:this[a]=b,b instanceof Function&&(b.ymacsCommand=a);return b}var c={};for(var e in a)c[e]=this[e],d.call(this,e,a[e]);return c}var e=5e4;function f(a){return a instanceof Ymacs_Marker?a.getPosition():a}function g(a){if(a){var b=a.charCodeAt(0);return b>=48&&b<=57||a.toUpperCase()!=a.toLowerCase()}}function h(a){if(a){var b=a.charCodeAt(0);return b>=48&&b<=57||a=="_"||a.toUpperCase()!=a.toLowerCase()}}b.lastIndexOfRegexp=function(a,b,c,d){a=a.substring(0,c),b=Ymacs_Regexp.search_backward(b),b.lastIndex=d||0;var e=b.exec(a);if(e){var f=Array.$(e,2);f.index=e.index+e[1].length,f.after=e.index+e[0].length,f[0]=a.substring(f.index,f.after);return this.matchData=f}},a.COMMANDS=b.COMMANDS={},a.newCommands=b.newCommands=function(){return d.apply(this.COMMANDS,arguments)},a.newMode=b.newMode=function(b,c){var d="*"+b+"*",e=d+"hooks";a.setGlobal(e,[]),this.COMMANDS[b]=Ymacs_Interactive("P",function(a){var f=this.getq(d);if(f)a!==true&&(this.getq(e).foreach(function(a){a.call(this,false)},this),f instanceof Function&&f.call(this),this.setq(d,null),this.modes.remove(b));else if(a!==false){var g=c.apply(this,arguments);g instanceof Function||(g=true),this.setq(d,g),this.modes.push(b),this.getq(e).foreach(function(a){a.call(this,true)},this)}return f})},a.addModeHook=b.addModeHook=function(a,b){typeof b=="string"&&(b=this.COMMANDS[b]);var c="*"+a+"*hooks";this.getq(c).pushUnique(b)},a.removeModeHook=b.removeModeHook=function(a,b){typeof b=="string"&&(b=this.COMMANDS[b]);var c="*"+a+"*hooks";this.getq(c).remove(b)},a.FIXARGS=function(a){a.code==null&&(a.code="")},a.CONSTRUCT=function(){this.__undoInProgress=this.__preventUndo=this.__preventUpdates=this.__savingExcursion=0,this.__dirtyLines=[],this.__undoQueue=[],this.__redoQueue=[],this.__overlays={},this.markers=[],this.caretMarker=this.createMarker(0,false,"point"),this.markMarker=this.createMarker(0,true,"mark"),this.matchData=[],this.currentCommand=this.previousCommand=null,this.currentKeys=[],this.progress={},this.variables={},this.globalVariables=c,this.modes=[],this.caretMarker.onChange.push(function(a){this._rowcol=this.caretMarker.getRowCol(),this.__preventUpdates==0&&this.callHooks("onPointChange",this._rowcol,this.point())}),this._tokenizerEvents={onFoundToken:this._on_tokenizerFoundToken.$(this)},this._textProperties=new Ymacs_Text_Properties({buffer:this}),this._textProperties.addEventListener("onChange",this._on_textPropertiesChange.$(this)),this.keymap=[],this.pushKeymap(this.makeDefaultKeymap()),this.setCode(this._code),this._lastCommandWasKill=0,delete this._code},b.withVariables=function(a,b){var c={},d,e;for(d in a)c[d]=this.variables[d],this.variables[d]=a[d];try{return b instanceof Function?b.apply(this,Array.$(arguments,2)):this.cmdApply(b,Array.$(arguments,2))}finally{for(d in c)c[d]===undefined?delete this.variables[d]:this.variables[d]=c[d]}},b.withCommands=function(a,b){var c=this.COMMANDS;this.COMMANDS=Object.makeCopy(c),Object.merge(this.COMMANDS,a);try{return b instanceof Function?b.apply(this,Array.$(arguments,2)):this.cmdApply(b,Array.$(arguments,2))}finally{this.COMMANDS=c}},b.getVariable=function(a){return a in this.variables?this.variables[a]:c[a]},b.setVariable=function(){return d.apply(this.variables,arguments)},a.setq=a.setVariable=a.setGlobal=b.setGlobal=function(){return d.apply(c,arguments)},b.setq=b.setVariable,b.getq=b.getVariable,a.getq=a.getVariable=function(a){return c[a]},b.pushKeymap=function(a){a instanceof Array?a.foreach(this.pushKeymap,this):(this.popKeymap(a),this.keymap.push(a),a.attached(this))},b.popKeymap=function(a){this.keymap.remove(a),a.detached(this)},b.makeDefaultKeymap=function(){return Ymacs_Keymap_Emacs()},b.signalError=function(a,b,c){this.callHooks("onMessage","error",a,b,c)},b.signalInfo=function(a,b,c){this.callHooks("onMessage","info",a,b,c)},b.createMarker=function(a,b,c){a==null&&(a=this.point());return new Ymacs_Marker({editor:this,pos:a,name:c,before:b})},b.point=function(){return this.caretMarker.getPosition()},b.setCode=function(a){this.__code=a,this.__size=a.length,this.__undoQueue=[],this.__redoQueue=[],this.__overlays={},this.markers.map("setPosition",0,true,true),this.code=a.split(/\n/),this._textProperties.reset(),this.tokenizer&&this.tokenizer.reset(),this.callHooks("onResetCode",this.code),this.caretMarker.setPosition(0,false,true),this.markMarker.setPosition(0,true)},b.setTokenizer=function(a){this.tokenizer!=null&&this.tokenizer.removeEventListener(this._tokenizerEvents),(this.tokenizer=a)?a.addEventListener(this._tokenizerEvents):(this._textProperties.reset(),this.callHooks("onResetCode",this.code))},b.getCode=function(){return this.__code||(this.__code=this.code.join("\n"))},b.getCodeSize=function(){if(this.__size)return this.__size;var a=this.code.length,b=a>0?-1:0;while(--a>=0)b+=this.code[a].length+1;return this.__size=b},b.getLine=function(a){a==null&&(a=this._rowcol.row);return this.code[a]},b.charAtRowCol=function(a,b){var c=this.code.length;if(a>=c--)return null;var d=this.code[a];if(b==d.length)return a==c&&d.charAt(b)||"\n";return d.charAt(b)},b.charAt=function(a){a==null?a=this.point():(a=f(a))<0&&(a+=this.point());var b=this._positionToRowCol(a);return this.charAtRowCol(b.row,b.col)},b.callInteractively=function(a,b,c){b||(b=[]);var d;a instanceof Function?d=a.ymacsCommand||null:(d=a,a=this.COMMANDS[a]);if(a.ymacsCallInteractively&&!c)return a.ymacsCallInteractively.apply(this,b);(this.currentCommand=d)!="undo"&&(this.__undoQueue=this.__undoQueue.concat(this.__redoQueue),this.__redoQueue=[]);if(this.previousCommand!=d)this.sameCommandCount(0),d!="undo"&&this._placeUndoBoundary();else if(d!="self_insert_command"||this.sameCommandCount()%20==0)d!="undo"&&this._placeUndoBoundary();this.preventUpdates();try{this.callHooks("beforeInteractiveCommand",d,a),a.ymacsMarkExtend||this.clearTransientMark();return a.apply(this,b)}catch(a){if(a instanceof Ymacs_Exception)this.signalError(a.message);else throw a}finally{this.resumeUpdates(),this.callHooks("afterInteractiveCommand",d,a),this.previousCommand=d,this.sameCommandCount(+1)}},b.resetOverwriteMode=function(a){arguments.length==0&&(a=this.overwriteMode),this.callHooks("onOverwriteMode",this.overwriteMode=!a),this.signalInfo(a?"Insert mode":"Overwrite mode")},b.getMinibuffer=function(){return this.whenYmacs(function(a){return a.minibuffer})},b.getMinibufferFrame=function(){return this.whenYmacs(function(a){return a.minibuffer_frame})},b.setMinibuffer=function(a){this.whenMinibuffer(function(b){b.setCode(a),b.cmd("end_of_buffer")})},b.cmd=function(a){return this.COMMANDS[a].apply(this,Array.$(arguments,1))},b.cmdApply=function(a,b){return this.COMMANDS[a].apply(this,b)},b.createDialog=function(a){a.parent||(a.parent=this.getActiveFrame()&&this.getActiveFrame().getParentDialog(),"noShadows"in a||(a.noShadows=true));var b=new DlDialog(a);this.whenActiveFrame(function(a){b.addEventListener("onDestroy",a.focus.clearingTimeout(0,a))});return b},b.getActiveFrame=function(){return this.whenYmacs("getActiveFrame")},b.when=function(a,b){if((a=this[a]||this.getq(a))!=null)return b instanceof Function?b.call(this,a):a[b].apply(a,Array.$(arguments,2))},b.whenActiveFrame=function(){var a=this.getActiveFrame();if(a.buffer===this){this.activeFrame=a;var b=Array.$(arguments);b.unshift("activeFrame");return this.when.apply(this,b)}this.activeFrame=null},b.forAllFrames=function(a){this.ymacs.getBufferFrames(this).foreach(a)},b.whenYmacs=function(){var a=Array.$(arguments);a.unshift("ymacs");return this.when.apply(this,a)},b.whenMinibuffer=function(a){return this.whenYmacs(function(b){if(b.minibuffer)return a.call(this,b.minibuffer)})},b.preventUpdates=function(){++this.__preventUpdates},b.resumeUpdates=function(){(this.__preventUpdates=Math.max(this.__preventUpdates-1,0))==0&&this.redrawDirtyLines()},b.getRegion=function(a,b){a==null&&(a=this.caretMarker),b==null&&(b=this.markMarker),a=f(a);if((b=f(b))",this.name.htmlEscape()," (",a.row+1,",",a.col,") "),c=[];for(var d in this.progress)c.push(d+": "+this.progress[d]);c.length>0&&b("[",c.join(", "),"]");return b.get()},b._recordChange=function(a,b,c,d){if(c>0){var f=this.__undoQueue;f.push({type:a,pos:b,len:c,text:d}),f.length>e&&f.shift()}},b._placeUndoBoundary=function(a){a=a||this.__undoQueue;var b=this.markers.map(function(a){return[a,a.getPosition()]}),c=a.peek();!c||c.type!=3?a.push({type:3,markers:b}):c.markers=b},b._playbackUndo=function(a){++this.__undoInProgress;var b=false,c;while(a.length>0&&a.peek().type==3)c=a.pop();while(a.length>0){c=a.pop();if(c.type==3){c.markers.foreach(function(a){a[0].setPosition(a[1])});break}b=true;var d=c.pos;switch(c.type){case 1:this._deleteText(d,d+c.len);break;case 2:this._insertText(c.text,d)}}--this.__undoInProgress;return b},b._replaceLine=function(a,b){this.code[a]=b,this._textProperties.replaceLine(a,b),this.__preventUpdates==0?this.callHooks("onLineChange",a):this.__dirtyLines[a]=true},b._deleteLine=function(a){this.code.splice(a,1),this._textProperties.deleteLine(a),this.tokenizer&&this.tokenizer.quickDeleteLine(a),this.__dirtyLines.splice(a,1),this.callHooks("onDeleteLine",a)},b._insertLine=function(a,b){this.code.splice(a,0,b),this._textProperties.insertLine(a),this.tokenizer&&this.tokenizer.quickInsertLine(a);var c=this.__preventUpdates==0;this.callHooks("onInsertLine",a,c),c||(this.__dirtyLines.length<=a?this.__dirtyLines[a]=true:this.__dirtyLines.splice(a,0,true))},b._insertText=function(a,b){if(!(a.length==0)){b==null&&(b=this.caretMarker.getPosition()),b=f(b),this.__preventUndo==0&&this._recordChange(1,b,a.length);var c=b==this.point()?this._rowcol:this._positionToRowCol(b),d=c.row;if(/^\n+$/.test(a)&&c.col==0)a.length.times(function(a){this._insertLine(d+a,"")},this);else{var e=a.split("\n"),g=this.code[d],h=g.substr(c.col);e.length>1?(this._replaceLine(d,g.substr(0,c.col)+e.shift()),e.foreach(function(a){this._insertLine(++d,a)},this),this._replaceLine(d,this.code[d]+h)):this._replaceLine(d,g.substr(0,c.col)+e[0]+g.substr(c.col))}this._updateMarkers(b,a.length),this.callHooks("onTextInsert",b,a)}},b._deleteText=function(a,b){a=this._boundPosition(f(a)),b=this._boundPosition(f(b));if(!(a==b)){if(b0&&b=a)break;a-=e+1,b++}return{row:b,col:a}},b._rowColToPosition=function(a,b){var c=0,d=this.code,e=Math.min(a,d.length-1),f=e;if(e<0)return 0;while(--e>=0)c+=d[e].length+1;return c+Math.min(b,d[f].length)},b._boundPosition=function(a){if(a<0)return 0;return Math.min(a,this.getCodeSize())},b._repositionCaret=function(a){var b=this.caretMarker.getPosition();a==null&&(a=b),a=f(a),a=this._boundPosition(a),this.caretMarker.setPosition(a);return a!=b},b._updateMarkers=function(a,b,c){this.__code=this.__size=null,this.markers.map("editorChange",a,b,c||0),this.tokenizer&&this.tokenizer.quickUpdate(Math.min(a,a+b))},b._saveExcursion=function(a,b){var c=this.createMarker(null,b);++this.__savingExcursion;try{return a.call(this)}finally{--this.__savingExcursion,this.caretMarker.swap(c,false,true),c.destroy()}},b._disableUndo=function(a){++this.__preventUndo;try{return a.call(this)}finally{--this.__preventUndo}},b._handleKeyEvent=function(a){var b=false;this.interactiveEvent(a);var c=this._lastCommandWasKill;this.__nextIsMeta&&(a.altKey=true),this.__nextIsMeta=false;var d=Ymacs_Keymap.unparseKey(a),e=this.currentKeys,f=false;e.push(d),this.keymap.r_foreach(function(a){var c=a.getHandler(e);c instanceof Array?(this.callInteractively(c[0],c[1]),b=true):c?b=f=true:d==="ESCAPE"?b=this.__nextIsMeta=true:a.defaultHandler&&e.length==1&&(b=this.callInteractively(a.defaultHandler[0],a.defaultHandler[1])),b&&$BREAK()},this),f||(b||e.length>1&&(this.signalError(e.join(" ").bold()+" is undefined",true),b=true),e.splice(0,e.length)),this._lastCommandWasKill==c&&typeof b!="object"&&(this._lastCommandWasKill=0),this.callHooks("finishedEvent",b),this.interactiveEvent(null);return b},b._on_tokenizerFoundToken=function(a,b,c,d){d?this._textProperties.addLineProps(a,b,c,"css",d):this._textProperties.removeLineProps(a,b,c,"css")},b._on_textPropertiesChange=function(a){this.__preventUpdates==0?this.callHooks("onLineChange",a):this.__dirtyLines[a]=true},b.formatLineHTML=function(a,b){var c=this._rowcol;b instanceof Ymacs_Marker&&(c=b.getRowCol()),b=a==c.row?c.col:null;return this._textProperties.getLineHTML(a,this.code[a],b)}}),DEFINE_CLASS("Ymacs_Marker",null,function(a,b){a.DEFAULT_ARGS={position:["pos",null],editor:["editor",null],before:["before",false],name:["name",null]},a.CONSTRUCT=function(){this.editor.markers.push(this),this.rowcol=null,this.onChange=[]},b.destroy=function(){this.editor.markers.remove(this),this.editor=null},b.editorChange=function(a,b,c){var d=this.position;this.before&&--d,b!=0&&a<=d&&(this.rowcol=null,this.position+=b,this.position=0;)a[c].call(this.editor,b)},b.getPosition=function(){return this.position},b.setPosition=function(a,b,c){if(c||this.position!=a)this.rowcol=null,this.position=a,b||this.callHooks(this.onChange,this.position)},b.getRowCol=function(){return this.rowcol||(this.rowcol=this.editor._positionToRowCol(this.position))},b.updateMarkers=function(a){this.editor._updateMarkers(this.getPosition(),a)},b.swap=function(a,b,c){var d=this.getPosition();this.setPosition(a.getPosition(),b,c),a.setPosition(d,b,c)}}),Ymacs_Buffer.newCommands({forward_char:Ymacs_Interactive("p",function(a){a==null&&(a=1);return this.cmd("goto_char",this.point()+a)}),backward_char:Ymacs_Interactive("p",function(a){a==null&&(a=1);return this.cmd("forward_char",-a)}),forward_line:Ymacs_Interactive("p",function(a){a==null&&(a=1);var b=this._rowcol;/^(forward|backward)_line$/.test(this.previousCommand)||this.setq("line_movement_requested_col",b.col);var c=this.cmd("goto_char",this._rowColToPosition(b.row+a,Math.max(b.col,this.getq("line_movement_requested_col"))));c||this.setq("line_movement_requested_col",b.col);return c}),backward_line:Ymacs_Interactive("p",function(a){a==null&&(a=1);return this.cmd("forward_line",-a)}),forward_whitespace:Ymacs_Interactive("P",function(a){var b=a?/[^\x20\t\xA0]/g:/[^\s]/g;if(this.cmd("search_forward_regexp",b)){this.cmd("backward_char");return true}if(!a)return this.cmd("end_of_buffer")}),backward_whitespace:Ymacs_Interactive("P",function(a){var b=a?/[^\x20\t\xA0]/g:/[^\s]/g;if(this.cmd("search_backward_regexp",b)){this.cmd("forward_char");return true}if(!a)return this.cmd("beginning_of_buffer")}),beginning_of_line:Ymacs_Interactive(function(){return this.cmd("goto_char",this._rowColToPosition(this._rowcol.row,0))}),back_to_indentation:Ymacs_Interactive(function(){var a=this._rowcol,b=this.code[a.row],c=/\S/.exec(b);if(c)return this.cmd("goto_char",this._rowColToPosition(a.row,c.index))}),beginning_of_indentation_or_line:Ymacs_Interactive(function(){return this.cmd("back_to_indentation")||this.cmd("beginning_of_line")}),end_of_line:Ymacs_Interactive(function(){var a=this._rowcol;return this.cmd("goto_char",this._rowColToPosition(a.row,this.code[a.row].length))}),beginning_of_buffer:Ymacs_Interactive(function(){return this.cmd("goto_char",0)}),end_of_buffer:Ymacs_Interactive(function(){return this.cmd("goto_char",this.getCodeSize())}),eob_p:function(){return this.point()==this.getCodeSize()},bob_p:function(){return this.point()==0},eol_p:function(){var a=this._positionToRowCol(this.point());return a.col==this.code[a.line].length},bol_p:function(){return this._positionToRowCol(this.point()).col==0},backward_delete_char:Ymacs_Interactive("^p",function(a){if(!this.deleteTransientRegion()){a==null&&(a=1);var b=this.point();b>0&&this._deleteText(b-a,b)}}),delete_char:Ymacs_Interactive("^p",function(a){if(!this.deleteTransientRegion()){a==null&&(a=1);var b=this.point();this._deleteText(b,b+a)}}),delete_whitespace:Ymacs_Interactive("^P",function(a){if(!this.deleteTransientRegion()){var b=this.point();if(this.cmd("forward_whitespace",a)){this._deleteText(b,this.point());return true}}}),backward_delete_whitespace:Ymacs_Interactive("^P",function(a){if(!this.deleteTransientRegion()){var b=this.point();if(this.cmd("backward_whitespace",a)){this._deleteText(this.point(),b);return true}}}),universal_argument:Ymacs_Interactive("^",function(){this.pushKeymap(Ymacs_Keymap_UniversalArgument()),this.isMinibuffer||this.setMinibuffer("C-u")}),overwrite_mode:Ymacs_Interactive(function(){this.resetOverwriteMode()}),self_insert_command:Ymacs_Interactive("^p",function(a){var b=this.interactiveEvent(),c=String.fromCharCode(b.charCode),d=this._rowcol;if(b.charCode&&c&&!b.altKey&&!b.ctrlKey){this.deleteTransientRegion(),a!=null&&(c=c.x(a));if(this.overwriteMode){var e=this.code[d.row],f=e.length-d.col;f>0&&this.cmd("delete_char",Math.min(f,a||1))}this.cmd("insert",c);return b.domStop=true}return false}),newline:Ymacs_Interactive("^p",function(a){a==null&&(a=1),this.deleteTransientRegion(),this.cmd("insert","\n".x(a))}),newline_and_indent:Ymacs_Interactive("^p",function(a){a?this.cmd("newline",a):(this.cmd("backward_delete_whitespace",true),this.cmd("newline"),this.cmd("indent_line"))}),indent_line:Ymacs_Interactive("P",function(a){if(this.tokenizer){var b=this.tokenizer.getIndentation(this._rowcol.row,this);if(b!=null){if(!a||/\S/.test(this.getLine())){var c=this.cmd("save_excursion",function(){this.cmd("back_to_indentation"),this._rowcol.col!=b&&(this.cmd("beginning_of_line"),this.cmd("delete_whitespace",true),this.cmd("insert"," ".x(b)));return this.point()});this.point()=0&&(b==null||e<=b)){this.cmd("goto_char",e+a.length);return true}}),search_backward:Ymacs_Interactive("sSearch backward: ",function(a,b){var c=this.getCode(),d=this.point();this.getq("case_fold_search")&&(c=c.toLowerCase(),a=a.toLowerCase());var e=c.lastIndexOf(a,d);e==d&&(e=c.lastIndexOf(a,d-1));if(e>=0&&e!=d&&(b==null||e>=b)){this.cmd("goto_char",e);return true}}),make_regexp:function(a){if(!(a instanceof RegExp)){var b=a.toLowerCase()!=a.toUpperCase();try{a=new RegExp(a,b?"ig":"g")}catch(a){throw new Ymacs_Exception("Invalid regexp")}}return a},search_forward_regexp:Ymacs_Interactive("sRegExp search: ",function(a){a=this.cmd("make_regexp",a);var b=this.getCode(),c=a.lastIndex=this.point(),d=this.matchData=a.exec(b);if(d&&a.lastIndex!=c){d.after=a.lastIndex,this.cmd("goto_char",a.lastIndex);return true}}),search_backward_regexp:Ymacs_Interactive("sBackward RegExp search: ",function(a){a=this.cmd("make_regexp",a);var b=this.lastIndexOfRegexp(this.getCode(),a,this.point());if(b&&b.index!=this.point()){this.cmd("goto_char",b.index);return true}}),forward_word:Ymacs_Interactive_X(function(){var a=this.getq("syntax_word"),b=false;while(!b&&!a.test(this.charAt()))this.cmd("forward_char")||(b=true);while(!b&&a.test(this.charAt()))this.cmd("forward_char")||(b=true)}),backward_word:Ymacs_Interactive_X(function(){var a=this.getq("syntax_word"),b=false;while(!b&&!a.test(this.charAt(-1)))this.cmd("backward_char")||(b=true);while(!b&&a.test(this.charAt(-1)))this.cmd("backward_char")||(b=true)}),forward_paragraph:Ymacs_Interactive_X(function(){this.cmd("forward_whitespace"),this.cmd("search_forward_regexp",this.getq("syntax_paragraph_sep"))?this.cmd("goto_char",this.cmd("match_beginning")+1):this.cmd("end_of_buffer")}),backward_paragraph:Ymacs_Interactive_X(function(){this.cmd("backward_whitespace"),this.cmd("search_backward_regexp",this.getq("syntax_paragraph_sep"))?this.cmd("goto_char",this.cmd("match_end")-1):this.cmd("beginning_of_buffer")}),transpose_words:Ymacs_Interactive_X(function(){this.cmd("backward_char"),this.getq("syntax_word").test(this.charAt())&&this.cmd("forward_word");var a=[];this.cmd("forward_word"),a.push(this.point()),this.cmd("backward_word"),a.push(this.point()),this.cmd("backward_word"),a.push(this.point()),this.cmd("forward_word"),a.push(this.point()),this.cmd("goto_char",this._swapAreas(a))}),transpose_lines:Ymacs_Interactive_X(function(){var a=[];this.cmd("backward_line"),this.cmd("beginning_of_line"),a.push(this.point()),this.cmd("end_of_line"),a.push(this.point()),this.cmd("forward_char"),a.push(this.point()),this.cmd("end_of_line"),a.push(this.point()),this.cmd("goto_char",this._swapAreas(a)+1)}),transpose_chars:Ymacs_Interactive_X(function(){var a=this.point();this.cmd("backward_char")&&this.cmd("goto_char",this._swapAreas([a-1,a,a,a+1]))}),kill_word:Ymacs_Interactive_X(function(){var a=this.point();this.cmd("forward_word");var b=this.point();this._killingAction(a,b,false)}),backward_kill_word:Ymacs_Interactive_X(function(){var a=this.point();this.cmd("backward_word");var b=this.point();this._killingAction(a,b,true)}),_apply_operation_on_word:function(a,b){var c=this.point();if(this.getq("syntax_word").test(this.charAt())){var d=this.cmd("save_excursion",function(){this.cmd("forward_word");return this.point()}),e=a.call(this._bufferSubstring(c,d));this._deleteText(c,d),this._insertText(e)}else this.cmd("forward_word"),this.cmd("backward_word"),c!=this.point()&&this.cmd(b)},capitalize_word:Ymacs_Interactive_X(function(){this.cmd("_apply_operation_on_word",function(){return this.charAt(0).toUpperCase()+this.substr(1).toLowerCase()},"capitalize_word")}),downcase_word:Ymacs_Interactive_X(function(){this.cmd("_apply_operation_on_word",String.prototype.toLowerCase,"downcase_word")}),upcase_word:Ymacs_Interactive_X(function(){this.cmd("_apply_operation_on_word",String.prototype.toUpperCase,"upcase_word")}),goto_char:Ymacs_Interactive("NGoto char: ",function(a){return this._repositionCaret(a)}),goto_line:Ymacs_Interactive("NGoto line: ",function(a){var b=this._rowColToPosition(a-1,0);return this.cmd("goto_char",b)}),move_to_column:Ymacs_Interactive("NMove to column: ",function(a,b){var c=this._positionToRowCol(this.point()),d=this.code[c.row];d.length0&&this.cmd("forward_char");var c="",d=false;this.cmd("looking_at",/\s*([-]|[0-9]+\.|\(?[a-z][\).])?\s+/ig)?(c=" ".x(this.matchData[0].length),d=/\s*[#>;\s]*\s*/g):this.cmd("looking_at",/\s*[#>;*\s]+\s*/g)&&(c=this.matchData[0],d=/\s*[#>;\s]*\s*/g),a&&(this._deleteText(this.point(),this.point()+this.matchData[0].length),c="");while(true){this.cmd("end_of_line"),this.cmd("backward_delete_whitespace");if(this.point()>=b.getPosition())break;this._replaceText(this.point(),this.point()+1," "),d&&this.cmd("looking_at",d)&&this._deleteText(this.point(),this.point()+this.matchData[0].length)}this.cmd("beginning_of_line");while(this.point()b.getPosition()&&this.cmd("goto_char",b),this._rowcol.col>this.getq("fill_column")&&(this.cmd("goto_char",e),this.cmd("backward_delete_whitespace"),this.cmd("newline"),this.cmd("insert",c))}b.destroy(),this.cmd("recenter_top_bottom")})}),fill_paragraph_no_prefix:Ymacs_Interactive(function(){return this.cmd("fill_paragraph",true)}),start_next_paragraph:Ymacs_Interactive(function(){this.cmd("backward_paragraph"),this.point()>0&&this.cmd("forward_char");var a="";this.cmd("looking_at",/(\s*)([0-9]+)(\.\s+)/g)?a=this.matchData[1]+(parseInt(this.matchData[2],10)+1)+this.matchData[3]:this.cmd("looking_at",/(\s*\(?)([a-z])([\.\)]\s+)/ig)?a=this.matchData[1]+String.fromCharCode(this.matchData[2].charCodeAt(0)+1)+this.matchData[3]:this.cmd("looking_at",/\s*[#>;*\s-]+\s*/g)&&(a=this.matchData[0]),this.cmd("forward_paragraph"),this.cmd("eob_p")&&this.cmd("newline"),this.cmd("insert","\n",a),this.cmd("looking_at",/\n\n/g)||(this.cmd("newline"),this.cmd("backward_char"))}),scroll_down:Ymacs_Interactive_X(function(){this.whenActiveFrame(function(a){var b=a.heightInLines();this.cmd("forward_line",Math.round(b/1.33)),this.cmd("recenter_top_bottom")})}),scroll_up:Ymacs_Interactive_X(function(){this.whenActiveFrame(function(a){var b=a.heightInLines();this.cmd("backward_line",Math.round(b/1.33)),this.cmd("recenter_top_bottom")})}),nuke_trailing_whitespace:Ymacs_Interactive(function(){this.cmd("save_excursion",function(){this.cmd("goto_char",0);while(this._rowcol.row0&&this.cmd("forward_line"),this.cmd("save_excursion",function(){this.cmd("end_of_line"),this.cmd("backward_delete_whitespace",true),this.cmd("beginning_of_line"),this.cmd("delete_whitespace",true);var a=this.code[this._rowcol.row],b=Math.floor((this.getq("fill_column")-a.length)/2);this.cmd("insert"," ".x(b))})},this)}),dabbrev_expand:Ymacs_Interactive_X(function(){this.previousCommand!="dabbrev_expand"&&this.setq("dabbrev_context",null);var a=this.getq("dabbrev_context");if(!a){a=this.setq("dabbrev_context",{});var b=this.cmd("save_excursion",function(){this.cmd("bind_variables",{syntax_word:this.getq("syntax_word_dabbrev")},"backward_word");return this.point()});if(b==this.point())return this.signalError("Nothing to expand");a.search=this.cmd("buffer_substring",b,this.point()),a.point=b,a.length=this.point()-b,a.lastSearch=b,a.encountered={},a.forward=false,a.startBuffer=a.buffer=this}var c;a.buffer.cmd("save_excursion",function d(){var b=this.getq("syntax_word_dabbrev"),e,f=false;this.cmd("goto_char",a.lastSearch);if(a.forward){while(this.cmd("search_forward",a.search))if(!b.test(this.charAt(-a.search.length-1))){f=true;break}if(f)a.lastSearch=this.point(),e=this.point()-a.search.length;else{a.buffer=this.whenYmacs("getNextBuffer",this);if(a.buffer===a.startBuffer){c=a.search,a.startBuffer.signalError("No more completions"),a.lastSearch=a.point+a.length,a.startBuffer.setq("dabbrev_context",null);return}a.lastSearch=0,a.buffer.cmd("save_excursion",d);return}}else{while(this.cmd("search_backward",a.search))if(!b.test(this.charAt(-1))){f=true;break}if(f)a.lastSearch=e=this.point(),this.cmd("goto_char",e+a.search.length);else{a.forward=true,a.lastSearch=a.point+a.length,d.call(this);return}}e!=null&&(this.cmd("bind_variables",{syntax_word:this.getq("syntax_word_dabbrev")},"forward_word"),c=this.cmd("buffer_substring",e,this.point()),Object.HOP(a.encountered,c)&&d.call(this))}),c!=null&&(this._replaceText(a.point,a.point+a.length,c),a.length=c.length,a.encountered[c]=true)}),split_frame_vertically:Ymacs_Interactive("p",function(a){a==null?a="50%":a+="%",this.whenActiveFrame("vsplit",a)}),split_frame_horizontally:Ymacs_Interactive("p",function(a){a==null?a="50%":a+="%",this.whenActiveFrame("hsplit",a)}),delete_other_frames:Ymacs_Interactive(function(){this.whenActiveFrame("deleteOtherFrames")}),delete_frame:Ymacs_Interactive(function(){this.whenActiveFrame("deleteFrame")}),other_frame:Ymacs_Interactive(function(){this.whenYmacs("focusOtherFrame")}),windmove:function(a){this.whenYmacs(function(b){var c=b.getFrameInDirection(a);c&&c.focus()})},next_buffer:Ymacs_Interactive(function(){this.whenYmacs("switchToNextBuffer",this.sameCommandCount()+1)}),previous_buffer:Ymacs_Interactive(function(){this.whenYmacs("switchToPreviousBuffer",this.sameCommandCount()+1)}),switch_to_buffer:Ymacs_Interactive("BSwitch to buffer: ",function(a){this.whenYmacs(function(b){b.switchToBuffer(a)})}),kill_buffer:Ymacs_Interactive(function(){this.whenYmacs(function(a){a.killBuffer(this)})}),rename_buffer:Ymacs_Interactive("sRename current buffer to: ",function(a){this.whenYmacs(function(b){b.renameBuffer(this,a)})}),delete_region_or_line:Ymacs_Interactive("^",function(){if(!this.deleteTransientRegion()){this.cmd("beginning_of_line");var a=this.point();if(this.cmd("forward_line")||this.cmd("end_of_line")){this._deleteText(a,this.point());return true}}}),close_last_xml_tag:Ymacs_Interactive_X(function(){var a,b;this.cmd("save_excursion",function(){var b=1;while(b!=0&&this.cmd("search_backward_regexp",/<\x2f?([a-zA-Z0-9:_-]+)/g))a=this.cmd("match_string",1),this.cmd("looking_at",/<\x2f/g)?++b:this.cmd("looking_at",/<[^\x2f][^>]*?\x2f>/g)||--b;b!=0&&(a=null)});if(a)this.cmd("insert","");else throw new Ymacs_Exception("Couldn't find a tag to close")}),bind_variables:function(){return this.withVariables.apply(this,arguments)},for_region:Ymacs_Interactive("^r\nCExecute command within region: ",function(a,b,c){if(b=a.getPosition()&&c<=b.getPosition())return this._repositionCaret(c);throw"YMACS_RESTRICT"}},function(){try{while(true){var d=this.point();c.call(this);if(this.point()==d&&!this.cmd("forward_line"))break}}catch(a){if(a!=="YMACS_RESTRICT")throw a}finally{a.destroy(),b.destroy()}})})}),function(){function a(a,b,c,d){a.cmd("save_excursion",function(){for(var a=this._positionToRowCol(b),e=this._positionToRowCol(c),f=Math.abs(e.col-a.col),g=a.row;g<=e.row;++g){this.cmd("goto_char",this._rowColToPosition(g,0));var h=this.code[g],i=a.col,j=e.col,k=this.point(),l=0;if(i>j){var m=i;i=j,j=m}i>h.length&&(l=i-h.length,i=h.length),j>h.length&&(j=h.length),d.call(this,k+i,k+j,l,f)}},b==a.point())}Ymacs_Buffer.newCommands({string_rectangle:Ymacs_Interactive("r\nsString rectangle: ",function(b,c,d){a(this,b,c,function(a,b,c){c>0?this._insertText(" ".x(c),a):this._deleteText(a,b),this._insertText(d,a+c)})}),kill_rectangle:Ymacs_Interactive("r",function(b,c){var d=[];a(this,b,c,function(a,b,c,e){var f=this._bufferSubstring(a,b);b-a0&&(this.cmd("forward_line")||(this.cmd("end_of_line"),this.cmd("newline")),this.cmd("move_to_column",c,true)),this.cmd("insert",a)},this)},yank_rectangle:Ymacs_Interactive("d",function(a){var b=this.getq("killed_rectangle");if(b==null)throw new Ymacs_Exception("No killed rectangle");this.cmd("insert_rectangle",a,b)})})}(),function(){function a(a,b,c){var d=this.createDialog({title:a,quitBtn:"destroy",modal:true}),e=new DlEntry({parent:d,type:"textarea",fillParent:true,value:b});d._focusedWidget=e,d.setSize({x:350,y:250}),e.addEventListener("onKeyPress",function(a){if(a.keyCode!=DlKeyboard.ESCAPE){var b=e.getValue();d.destroy(),c.delayed(0,this,b)}}.clearingTimeout(0,this)),d.show(true),e.select()}Ymacs_Buffer.newCommands({yank_from_operating_system:Ymacs_Interactive(function(){a.call(this,"Paste below (press CTRL-V)",null,function(a){this._saveKilledText(a),this.cmd("yank"),this.cmd("recenter_top_bottom")})}),copy_for_operating_system:Ymacs_Interactive("r",function(b,c){a.call(this,"Press CTRL-C",this.cmd("buffer_substring"),function(){this.cmd("copy_region_as_kill",b,c)})}),kill_for_operating_system:Ymacs_Interactive("r",function(b,c){a.call(this,"Press CTRL-C or CTRL-X",this.cmd("buffer_substring"),function(){this.cmd("kill_region",b,c)})})})}(),["forward_char","forward_word","forward_line","forward_paragraph","forward_sexp","beginning_of_line","beginning_of_indentation_or_line","beginning_of_buffer","backward_char","backward_word","backward_line","backward_paragraph","backward_sexp","end_of_line","end_of_buffer"].foreach(function(a){Ymacs_Buffer.COMMANDS[a+"_mark"]=Ymacs_Interactive("^",function(){this.ensureTransientMark(),this.cmdApply(a,arguments),this.ensureTransientMark()})}),Ymacs_Buffer.newCommands({get_region:function(){return this.getRegion()},cperl_lineup:Ymacs_Interactive("r",function(a,b){this.cmd("save_excursion",function(){var c=this._positionToRowCol(b),d=0,e=[];this.cmd("goto_char",a),this.cmd("forward_whitespace",true);var f=this.charAt();if(f.toLowerCase()!=f.toUpperCase()){this.signalError("Cannot lineup here");return}while(this._rowcol.row<=c.row){var g=this.getLine().indexOf(f);g>=0&&(g>d&&(d=g),e.push([this._rowcol.row,g]));if(!this.cmd("forward_line"))break}++d,e.foreach(function(a){this.cmd("goto_char",this._rowColToPosition(a[0],a[1])),this.cmd("insert"," ".x(d-a[1]))},this)})}),htmlize_region:Ymacs_Interactive("r\nP",function(a,b,c){this.tokenizer.finishParsing();var d=this._positionToRowCol(a).row,e=String.buffer(),f=d,g;c&&!c.empty&&(f=parseInt(c,10)),b=this._positionToRowCol(b).row,g=String(b).length;while(d<=b)e("
"),c&&e("",f.zeroPad(g," "),""),++f,e(this._textProperties.getLineHTML(d,this.code[d],null),"
\n"),++d;e=e.get();var h=this.ymacs.switchToBuffer("*Htmlize*");h.setCode(e),h.cmd("xml_mode",true)}),execute_extended_command:Ymacs_Interactive("^CM-x ",function(a){this.callInteractively(a)}),set_variable:Ymacs_Interactive("vSet variable: \nsTo value: ",function(a,b){var c=parseFloat(b);isNaN(c)||(b=c),this.setq(a,b)}),eval_string:Ymacs_Interactive("^MEval string: ",function(a){try{var b=[this,this.ymacs];a=new Function("buffer","ymacs",a),a.apply(this,b),this.clearTransientMark()}catch(a){this.signalError(a.type+": "+a.message),window.console&&console.log(a)}}),eval_region:Ymacs_Interactive("^r",function(a,b){this.cmd("eval_string",this.cmd("buffer_substring",a,b))}),eval_buffer:Ymacs_Interactive(function(){this.cmd("eval_string",this.getCode())}),toggle_line_numbers:Ymacs_Interactive("^",function(){this.whenActiveFrame("toggleLineNumbers")}),save_file:Ymacs_Interactive("FWrite file: ",function(a){var b=this.ymacs.ls_getFileDirectory(a,"file");b.dir[b.other[0]]=this.getCode(),this.ymacs.ls_set(b.store),this.signalInfo("Saved in local storage")}),load_file:Ymacs_Interactive("fFind file: ",function(a){var b=this.ymacs.ls_getFileContents(a),c=this.ymacs.createBuffer({name:a});c.setCode(b),this.cmd("switch_to_buffer",a)}),delete_file:Ymacs_Interactive("fDelete file: ",function(a){this.ymacs.ls_getFileContents(a);var b=this.ymacs.ls_get();delete b[a],this.ymacs.ls_set(b)}),eval_file:Ymacs_Interactive("fEval file: ",function(a){this.cmd("eval_string",this.ymacs.ls_getFileContents(a))})}),DEFINE_CLASS("Ymacs_Keymap",null,function(a,b){var c={};Object.foreach(DlKeyboard,function(a,b){typeof a=="number"&&(c[a]=b)}),a.CONSTRUCT=function(){this.definitions=Object.makeCopy(this.__originalDefs)},b.FINISH_OBJECT_DEF=function(){this.__originalDefs={};var a=this.constructor.KEYS;a&&this.defineKeys(a)},b.parseKey=function(a){var b={},c=a.split(/-/);c.reverse(),c.foreach(function(a,d){if(d==0)typeof DlKeyboard[a]=="number"?b.keyCode=DlKeyboard[a]:(c[d]=a.toLowerCase(),b.charCode=c[d].charCodeAt(0));else switch(a){case"C":b.ctrlKey=true;break;case"M":b.metaKey=true;break;case"S":b.shiftKey=true}}),c.reverse();var d=c.pop();b.str=c.sort().join("-"),b.str&&(b.str+="-"),b.str+=d;return b},a.unparseKey=function(a){var b,d=[];a.keyCode in c?b=c[a.keyCode]:a.charCode&&(a.charCode==32?b="SPACE":a.charCode==45?b="DASH":b=String.fromCharCode(a.charCode).toLowerCase()),a.ctrlKey&&d.push("C"),a.altKey&&d.push("M"),a.shiftKey&&(a.charCode&&/^[a-zA-Z0-9]$/.test(b)||a.keyCode)&&d.push("S"),d.sort(),(d=d.join("-"))&&(d+="-");return d+b},b.defineKey=function(a,b,c){b instanceof Array&&(c=b.slice(1),b=b[0]),a=a.trim().split(/\s*&&\s*/);if(a.length>1)a.foreach(function(a){this.defineKey(a,b,c)},this);else{a=a[0].trim();var d=this.definitions||this.__originalDefs;if(a.indexOf(" ")>=0){var e=a.split(/\s+/);a=e.pop(),e.foreach(function(a){a=this.parseKey(a).str,d[a]||(d[a]={}),d=d[a]},this)}a=this.parseKey(a),d[a.str]=[b,c]}},b.defineKeys=function(a){Object.foreach(a,function(a,b){this.defineKey(b,a)},this)},b.getHandler=function(a){var b=null,c=this.definitions;a.foreach(function(a){var d=b?b[a]:c[a];d?(b=d)instanceof Array&&$BREAK():b&&(b=null,$BREAK())});return b},b.attached=Function.noop,b.detached=Function.noop}),DEFINE_SINGLETON("Ymacs_Keymap_Emacs",Ymacs_Keymap,function(a,b){var c=String.template("","","","","","","
Char: $ch
Char code: $code / 0x$codeHex
Position: $point
Mark: $mark
Buffer size: $sizeKB
");a.KEYS={"ARROW_UP && C-p":"backward_line","ARROW_DOWN && C-n":"forward_line","ARROW_LEFT && C-b":"backward_char","ARROW_RIGHT && C-f":"forward_char",HOME:"beginning_of_indentation_or_line","END && C-e":"end_of_line","C-a":"beginning_of_line","C-HOME && M-<":"beginning_of_buffer","C-END && M->":"end_of_buffer","C-ARROW_RIGHT && M-f":"forward_word","C-ARROW_LEFT && M-b":"backward_word","C-ARROW_DOWN":"forward_paragraph","C-ARROW_UP":"backward_paragraph","C-l":"recenter_top_bottom","PAGE_UP && M-v":"scroll_up","PAGE_DOWN && C-v":"scroll_down","S-ARROW_UP && S-C-p":"backward_line_mark","S-ARROW_DOWN && S-C-n":"forward_line_mark","S-ARROW_LEFT && S-C-b":"backward_char_mark","S-ARROW_RIGHT && S-C-f":"forward_char_mark","S-C-ARROW_RIGHT && S-M-f":"forward_word_mark","S-C-ARROW_LEFT && S-M-b":"backward_word_mark","S-C-ARROW_DOWN":"forward_paragraph_mark","S-C-ARROW_UP":"backward_paragraph_mark","S-HOME":"beginning_of_indentation_or_line_mark","S-C-a":"beginning_of_line_mark","S-END":"end_of_line_mark","S-C-HOME":"beginning_of_buffer_mark","S-C-END":"end_of_buffer_mark",BACKSPACE:"backward_delete_char","DELETE && C-d":"delete_char","ENTER && C-m":"newline","M-d && C-DELETE":"kill_word","C-BACKSPACE && M-BACKSPACE && M-DELETE":"backward_kill_word","C-k":"kill_line","C-y && S-INSERT":"yank","M-y":"yank_pop","C-SPACE":"set_mark_command","C-x C-x":"exchange_point_and_mark","C-w":"kill_region","M-t":"transpose_words","C-t":"transpose_chars","C-x C-t":"transpose_lines","M-w":"copy_region_as_kill","M-c":"capitalize_word","M-u":"upcase_word","M-l":"downcase_word",F11:"nuke_trailing_whitespace",TAB:"indent_line","C-M-\\":"indent_region","M-q":"fill_paragraph","C-/ && C-x u && C-_ && C-z":"undo",INSERT:"overwrite_mode","M-s":"center_line","M-/":"dabbrev_expand","C-s":"isearch_forward","C-r":"isearch_backward","M-C-s":"isearch_forward_regexp","M-C-r":"isearch_backward_regexp","C-u":"universal_argument","M-g":"goto_line","C-x h":"mark_whole_buffer","C-g":"keyboard_quit","C-x r t":"string_rectangle","C-x r c":"clear_rectangle","C-x r k":"kill_rectangle","C-x r y":"yank_rectangle","C-x C-ARROW_RIGHT && C-x ARROW_RIGHT && C-TAB":"next_buffer","C-x C-ARROW_LEFT && C-x ARROW_LEFT && C-S-TAB":"previous_buffer","C-x b":"switch_to_buffer","C-x k":"kill_buffer","C-x 0":"delete_frame","C-x 1":"delete_other_frames","C-x 2":"split_frame_vertically","C-x 3":"split_frame_horizontally","C-x o":"other_frame","C-x l":"toggle_line_numbers","M-x":"execute_extended_command","C-S-y":"yank_from_operating_system","M-S-w":"copy_for_operating_system","C-S-w":"kill_for_operating_system","M-S-y":"yank_shift","C-c /":"close_last_xml_tag","S-BACKSPACE":"backward_delete_whitespace","S-DELETE":"delete_whitespace","C-M-d":"delete_region_or_line","M-ENTER":"start_next_paragraph","M-S-q":"fill_paragraph_no_prefix","C-M-|":"cperl_lineup","C-F4":"kill_buffer","M-ARROW_LEFT":["windmove","left"],"M-ARROW_RIGHT":["windmove","right"],"M-ARROW_UP":["windmove","up"],"M-ARROW_DOWN":["windmove","down"],"C-x =":function(){var a=this.charAt(),b=a;a==" "?b="":a=="\n"?b="":a=="-"&&(b=""),this.signalInfo(c({ch:b.htmlEscape(),code:a.charCodeAt(0),codeHex:a.charCodeAt().hex(),point:this.point(),mark:this.markMarker.getPosition(),size:this.getCodeSize(),sizeKB:this.getCodeSize().formatBytes(2)}),true)}},b.defaultHandler=["self_insert_command"]}),DEFINE_SINGLETON("Ymacs_Keymap_UniversalArgument",Ymacs_Keymap,function(a,b){b.defaultHandler=[Ymacs_Interactive("^",function(){var a=this.interactiveEvent(),b=String.fromCharCode(a.charCode),c=this.getPrefixArg(true);if(a.charCode&&(/^[0-9]$/.test(b)||b==="-"&&c==="")&&!a.altKey&&!a.ctrlKey){c+=b,this.setPrefixArg(c),this.isMinibuffer||this.whenMinibuffer(function(a){a.cmd("insert"," ",b)});return true}this.popKeymap(Ymacs_Keymap_UniversalArgument());return false})],b.attached=function(a){a.setPrefixArg("")}}),DEFINE_SINGLETON("Ymacs_Keymap_ISearch",Ymacs_Keymap,function(a,b){a.KEYS={"C-g && ESCAPE":["isearch_abort",true],"C-w":"isearch_yank_word_or_char","C-s":"isearch_forward","C-r":"isearch_backward",BACKSPACE:function(){this.getMinibuffer().point()>this._isearchContext.mbMark.getPosition()&&(this.getMinibuffer().cmd("backward_delete_char"),this.cmd("goto_char",this._isearchContext.point),d.call(this,this._isearchContext.forward))},ENTER:"isearch_abort"},a.CONSTRUCT=function(){this.defaultHandler=["isearch_printing_char"]};function c(a){if(!this._isearchContext){this.pushKeymap(Ymacs_Keymap_ISearch()),this.cmd("set_mark_command",this.point()),this.setMinibuffer(a?"I-Search: ":"I-Search backward: "),this._isearchContext={forward:a,point:this.point(),mbMark:this.getMinibuffer().createMarker(null,true)};return true}}function d(a){this._isearchContext.forward=a,this._isearchContext.point=this.point();var b=f(this);!/\S/.test(b)&&this._isearchLastText&&(this.getMinibuffer()._placeUndoBoundary(),this.getMinibuffer().cmd("insert",this._isearchLastText),b=this._isearchLastText);return e.call(this,b)}function e(a){a==null&&(a=f(this));var b=this.cmd("bind_variables",{case_fold_search:a==a.toLowerCase()},this.cmd,this._isearchContext.forward?"search_forward":"search_backward",a);if(b){this.cmd("ensure_caret_visible");var c=this._positionToRowCol(this.point()+(this._isearchContext.forward?-1:1)*a.length);this.setOverlay("isearch",{line1:c.row,line2:this._rowcol.row,col1:c.col,col2:this._rowcol.col})}return b}function f(a){return a.cmd("isearch_get_search_text")}Ymacs_Buffer.newCommands({isearch_get_search_text:Ymacs_Interactive(function(){if(this._isearchContext)return this.getMinibuffer()._bufferSubstring(this._isearchContext.mbMark)}),isearch_forward:Ymacs_Interactive(function(){c.call(this,true)||(d.call(this,true)||this.signalError("No more forward occurrences of the search text"))}),isearch_forward_regexp:Ymacs_Interactive(function(){this.signalError("Not implemented, but should be easy. Volunteers?")}),isearch_backward_regexp:Ymacs_Interactive(function(){this.signalError("Not implemented, but should be easy. Volunteers?")}),isearch_backward:Ymacs_Interactive(function(){c.call(this,false)||(d.call(this,false)||this.signalError("No more backward occurrences of the search text"))}),isearch_yank_word_or_char:Ymacs_Interactive(function(){var a=this.point(),b=this.cmd("save_excursion",function(){this.cmd("forward_word");return this.point()});if(b!=a){var c=this._bufferSubstring(a,b);this.getMinibuffer()._placeUndoBoundary(),this.getMinibuffer().cmd("insert",c.toLowerCase()),c=f(this),this._isearchContext.forward&&this.cmd("goto_char",b-c.length),e.call(this,c)}}),isearch_printing_char:Ymacs_Interactive(function(){var a=this.interactiveEvent();if(a.charCode&&!a.ctrlKey&&!a.altKey){this.getMinibuffer().cmd("self_insert_command"),this.cmd("goto_char",this._isearchContext.point),e.call(this,f(this));return a.domStop=true}if(a.keyCode!=0||a.ctrlKey||a.altKey){this.cmd("isearch_abort");return false}}),isearch_abort:Ymacs_Interactive(function(a){a||(this._isearchLastText=f(this)),this.setMinibuffer(""),this.popKeymap(Ymacs_Keymap_ISearch()),this._isearchContext.mbMark.destroy(),this._isearchContext=null,a&&this.cmd("exchange_point_and_mark"),this.deleteOverlay("isearch"),this.deleteOverlay("isearch-lazy");return true})})}),Ymacs_Buffer.newMode("minibuffer_mode",function(){var a=this.createMarker(0,true),b=this.setq({minibuffer_end_marker:a}),c=Ymacs_Keymap_Minibuffer();this.pushKeymap(c);return function(){this.setq(b),a.destroy(),this.popKeymap(c)}}),function(){var a=false,b=null,c=null;function d(d,e){b&&b.destroy(),b=new DlVMenu({}),e.foreach(function(a){var c=a;typeof a!="string"&&(c=a.completion,a=a.label),new DlMenuItem({parent:b,label:a.htmlEscape(),data:c})});var f=Ymacs_Completion_Popup.get();f.popup({timeout:0,content:b,align:{prefer:"Tr",fallX1:"_r",fallX2:"_L",fallY1:"B_",fallY2:"T_"},anchor:d.getCaretElement(),widget:d,onHide:function(){a=false,b=c=null},isContext:true}),a=true}function e(a,b,c){this.whenMinibuffer(function(d){var e=d.setq({completion_list:a,minibuffer_validation:function(a){a==null&&(a=d.cmd("minibuffer_contents"));if(c)return c.call(this,d,a);return true}.$(this),minibuffer_continuation:function(a){d.setq(e),b&&b.call(this,a)}.$(this)})})}function f(a,b){var c=this.ymacs.ls_getFileDirectory(b),e=c.dir,f=c.other,g=c.path,h=f[0];if(f.length!=1)throw new Ymacs_Exception("Not found");if(typeof e[h]=="string")return[g.concat([h]).join("/")];var i=[];for(var j in e)j.indexOf(h)==0&&i.push(j);var k=i.common_prefix();if(k!=h)i.length==1&&typeof e[k]!="string"&&(k+="/"),a.cmd("minibuffer_replace_input",g.concat([k]).join("/"));else{if(i.length==1)throw new Ymacs_Exception("Single completion");if(i.length==0)throw new Ymacs_Exception("No completions");i=i.map(function(a){typeof e[a]!="string"&&(a+="/");return{label:a,completion:g.concat([a]).join("/")}}),d(this.getMinibufferFrame(),i)}return null}Ymacs_Buffer.newCommands({minibuffer_prompt:function(a,b){this.whenMinibuffer(function(c){var d=this.getMinibufferFrame();c.setCode(""),c.cmd("prevent_undo",function(){c.cmd("insert",a)}),c.getq("minibuffer_end_marker").setPosition(c.point()),d._redrawCaret(true),b||d.focus()})},minibuffer_read_number:function(a){e.call(this,null,a,function(a,b){var c=parseInt(b,10);isNaN(c)&&a.signalError("Please enter a number");return!isNaN(c)})},minibuffer_read_command:function(a){var b=Array.hashKeys(this.COMMANDS).grep(function(a){return this.COMMANDS[a].ymacsInteractive},this).sort();e.call(this,b,a,function(a,b){var c=this.COMMANDS[b],d=c&&c.ymacsInteractive;d||a.signalError("No such command: "+b);return d})},minibuffer_read_function:function(a){var b=Array.hashKeys(this.COMMANDS).sort();e.call(this,b,a,function(a,b){var c=this.COMMANDS[b],d=!!c;d||a.signalError("No such function: "+b);return d})},minibuffer_read_buffer:function(a){this.whenYmacs(function(b){var c=b.buffers.map("name");c.push(c.shift()),e.call(this,c,a),k.call(this)})},minibuffer_read_string:function(a,b){e.call(this,a,b)},minibuffer_read_variable:function(a){var b=this.globalVariables;Object.merge(b,this.variables);var c=Array.hashKeys(b).grep(function(a){return!/^\*/.test(a)}).sort();e.call(this,c,a)},minibuffer_read_existing_file:function(a){var b=this.ymacs.ls_getFileDirectory(this.name).path.join("/");b&&(b+="/"),this.cmd("minibuffer_replace_input",b),e.call(this,f,a,function(a,b){var c=this.ymacs.ls_getFileContents(b,true);c||a.signalError("No such file: "+b);return c})},minibuffer_read_file:function(a){var b=this.ymacs.ls_getFileDirectory(this.name).path.join("/");b&&(b+="/"),e.call(this,f,a)},minibuffer_read_file_or_directory:function(a){var b=this.ymacs.ls_getFileDirectory(this.name).path.join("/");b&&(b+="/"),e.call(this,f,a)},minibuffer_read_directory:function(a){var b=this.ymacs.ls_getFileDirectory(this.name).path.join("/");b&&(b+="/"),e.call(this,f,a)},minibuffer_prompt_end:function(){return this.whenMinibuffer(function(a){return a.getq("minibuffer_end_marker").getPosition()})},minibuffer_contents:function(){return this.whenMinibuffer(function(a){return a._bufferSubstring(a.getq("minibuffer_end_marker"))})},minibuffer_replace_input:function(a){this.whenMinibuffer(function(b){b._replaceText(b.getq("minibuffer_end_marker"),b.getCodeSize(),a),this.getMinibufferFrame()._redrawCaret(true)})},minibuffer_complete:function(){this.whenMinibuffer(function(a){var b=a.getq("completion_list"),c=a.cmd("minibuffer_contents"),e=c.replace(/([\[\]\(\)\{\}\.\*\+\?\|\\])/g,"\\$1").replace(/([_-])/g,"[^_-]*[_-]");e=new RegExp("^"+e,"i");if(b instanceof Function){b=b.call(this,a,c,e);if(!b)return}else b&&b.length>0&&(b=b.grep(function(a){return e.test(a)}));if(!b||b.length==0)a.signalError("No completions");else{var f=b.common_prefix();f!=c?a.cmd("minibuffer_replace_input",f):b.length==1?a.signalError("Sole completion"):d(this.getMinibufferFrame(),b)}})},minibuffer_complete_and_exit:function(){this.whenMinibuffer(function(a){a.getq("minibuffer_validation").call(a)&&a.cmd("minibuffer_keyboard_quit",this.getq("minibuffer_continuation"))})},minibuffer_keyboard_quit:function(a){this.whenMinibuffer(function(b){var c=this.cmd("minibuffer_contents");b.setCode(""),this.ymacs.getActiveFrame().focus(),function(b){a&&a.call(this,b),this.getPrefixArg()}.delayed(1,this,c)}),DlPopup.clearAllPopups()}});function g(a){var d=c,e;switch(a){case"next":c==null&&(c=-1),c=b.children().rotateIndex(++c);break;case"prev":c==null&&(c=0),c=b.children().rotateIndex(--c)}d!=null&&(e=b.children(d),e.callHooks("onMouseLeave")),d=c,e=b.children(c),e.callHooks("onMouseEnter")}function h(){if(a)return g.call(this,"next")}function i(){if(a)return g.call(this,"prev")}function j(){a?c!=null?(this.cmd("minibuffer_replace_input",b.children()[c].userData),DlPopup.clearAllPopups()):this.signalError("Select something..."):this.cmd("minibuffer_complete_and_exit")}function k(){a||this.cmd("minibuffer_complete"),h.call(this)}function l(){i.call(this)}function m(){a?DlPopup.clearAllPopups():this.cmd("minibuffer_keyboard_quit")}DEFINE_SINGLETON("Ymacs_Keymap_Minibuffer",Ymacs_Keymap,function(a,b){a.KEYS={"C-g":"minibuffer_keyboard_quit",TAB:k,"S-TAB":l,ARROW_DOWN:h,ARROW_UP:i,ENTER:j,ESCAPE:m},b.defaultHandler=[function(){DlPopup.clearAllPopups();return false}]})}(),DEFINE_CLASS("Ymacs_Completion_Popup",DlCompletionPopup),DEFINE_CLASS("Ymacs_Stream",null,function(a,b){a.DEFAULT_ARGS={buffer:["buffer",null],line:["line",0],col:["col",0]},b.nextCol=function(){++this.col},b.prevCol=function(){--this.col},b.nextLine=function(){++this.line,this.col=0},b.prevLine=function(){--this.line,this.col=0},b.peek=function(a){a==null&&(a=0);return this.buffer.code[this.line].charAt(this.col+a)},b.get=function(){var a=this.peek();this.nextCol();return a},b.lineText=function(a){a==null&&(a=this.line);return this.buffer.code[a]},b.lineIndentation=function(a){return/^\s*/.exec(this.lineText(a))[0].length},b.lookingAt=function(a){var b=this.buffer.code[this.line];return a instanceof RegExp?a.exec(b.substr(this.col)):b.substr(this.col,a.length)==a},b.textBefore=function(a){a==null&&(a=this.buffer._rowColToPosition(this.line,this.col));return this.buffer.getCode().substr(0,a)},b.textAfter=function(a){a==null&&(a=this.buffer._rowColToPosition(this.line,this.col));return this.buffer.getCode().substr(a)},b.substring=function(a,b){return this.buffer.getCode().substring(a,b)},b.substr=function(a,b){return this.buffer.getCode().substr(a,b)},b.eol=function(){return this.col==this.buffer.code[this.line].length},b.eof=function(){var a=this.buffer.code.length,b=this.line;return b>=a||b==a-1&&this.eol()},b.length=function(){return this.buffer.code.length},b.lineLength=function(a){a==null&&(a=this.line);return this.buffer.code[a].length},b.save=function(){return{buffer:this.buffer,line:this.line,col:this.col}},b.restore=function(a){this.buffer=a.buffer,this.line=a.line,this.col=a.col},b.checkStop=function(){if(this.eof())throw this.EOF;if(this.eol())throw this.EOL},b.EOL=new function(){},b.EOF=new function(){}}),DEFINE_CLASS("Ymacs_Tokenizer",DlEventProxy,function(a,b){var c={};a.define=function(a,b){c[a.toLowerCase()]=b},a.DEFAULT_EVENTS=["onFoundToken"],a.DEFAULT_ARGS={buffer:["buffer",null],type:["type",null]},a.FIXARGS=function(a){typeof a.type=="string"&&(a.type=c[a.type.toLowerCase()])},a.CONSTRUCT=function(){var a=null,b=null;this.quickUpdate=function(c){var d=this.buffer._positionToRowCol(c).row;this.parsers.splice(d-1,this.parsers.length+1),a!=null?a=Math.min(d,a):a=d,clearTimeout(b),b=function(){this._do_quickUpdate(a),a=null}.delayed(1,this)},this._stopQuickUpdate=function(){clearTimeout(b),clearTimeout(this.timerUpdate)},this.reset()},b.reset=function(){this.stream=new Ymacs_Stream({buffer:this.buffer}),this.theParser=this.type(this.stream,this),this.parsers=[],this.parsers[-1]=this.theParser.copy(),this.timerUpdate=null,this.quickUpdate(0)},b.getLanguage=function(a){return c[a](this.stream,this)},b.showProgress=function(a){a!=null&&(a=Math.round(a/this.stream.length()*100)+"%"),this.buffer.updateProgress("Syntax highlighting",a)},b._do_quickUpdate=function(a){this._stopQuickUpdate();var b=this.stream,c,d=this.parsers,e;b.line=a-1;while(!(c=d[b.line]))b.prevLine();b.nextLine(),c=c();var f=0,g=true,h=function(){this.buffer.preventUpdates(),e=g?3:20,++f>10&&this.showProgress(this.stream.line);while(true)try{while(true)c.next()}catch(a){if(a===b.EOL){d[b.line]=c.copy(),b.nextLine();if(--e==0){this.buffer.resumeUpdates(),this.timerUpdate=setTimeout(h,g?500:50),g=false;return}}else{if(a===b.EOF){d[b.line]=c.copy(),this.buffer.resumeUpdates(),c.on_EOF&&c.on_EOF();break}throw a}}this.showProgress()}.$(this);h()},b.quickInsertLine=function(a){this.parsers.splice(a,this.parsers.length+1)},b.quickDeleteLine=function(a){this.parsers.splice(a,this.parsers.length+1)},b.onToken=function(a,b,c,d){this.callHooks("onFoundToken",a,b,c,d)},b.getParserForLine=function(a){this._stopQuickUpdate();var b=this.stream,c,d=this.parsers,e,f=b.line;b.line=a-1;while(!(c=d[b.line]))b.prevLine();b.nextLine(),c=c();try{this.buffer.preventUpdates();while(true){if(b.line==a)return c;try{while(true)c.next()}catch(a){if(a===b.EOL)d[b.line]=c.copy(),b.nextLine();else{if(a===b.EOF)break;throw a}}}}finally{this.buffer.resumeUpdates(),b.lineb.line?1:a.col-b.col}var d={"(":")","[":"]","{":"}","\"":{close:"\"",backslash:/[\x22\\]/g},"'":{close:"'",backslash:/[\x27\\]/g}};function e(a){throw new Ymacs_Exception("Balanced expression not found")}function f(a){var b=a.context.passedParens;return b instanceof Function?b():b}Ymacs_Buffer.newCommands({matching_paren:function(){var a=this.tokenizer.getLastParser(),b=this._rowcol;if(a){var c=f(a);return c.foreach(function(a){var c=a.closed;a.line==b.row&&a.col==b.col?$RETURN(this._rowColToPosition(c.line,c.col+1)):c.line==b.row&&c.col==b.col-1&&$RETURN(this._rowColToPosition(a.line,a.col))},this)}},indent_sexp:Ymacs_Interactive(function(){var a=this.cmd("matching_paren");a!=null?this.cmd("indent_region",this.point(),a):e(this)}),goto_matching_paren:Ymacs_Interactive(function(){var a=this.cmd("matching_paren");if(a!=null){this.cmd("goto_char",a);return true}}),forward_sexp:Ymacs_Interactive(function(){var a=this._rowcol,b=this.tokenizer.finishParsing();if(b){var d=f(b).mergeSort(c),g=d.foreach(function(b){(b.line>a.row||b.line==a.row&&b.col>=a.col)&&$RETURN(b)});if(!g||!g.closed){e(this);return}var h=this._rowColToPosition(g.line,g.col);this._rowcol.row==g.line&&this._rowcol.col==g.col||!/\S/.test(this._bufferSubstring(null,h))?this.cmd("goto_char",this._rowColToPosition(g.closed.line,g.closed.col)+1):this.cmd("goto_char",h);return true}}),backward_sexp:Ymacs_Interactive(function(){var a=this._rowcol,b=this.tokenizer.finishParsing();if(b){var d=f(b).grep("closed").map("closed").mergeSort(c),g=d.r_foreach(function(b){(b.line=0}),b!=null?this.cmd("goto_char",this._rowColToPosition(b.line,b.col)+1):e(this)}}),backward_up_list:Ymacs_Interactive(function(){var a=this._rowcol,b=this.tokenizer.finishParsing();if(b){var d={line:a.row,col:a.col};b=f(b).grep("closed").mergeSort(c).grep_last(function(a){return c(a,d)<0&&c(a.closed,d)>=0}),b!=null?this.cmd("goto_char",this._rowColToPosition(b.line,b.col)):e(this)}}),up_list:Ymacs_Interactive(function(){this.cmd("backward_up_list"),this.cmd("forward_sexp")})}),Ymacs_Buffer.newMode("paren_match_mode",function(){var a=Ymacs_Keymap_ParenMatch();this.pushKeymap(a);var b=false,c=function(){b&&this.deleteOverlay("match-paren")}.clearingTimeout(500,this),d={beforeInteractiveCommand:function(){c.doItNow()},afterInteractiveCommand:function(){var a=this.tokenizer.getLastParser(),d=this._rowcol;a&&f(a).foreach(function(a){var e=a.closed;if(a.line==d.row&&a.col==d.col||e.line==d.row&&e.col==d.col-1)b=true,this.setOverlay("match-paren",{line1:a.line,line2:e.line,col1:a.col,col2:e.col+1}),c()},this)}.clearingTimeout(100)};this.addEventListener(d);return function(){c.doItNow(),this.popKeymap(a),this.removeEventListener(d)}})}),function(){Ymacs_Buffer.newCommands({lisp_open_paren:Ymacs_Interactive(function(a){a==null&&(a="("),a+=i(a),this.cmd("insert",a),this.cmd("backward_char")}),lisp_close_paren:Ymacs_Interactive(function(a){var b=new RegExp("\\s*\\"+a,"ig");this.cmd("looking_at",b)&&this._deleteText(this.point(),this.matchData.after),this.cmd("insert",a)}),lisp_close_all_parens:Ymacs_Interactive(function(){var a=this.tokenizer.getParserForLine(this._rowcol.row);if(a){var b=this.tokenizer.stream;b.line=this._rowcol.row,b.col=0;try{while(b.col?@\[\]\^_\{\}~]$/i.test(a)}function l(a){return a!="#"&&k(a)}Ymacs_Tokenizer.define("lisp",function(d,e){var m=[],n=false,o=false,p=null,q=[],r=[],s=[],t=[],u={next:D,copy:v,indentation:E};function v(){var a=b.context={cont:m.slice(0),quote:p,inString:n,inComment:o,parens:q.slice(0),passedParens:r.slice(0),backList:s.slice(0),list:t.slice(0)};function b(){m=a.cont.slice(0),n=a.inString,p=a.quote,o=a.inComment,q=a.parens.slice(0),r=a.passedParens.slice(0),s=a.backList.slice(0),t=a.list.slice(0);return u}return b}function w(a,b,c){e.onToken(d.line,a,b,c)}function x(a){a==null&&(a={c1:d.col}),t.push(a)}function y(){return d.buffer.getq("indent_level")}function z(){var a=d.col,b=d.get(),c=b;while(!d.eol()){b=d.peek();if(!k(b))break;c+=b,d.nextCol()}return b&&{line:d.line,c1:a,c2:d.col,id:c.toLowerCase()}}function A(a,b){var c,e=false,f=d.col;while(!d.eol()){if((c=d.peek())===a&&!e){m.pop(),n=null,w(f,d.col,b),w(d.col,++d.col,b+"-stopper");return true}e=!e&&c==="\\",d.nextCol()}w(f,d.col,b)}function B(){var a=d.lineText(),b=a.indexOf("|#",d.col),c=/^\s*\|+/.exec(a.substr(d.col));c&&w(d.col,d.col+=c[0].length,"mcomment-starter"),b>=0?(m.pop(),o=null,w(d.col,b,"mcomment"),w(b,b+=2,"mcomment-stopper"),d.col=b):(w(d.col,a.length,"mcomment"),d.col=a.length)}function C(a){var b=t&&t.length>0&&t[0].id;if(b){b=b.toLowerCase();if(a==null)return b;return typeof a=="string"?b==a:b in a}}function D(){d.checkStop();if(m.length>0)return m.peek()();var e=d.peek(),h;if(h=d.lookingAt(/^#\\(Space|Newline|.?)/i))x(),w(d.col,d.col+=h[0].length,"constant");else if(d.lookingAt(/^#\x27[^(]/))x(),d.col+=2,h=z(),w(h.c1,h.c2,"function-name");else if(d.lookingAt("#|"))o={line:d.line,c1:d.col},w(d.col,d.col+=2,"mcomment-starter"),m.push(B);else if(h=d.lookingAt(/^;+/))w(d.col,d.col+=h[0].length,"comment-starter"),w(d.col,d.col=d.lineLength(),"comment");else if(e==="\"")x(),n={line:d.line,c1:d.col},w(d.col,++d.col,"string-starter"),m.push(A.$C(e,"string"));else if(h=d.lookingAt(/^[+-]?(#x[0-9a-f]+|#o[0-7]+|#b[01]+|[0-9]*\.?[0-9]+e?[0-9]*)(\x2f(#x[0-9a-f]+|#o[0-7]+|#b[01]+|[0-9]*\.?[0-9]+e?[0-9]*))?/))x(),w(d.col,d.col+=h[0].length,"number");else if(h=i(e))x(),s.push(t),t=[],q.push({line:d.line,col:d.col,type:e}),w(d.col,++d.col,"open-paren");else if(h=j(e)){var k=q.pop();!k||k.type!=h?w(d.col,++d.col,"error"):(k.closed={line:d.line,col:d.col,opened:k},r.push(k),t=s.pop(),w(d.col,++d.col,"close-paren"))}else if(l(e)&&(h=z())){var p=e==":"?"lisp-keyword":h.id in a?"keyword":h.id in b?"builtin":h.id in c?"constant":null;p||(C(f)&&t.length==1?p="function-name":C(g)&&t.length==1?p="type":/^with-/i.test(h.id)&&(p="builtin")),x(h),w(h.c1,h.c2,p)}else w(d.col,++d.col,null)}function E(){if(n)return 0;var a=d.lineText(),b=0,c=q.peek();if(c){var e=d.lineText(c.line);b=c.col+1;var f;if(l(e.charAt(b))){b=c.col+y();var g=/\s\S/g;g.lastIndex=c.col,(f=g.exec(e))&&(f=f.index+1)}if(t&&t.length){var i=C();if(i){i=i.replace(/\*$/,"");var j=h[i];!j&&/^with/.test(i)&&(j="1*"),j||(j="1+");if(j){var k=parseInt(j,10),m=/\+$/.test(j),o=/\*$/.test(j);if(t.length-1=0?(m.pop(),p=null,u(f.col,b,"mcomment"),u(b,b+=2,"mcomment-stopper"),f.col=b):(u(f.col,a.length,"mcomment"),f.col=a.length)}function x(a,b){var c,d=false,e=f.col;while(!f.eol()){if((c=f.peek())===a&&!d){m.pop(),q=null,u(e,f.col,b),u(f.col,++f.col,b+"-stopper");return true}d=!d&&c==="\\",f.nextCol()}u(e,f.col,b)}function y(){var a,b=false,c=0,d=f.col;while(!f.eol()){a=f.peek(),k(a)&&!b&&!c&&c++,l(a)&&!b&&(c--,c<0&&(c=0));if(a==="/"&&!b&&!c){m.pop(),q=null,u(d,f.col,"regexp"),u(f.col,++f.col,"regexp-stopper");var e=f.lookingAt(/^[gmsiy]+/);e&&u(f.col,f.col+=e[0].length,"regexp-modifier");return true}b=!b&&a==="\\",f.nextCol()}u(d,f.col,"regexp")}function z(){f.checkStop();if(m.length>0)return m.peek()();var h=f.peek(),i,j;if(f.lookingAt("/*"))p={line:f.line,c1:f.col},u(f.col,f.col+=2,"mcomment-starter"),m.push(w);else if(f.lookingAt("//"))u(f.col,f.col+=2,"comment-starter"),u(f.col,f.col=f.lineLength(),"comment");else if(h==="\""||h==="'")q={line:f.line,c1:f.col},u(f.col,++f.col,"string-starter"),m.push(x.$C(h,"string"));else if(i=f.lookingAt(/^0x[0-9a-f]+|^[0-9]*\.?[0-9]+/))u(f.col,f.col+=i[0].length,"number");else if(g(h)&&(j=v())){var r=j.id in a?"keyword":j.id in b?"type":j.id in c?"constant":j.id in d?"builtin":null;u(j.c1,j.c2,r)}else if(j=k(h))n.push({line:f.line,col:f.col,type:h}),u(f.col,++f.col,"open-paren");else if(j=l(h)){var s=n.pop();!s||s.type!=j?u(f.col,++f.col,"error"):(s.closed={line:f.line,col:f.col,opened:s},o.push(s),u(f.col,++f.col,"close-paren"))}else h==="/"&&e.test(f.textBefore())?(u(f.col,++f.col,"regexp-starter"),m.push(y)):(i=f.lookingAt(/^\s+$/))?u(f.col,f.col+=i[0].length,"trailing-whitespace"):u(f.col,++f.col,null)}function A(){if(q)return 0;var a=f.line,b=f.lineText(),c=0;if(p){var d=f.lineText(p.line);c=p.c1+1;if(!/^\s*\*/.test(b)){var e=/[^\s*]/g;e.lastIndex=p.c1+1;var g=e.exec(d);g&&(c=g.index)}return c}var h=n.peek();if(h){var e=new RegExp("^\\s*\\"+i[h.type]),j=e.test(b),k=f.lineText(h.line);e=/\S/g,e.lastIndex=h.col+1;var g=e.exec(k);g?c=j?h.col:g.index:(c=f.lineIndentation(h.line)+s(),j&&(c-=s()))}if(a>0){var l=f.textBefore();if(/\)\s*$/.test(l)&&o.length>0){h=o.peek();var m=f.lineText(h.line);/^\s*(if|for|while)\W/.test(m)&&(c+=s())}else/\Welse\s*$/.test(l)&&(c+=s())}/^\s*(case|default)\W/.test(b)&&(c-=s()/2);return c}return r}Ymacs_Tokenizer.define("js",m.$C(a.toHash(true),b.toHash(true),c.toHash(true),d.toHash(true)));var n=d.concat("\nDEFINE_CLASS DEFINE_SINGLETON DEFINE_HIDDEN_CLASS \nDEFAULT_ARGS DEFAULT_EVENTS \nFIXARGS CONSTRUCT BEFORE_BASE FINISH_OBJECT_DEF \nD P $".qw());Ymacs_Tokenizer.define("js-dynarchlib",m.$C(a.toHash(true),b.toHash(true),c.toHash(true),n.toHash(true)))}(),DEFINE_SINGLETON("Ymacs_Keymap_CLanguages",Ymacs_Keymap,function(a,b){a.KEYS={ENTER:"newline_and_indent","} && ) && ] && : && ; && { && ( && [ && *":"c_insert_and_indent"}}),Ymacs_Buffer.newMode("javascript_mode",function(a){var b=this.tokenizer,c=Ymacs_Keymap_CLanguages();this.setTokenizer(new Ymacs_Tokenizer({buffer:this,type:a?"js-dynarchlib":"js"})),this.pushKeymap(c);var d=this.cmd("paren_match_mode",true);return function(){this.setTokenizer(b),this.popKeymap(c),d||this.cmd("paren_match_mode",false)}}),Ymacs_Buffer.newCommands({javascript_dl_mode:Ymacs_Interactive(function(){return this.cmd("javascript_mode",true)}),c_electric_block:Ymacs_Interactive(function(){this.cmd("indent_line"),this.cmd("insert","{\n\n}"),this.cmd("indent_line"),this.cmd("backward_line",1),this.cmd("indent_line")}),c_insert_and_indent:Ymacs_Interactive(function(){var a;if(a=this.cmd("self_insert_command")){this.cmd("indent_line");return a}})}),Ymacs_Tokenizer.define("xml",function(a,b){var c=[],d=[],e=null,f=null,g={next:s,copy:h,indentation:t};function h(){var a=c.slice(0),b=d.slice(0),h=e,i=f;function j(){d=b.slice(0),c=a.slice(0),e=h,f=i;return g}return j}function i(){return a.buffer.getq("indent_level")}function j(c,d,e){b.onToken(a.line,c,d,e)}function k(a){return a.toLowerCase()!=a.toUpperCase()}function l(a){return a&&(k(a)||/^[:_-]$/.test(a))}function m(a){return a&&(k(a)||/^[0-9_-]$/.test(a))}function n(){var b=a.col,c=a.get(),d=c;while(!a.eol()){c=a.peek();if(!m(c))break;d+=c,a.nextCol()}return c&&{line:a.line,c1:b,c2:a.col,id:d}}function o(b){var c,e=false,f=a.col;while(!a.eol()){if((c=a.peek())===b&&!e){d.pop(),j(f,a.col,"string"),j(a.col,++a.col,"string-stopper");return}e=!e&&c==="\\",a.nextCol()}j(f,a.col,"string")}function p(){var b=a.peek(),f;a.lookingAt(/^\x2f>/)?(d.pop(),e=null,j(a.col,++a.col,"xml-closetag-slash"),j(a.col,++a.col,"xml-close-bracket")):b===">"?(d.pop(),c.push(e),e=null,j(a.col,++a.col,"xml-close-bracket")):l(b)&&(f=n())?j(f.c1,f.c2,"xml-attribute"):b==="\""||b==="'"?(j(a.col,++a.col,"string-starter"),d.push(o.$C(b))):j(a.col,++a.col,null)}function q(b,c){var e=a.lineText(),g=e.indexOf(c,a.col);g>=0?(d.pop(),j(a.col,g,b),f=null,j(g,g+=c.length,b+"-stopper"),a.col=g):(j(a.col,e.length,b),a.col=e.length)}function r(){var b=a.lookingAt(/^([\s\xA0]*)(>?)/);b&&b[0]?(b[1]&&j(a.col,a.col+=b[1].length,null),b[2]&&(j(a.col,a.col+=b[2].length,"xml-close-bracket"),d.pop())):j(a.col,++a.col,"error")}function s(){a.checkStop();if(d.length>0)return d.peek()();var b=a.peek(),g;if(a.lookingAt(""));else if(a.lookingAt(""));else if(a.lookingAt(/^<\x2f/)&&l(a.peek(+2))){j(a.col,++a.col,"xml-open-bracket"),j(a.col,++a.col,"xml-closetag-slash");var h=n(),i=c.pop();j(h.c1,h.c2,i&&i.id==h.id?"xml-close-tag":"error"),d.push(r)}else if(b==="<"&&l(a.peek(+1))){j(a.col,++a.col,"xml-open-bracket");var h=n();j(h.c1,h.c2,"xml-open-tag"),e=h,d.push(p)}else(g=a.lookingAt(/^&.*?;/))?(j(a.col,++a.col,"xml-entity-starter"),j(a.col,a.col+=g[0].length-2,"xml-entity"),j(a.col,++a.col,"xml-entity-stopper")):b==="&"?j(a.col,++a.col,"error"):j(a.col,++a.col,null)}function t(){var b,d;if(f)b=a.lineIndentation(f.line)+i();else if(e)b=e.c1+e.id.length+1;else if(d=c.peek())b=a.lineIndentation(d.line)+i(),/^\s*<\x2f/.test(a.lineText())&&(b-=i());return b}return g}),DEFINE_SINGLETON("Ymacs_Keymap_XML",Ymacs_Keymap,function(a,b){a.KEYS={"C-c /":"xml_close_tag","C-ENTER":"xml_zen_expand",ENTER:"newline_and_indent"}}),Ymacs_Buffer.newMode("xml_mode",function(){var a=this.tokenizer;this.setTokenizer(new Ymacs_Tokenizer({buffer:this,type:"xml"}));var b=Ymacs_Keymap_XML();this.pushKeymap(b);var c=this.setq({indent_level:2});return function(){this.setTokenizer(a),this.popKeymap(b),this.setq(c)}}),function(){DEFINE_SINGLETON("Ymacs_Keymap_XML_Zen",Ymacs_Keymap,function(a,b){a.KEYS={TAB:"xml_zen_next_poi","S-TAB":"xml_zen_prev_poi","C-g":"xml_zen_stop"}});var a=1,b=2,c=3,d=4,e=5;function f(a,b){for(var c=a.repeat||1,d=1;d<=c;++d)d>1&&b("\n"),b("<",a.type),a.id&&b(" id=\"",a.id.replace(/\$/g,d),"\""),a.klass&&b(" class=\"",a.klass.replace(/\$/g,d),"\""),a.attributes&&a.attributes.foreach(function(a){b(" ",a,"=\"|\"")}),b(">"),a.child?(b("\n"),f(a.child,b),b("\n")):b("|"),b(""),a.next&&(b("\n"),f(a.next,b))}function g(f,h){var i={type:""},j=a;OUTER:while(h":i.child=g(f,h),h=i.child.i;break OUTER;case"(":i.child=g(f,h),h=i.child.i;break;case")":break OUTER;case"+":i.next=g(f,h),h=i.next.i;break OUTER;default:switch(j){case a:i.type+=k;break;case b:i.klass+=k;break;case c:i.id+=k;break;case d:i.repeat=parseInt(String(i.repeat)+k,10);break;case e:i.attributes.push(i.attributes.pop()+k)}}}i.i=h;return i}function h(){var a=this.point(),b=this.getq("xml_zen_markers"),c=b[0],d=b.peek();(ad.getPosition()||d.getPosition()==b.peek(1).getPosition())&&this.cmd("xml_zen_stop")}Ymacs_Buffer.newCommands({xml_close_tag:Ymacs_Interactive(function(){this.cmd("close_last_xml_tag"),this.cmd("indent_line")}),xml_zen_expand:Ymacs_Interactive(function(){this.cmd("xml_zen_stop");var a=String.buffer(),b=this.cmd("save_excursion",function(){this.cmd("backward_whitespace");while(!this.cmd("looking_back",/[\x20\xa0\s\t\n;&]/))if(!this.cmd("backward_char"))break;return this.point()}),c=this.point();try{f(g(this.cmd("buffer_substring",b,c).trim(),0),a)}catch(a){throw new Ymacs_Exception("The Zen is not strong today :-/")}a=a.get(),this.cmd("delete_region",b,c),this.cmd("insert",a),b=this.createMarker(b,false,"xml_zen");var d=this.createMarker(this.point(),true,"xml_zen"),e=[];this.cmd("goto_char",b.getPosition());while(this.cmd("search_forward","|",d.getPosition()))this.cmd("backward_delete_char"),e.push(this.createMarker(this.point(),true,"xml_zen_start")),e.push(this.createMarker(this.point(),false,"xml_zen_end"));this.cmd("indent_region",b.getPosition(),d.getPosition());var i=e.length;i>0?(this.cmd("goto_char",e[0]),e.unshift(b),e.push(d),this.setq("xml_zen_markers",e),this.pushKeymap(Ymacs_Keymap_XML_Zen()),this.addEventListener("afterInteractiveCommand",h)):(b.destroy(),d.destroy())}),xml_zen_stop:Ymacs_Interactive(function(){var a=this.getq("xml_zen_markers");a&&(a.map("destroy"),this.setq("xml_zen_markers",null)),this.popKeymap(Ymacs_Keymap_XML_Zen()),this.removeEventListener("afterInteractiveCommand",h)}),xml_zen_next_poi:Ymacs_Interactive(function(){var a=this.getq("xml_zen_markers"),b=this.point();a.foreach(function(a){a.getPosition()>b&&(this.cmd("goto_char",a.getPosition()),$BREAK())},this)}),xml_zen_prev_poi:Ymacs_Interactive(function(){var a=this.getq("xml_zen_markers"),b=this.point();a.r_foreach(function(a){a.getPosition()=0?(f.pop(),h=null,o(a.col,c,"mcomment"),o(c,c+=2,"mcomment-stopper"),a.col=c):(o(a.col,b.length,"mcomment"),a.col=b.length)}function q(b,c){var d,e=false,h=a.col;while(!a.eol()){if((d=a.peek())===b&&!e){f.pop(),g=null,o(h,a.col,c),o(a.col,++a.col,c+"-stopper");return true}e=!e&&d==="\\",a.nextCol()}o(h,a.col,c)}function r(){a.checkStop();if(f.length>0)return f.peek()();var b=a.peek(),c;if(a.lookingAt("/*"))h={line:a.line,c1:a.col},o(a.col,a.col+=2,"mcomment-starter"),f.push(p);else if(b==="\""||b==="'")g={line:a.line,c1:a.col},o(a.col,++a.col,"string-starter"),f.push(q.$C(b,"string"));else if(c=m(b))d.push({line:a.line,col:a.col,type:b}),o(a.col,++a.col,"open-paren");else if(c=n(b)){var i=d.pop();!i||i.type!=c?o(a.col,++a.col,"error"):(i.closed={line:a.line,col:a.col,opened:i},e.push(i),o(a.col,++a.col,"close-paren"))}else(c=a.lookingAt(/^([a-zA-z-]+):/))?(o(a.col,a.col+=c[1].length,"keyword"),o(a.col,++a.col,"operator")):(c=a.lookingAt(/^([0-9.]+)(px|pt|em|ex|in|cm|mm|%)/))?(o(a.col,a.col+=c[1].length,"number"),o(a.col,a.col+=c[2].length,"type")):(c=a.lookingAt(/^(\.[a-zA-Z0-9_:-]+)/))?o(a.col,a.col+=c[1].length,"function-name"):(c=a.lookingAt(/^(#[a-zA-Z0-9_:-]+)/))?o(a.col,a.col+=c[1].length,"constant"):(c=a.lookingAt(/^(@[a-zA-Z0-9_:-]+)/))?o(a.col,a.col+=c[1].length,"builtin"):(c=a.lookingAt(/^(url|none|auto|bold|italic|normal|inherit|print|screen|all)/))?o(a.col,a.col+=c[1].length,"builtin"):o(a.col,++a.col,null)}function s(){if(g)return 0;var b=a.line,c=a.lineText(),e=0;if(h){var f=a.lineText(h.line);e=h.c1+1;if(!/^\s*\*/.test(c)){var i=/[^\s*]/g;i.lastIndex=h.c1+1;var l=i.exec(f);l&&(e=l.index)}return e}var m=d.peek();if(m){var i=new RegExp("^\\s*\\"+k[m.type]),n=i.test(c),o=a.lineText(m.line);i=/\S/g,i.lastIndex=m.col+1;var l=i.exec(o);l?e=n?m.col:l.index:(e=a.lineIndentation(m.line)+j(),n&&(e-=j()))}return e}return c}),DEFINE_SINGLETON("Ymacs_Keymap_CSS",Ymacs_Keymap),Ymacs_Keymap_CSS().defineKeys({ENTER:"newline_and_indent",": && } && )":"c_insert_and_indent"}),Ymacs_Buffer.newMode("css_mode",function(){var a=this.tokenizer;this.setTokenizer(new Ymacs_Tokenizer({buffer:this,type:"css"}));var b=this.cmd("paren_match_mode",true);this.pushKeymap(Ymacs_Keymap_CSS());return function(){this.setTokenizer(a),b||this.cmd("paren_match_mode",false),this.popKeymap(Ymacs_Keymap_CSS())}}),Ymacs_Tokenizer.define("markdown",function(a,b){var c={next:f,copy:d};function d(){var a=b.context={};function b(){return c}return b}function e(c,d,e){b.onToken(a.line,c,d,e)}function f(){a.checkStop();var c;a.col==0&&(c=a.lookingAt(/^(#+)/))?e(0,a.col=a.lineLength(),"markdown-heading"+c[0].length):a.line>0&&a.col==0&&(c=a.lookingAt(/^[=-]+$/))&&/\S/.test(a.lineText(a.line-1))?(c=c[0].charAt(0)=="="?1:2,c="markdown-heading"+c,b.onToken(a.line-1,0,a.lineLength(a.line-1),c),e(0,a.col=a.lineLength(),c)):a.col==0&&(c=a.lookingAt(/^[>\s]*/))?((c=c[0].replace(/\s+/g,"").length)>3&&(c=""),c="markdown-blockquote"+c,e(0,a.col=a.lineLength(),c)):e(a.col,++a.col,null)}return c}),Ymacs_Buffer.newMode("markdown_mode",function(){var a=this.tokenizer;this.setTokenizer(new Ymacs_Tokenizer({buffer:this,type:"markdown"}));return function(){this.setTokenizer(a)}})