Added indentation to lua

This commit is contained in:
Lee Gao 2011-08-18 20:23:31 -04:00
commit db9862b3f7
4 changed files with 97 additions and 13 deletions

View file

@ -18835,11 +18835,12 @@ exports.XmlHighlightRules = XmlHighlightRules;
*
* ***** END LICENSE BLOCK ***** */
define('ace/mode/lua', ['require', 'exports', 'module' , 'pilot/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/lua_highlight_rules'], function(require, exports, module) {
define('ace/mode/lua', ['require', 'exports', 'module' , 'pilot/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/lua_highlight_rules', 'ace/range'], function(require, exports, module) {
var oop = require("pilot/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var LuaHighlightRules = require("ace/mode/lua_highlight_rules").LuaHighlightRules;
var Range = require("ace/range").Range;
var Mode = function() {
this.$tokenizer = new Tokenizer(new LuaHighlightRules().getRules());
@ -18853,21 +18854,62 @@ oop.inherits(Mode, TextMode);
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
var tokens = tokenizedLine.tokens;
var endState = tokenizedLine.state;
if (tokens.length && tokens[tokens.length-1].type == "comment") {
return indent;
}
var chunks = ["function", "then", "do", "repeat"];
if (state == "start") {
var match = line.match(/^.*[\{\(\[]\s*$/);
if (match) {
indent += tab;
} else {
for (var i in tokens){
var token = tokens[i];
if (token.type != "keyword") continue;
var chunk_i = chunks.indexOf(token.value);
if (chunk_i != -1){
indent += tab;
break;
}
}
}
}
return indent;
};
/*this.checkOutdent = function(state, line, input) {
if (input !== "\r\n" && input !== "\r" && input !== "\n")
return false;
var tokens = this.$tokenizer.getLineTokens(line.trim(), state).tokens;
if (!tokens)
return false;
// ignore trailing comments
do {
var last = tokens.pop();
} while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
if (!last)
return false;
var outdents = {
"end" : 1,
"until" : 1,
"else" : 1
}
return (last.type == "keyword" && outdents[last.value]);
};
this.autoOutdent = function(state, doc, row) {
console.log(doc, row);
var indent = this.$getIndent(doc.getLine(row));
var tab = doc.getTabString();
if (indent.slice(-tab.length) == tab)
doc.remove(new Range(row, indent.length-tab.length, row, indent.length));
};*/
}).call(Mode.prototype);
exports.Mode = Mode;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -42,6 +42,7 @@ var oop = require("pilot/oop");
var TextMode = require("ace/mode/text").Mode;
var Tokenizer = require("ace/tokenizer").Tokenizer;
var LuaHighlightRules = require("ace/mode/lua_highlight_rules").LuaHighlightRules;
var Range = require("ace/range").Range;
var Mode = function() {
this.$tokenizer = new Tokenizer(new LuaHighlightRules().getRules());
@ -55,21 +56,62 @@ oop.inherits(Mode, TextMode);
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
var tokens = tokenizedLine.tokens;
var endState = tokenizedLine.state;
if (tokens.length && tokens[tokens.length-1].type == "comment") {
return indent;
}
var chunks = ["function", "then", "do", "repeat"];
if (state == "start") {
var match = line.match(/^.*[\{\(\[]\s*$/);
if (match) {
indent += tab;
} else {
for (var i in tokens){
var token = tokens[i];
if (token.type != "keyword") continue;
var chunk_i = chunks.indexOf(token.value);
if (chunk_i != -1){
indent += tab;
break;
}
}
}
}
return indent;
};
/*this.checkOutdent = function(state, line, input) {
if (input !== "\r\n" && input !== "\r" && input !== "\n")
return false;
var tokens = this.$tokenizer.getLineTokens(line.trim(), state).tokens;
if (!tokens)
return false;
// ignore trailing comments
do {
var last = tokens.pop();
} while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
if (!last)
return false;
var outdents = {
"end" : 1,
"until" : 1,
"else" : 1
}
return (last.type == "keyword" && outdents[last.value]);
};
this.autoOutdent = function(state, doc, row) {
console.log(doc, row);
var indent = this.$getIndent(doc.getLine(row));
var tab = doc.getTabString();
if (indent.slice(-tab.length) == tab)
doc.remove(new Range(row, indent.length-tab.length, row, indent.length));
};*/
}).call(Mode.prototype);
exports.Mode = Mode;