From 2fdb6378a33fe04c1ba1ee90fe901ef0b9ecec5e Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 8 May 2012 23:34:09 -0700 Subject: [PATCH] merge c9mode changes --- Makefile.dryice.js | 2 +- lib/ace/edit_session/bracket_match.js | 8 +- lib/ace/mode/c9search.js | 86 +++++++++++++++++++++ lib/ace/mode/c9search_highlight_rules.js | 66 ++++++++++++++++ lib/ace/mode/folding/c9search.js | 97 ++++++++++++++++++++++++ lib/ace/mode/folding/fold_mode.js | 4 +- 6 files changed, 259 insertions(+), 4 deletions(-) create mode 100644 lib/ace/mode/c9search.js create mode 100644 lib/ace/mode/c9search_highlight_rules.js create mode 100644 lib/ace/mode/folding/c9search.js diff --git a/Makefile.dryice.js b/Makefile.dryice.js index 4febbac6..f87cd5ee 100755 --- a/Makefile.dryice.js +++ b/Makefile.dryice.js @@ -230,7 +230,7 @@ function buildAce(aceProject, options) { "css", "html", "javascript", "php", "coldfusion", "python", "lua", "xml", "ruby", "java", "c_cpp", "coffee", "perl", "csharp", "haxe", "liquid", "svg", "clojure", "scss", "json", "groovy", "ocaml", "scala", "textile", "scad", "markdown", "latex", "powershell", "sql", - "text", "pgsql", "sh", "xquery", "less", "golang" + "text", "pgsql", "sh", "xquery", "less", "golang", "c9search" ], themes: [ "chrome", "clouds", "clouds_midnight", "cobalt", "crimson_editor", "dawn", diff --git a/lib/ace/edit_session/bracket_match.js b/lib/ace/edit_session/bracket_match.js index 8144462a..86400214 100644 --- a/lib/ace/edit_session/bracket_match.js +++ b/lib/ace/edit_session/bracket_match.js @@ -152,7 +152,7 @@ function BracketMatch() { return null; }; - this.$findClosingBracket = function(bracket, position, typeRe) { + this.$findClosingBracket = function(bracket, position, typeRe, allowBlankLine) { var closingBracket = this.$brackets[bracket]; var depth = 1; @@ -197,6 +197,12 @@ function BracketMatch() { // whose type matches typeRe do { token = iterator.stepForward(); + if (allowBlankLine) { + // if you've reached the doc end, or, you match a new content line + if (token === null || token.type == "string") { + return {row: iterator.getCurrentTokenRow() + (token === null ? 1 : -1), column: 0}; + } + } } while (token && !typeRe.test(token.type)); if (token == null) diff --git a/lib/ace/mode/c9search.js b/lib/ace/mode/c9search.js new file mode 100644 index 00000000..cff2b22a --- /dev/null +++ b/lib/ace/mode/c9search.js @@ -0,0 +1,86 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Garen J. Torikian + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var C9SearchHighlightRules = require("./c9search_highlight_rules").C9SearchHighlightRules; +var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent; +var C9StyleFoldMode = require("./folding/c9search").FoldMode; + +var Mode = function() { + this.$tokenizer = new Tokenizer(new C9SearchHighlightRules().getRules(), "i"); + this.$outdent = new MatchingBraceOutdent(); + this.foldingRules = new C9StyleFoldMode(); +}; +oop.inherits(Mode, TextMode); + +(function() { + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + + // ignore braces in comments + var tokens = this.$tokenizer.getLineTokens(line, state).tokens; + if (tokens.length && tokens[tokens.length-1].type == "comment") { + return indent; + } + + var match = line.match(/^.*\{\s*$/); + if (match) { + indent += tab; + } + + return indent; + }; + + this.checkOutdent = function(state, line, input) { + return this.$outdent.checkOutdent(line, input); + }; + + this.autoOutdent = function(state, doc, row) { + this.$outdent.autoOutdent(doc, row); + }; + +}).call(Mode.prototype); + +exports.Mode = Mode; + +}); diff --git a/lib/ace/mode/c9search_highlight_rules.js b/lib/ace/mode/c9search_highlight_rules.js new file mode 100644 index 00000000..0555963a --- /dev/null +++ b/lib/ace/mode/c9search_highlight_rules.js @@ -0,0 +1,66 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Garen J. Torikian + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var C9SearchHighlightRules = function() { + + // regexp must not have capturing parentheses. Use (?:) instead. + // regexps are ordered -> the first match is used + this.$rules = { + "start" : [ + { + token : ["string", "text"], // single line + regex : "(.+)(:$)" + }, + { + token : ["constant.numeric", "text"], + regex : "(^\\s*[0-9]+)(:\\s*)" + } + ] + }; +}; + +oop.inherits(C9SearchHighlightRules, TextHighlightRules); + +exports.C9SearchHighlightRules = C9SearchHighlightRules; + +}); diff --git a/lib/ace/mode/folding/c9search.js b/lib/ace/mode/folding/c9search.js new file mode 100644 index 00000000..dd501153 --- /dev/null +++ b/lib/ace/mode/folding/c9search.js @@ -0,0 +1,97 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Ajax.org Code Editor (ACE). + * + * The Initial Developer of the Original Code is + * Ajax.org B.V. + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Fabian Jakobs + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +define(function(require, exports, module) { +"use strict"; + +var oop = require("../../lib/oop"); +var Range = require("../../range").Range; +var BaseFoldMode = require("./fold_mode").FoldMode; + +var FoldMode = exports.FoldMode = function() {}; +oop.inherits(FoldMode, BaseFoldMode); + +(function() { + + this.foldingStartMarker = /[a-zA-Z](:)\s*$/; + this.foldingStopMarker = /^(\s*)$/; + + this.getFoldWidgetRange = function(session, foldStyle, row) { + var line = session.getLine(row); + var match = line.match(this.foldingStartMarker); + if (match) { + var i = match.index; + + if (match[1]) + return this.openingBracketBlock(session, match[1], row, i, false, true); + + var range = session.getCommentFoldRange(row, i + match[0].length); + range.end.column -= 2; + return range; + } + + if (foldStyle !== "markbeginend") + return; + + var match = line.match(this.foldingStopMarker); + if (match) { + var i = match.index + match[0].length; + + if (match[2]) { + var range = session.getCommentFoldRange(row, i); + range.end.column -= 2; + return range; + } + + var end = {row: row, column: i}; + var start = session.$findOpeningBracket(match[1], end); + + if (!start) + return; + + start.column++; + end.column--; + + return Range.fromPoints(start, end); + } + }; + +}).call(FoldMode.prototype); + +}); + diff --git a/lib/ace/mode/folding/fold_mode.js b/lib/ace/mode/folding/fold_mode.js index 762eddee..849526c7 100644 --- a/lib/ace/mode/folding/fold_mode.js +++ b/lib/ace/mode/folding/fold_mode.js @@ -91,9 +91,9 @@ var FoldMode = exports.FoldMode = function() {}; } }; - this.openingBracketBlock = function(session, bracket, row, column) { + this.openingBracketBlock = function(session, bracket, row, column, typeRe, allowBlankLine) { var start = {row: row, column: column + 1}; - var end = session.$findClosingBracket(bracket, start); + var end = session.$findClosingBracket(bracket, start, typeRe, allowBlankLine); if (!end) return;