diff --git a/lib/ace/mode/folding/lua.js b/lib/ace/mode/folding/lua.js new file mode 100644 index 00000000..c01f1e9f --- /dev/null +++ b/lib/ace/mode/folding/lua.js @@ -0,0 +1,75 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Distributed under the BSD license: + * + * Copyright (c) 2012, Ajax.org B.V. + * 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 Ajax.org B.V. 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 HOLDERS AND CONTRIBUTORS "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 AJAX.ORG B.V. 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. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../../lib/oop"); +var BaseFoldMode = require("./fold_mode").FoldMode; +var Range = require("../../range").Range; + +var FoldMode = exports.FoldMode = function() {}; + +oop.inherits(FoldMode, BaseFoldMode); + +(function() { + + this.foldingStartMarker = /\b(function|local\s+function|then|do|repeat)\b|{[ \t]*$|\[\[/; + this.foldingStopMarker = /\bend\b|^\s*}|\]\]/; + + this.getFoldWidgetRange = function(session, foldStyle, row) { + var lines = session.doc.getAllLines(row); + var line = lines[row]; + + var re = this.foldingStartMarker.test(line) ? this.foldingStartMarker : this.foldingStopMarker; + + if (this.foldingStartMarker.test(line)) { + for (var i = row + 1, l = session.getLength(); i < l; i++) { + if (re.test(lines[i])) + break; + } + + return new Range(row, line.length, i, 0); + } + + if (this.foldingStopMarker.test(line)) { + for (var i = row - 1; i >= 0; i--) { + line = lines[i]; + if (re.test(line)) + break; + } + + return new Range(i, line.length, row, 0); + } + }; + +}).call(FoldMode.prototype); + +}); diff --git a/lib/ace/mode/lua.js b/lib/ace/mode/lua.js index efb3ffd1..e1a6143a 100644 --- a/lib/ace/mode/lua.js +++ b/lib/ace/mode/lua.js @@ -35,10 +35,12 @@ var oop = require("../lib/oop"); var TextMode = require("./text").Mode; var Tokenizer = require("../tokenizer").Tokenizer; var LuaHighlightRules = require("./lua_highlight_rules").LuaHighlightRules; +var LuaFoldMode = require("./folding/lua").FoldMode; var Range = require("../range").Range; var Mode = function() { this.$tokenizer = new Tokenizer(new LuaHighlightRules().getRules()); + this.foldingRules = new LuaFoldMode(); }; oop.inherits(Mode, TextMode);