Slightly improved auto indent for Clojure
This commit is contained in:
parent
8416cfb42a
commit
effcb04a9a
1 changed files with 22 additions and 11 deletions
|
|
@ -35,7 +35,7 @@ var oop = require("../lib/oop");
|
||||||
var TextMode = require("./text").Mode;
|
var TextMode = require("./text").Mode;
|
||||||
var ClojureHighlightRules = require("./clojure_highlight_rules").ClojureHighlightRules;
|
var ClojureHighlightRules = require("./clojure_highlight_rules").ClojureHighlightRules;
|
||||||
var MatchingParensOutdent = require("./matching_parens_outdent").MatchingParensOutdent;
|
var MatchingParensOutdent = require("./matching_parens_outdent").MatchingParensOutdent;
|
||||||
var Range = require("../range").Range;
|
var lang = require("../lib/lang");
|
||||||
|
|
||||||
var Mode = function() {
|
var Mode = function() {
|
||||||
this.HighlightRules = ClojureHighlightRules;
|
this.HighlightRules = ClojureHighlightRules;
|
||||||
|
|
@ -47,6 +47,19 @@ oop.inherits(Mode, TextMode);
|
||||||
|
|
||||||
this.lineCommentStart = ";";
|
this.lineCommentStart = ";";
|
||||||
|
|
||||||
|
this.$checkBracketDelta = function (line) {
|
||||||
|
var delta = 0;
|
||||||
|
for(var i = 0; i < line.length; i++) {
|
||||||
|
var ch = line[i];
|
||||||
|
if(ch === '(' || ch === '[' || ch === '{') {
|
||||||
|
delta++;
|
||||||
|
} else if(ch === ')' || ch === ']' || ch === '}') {
|
||||||
|
delta--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return delta;
|
||||||
|
};
|
||||||
|
|
||||||
this.getNextLineIndent = function(state, line, tab) {
|
this.getNextLineIndent = function(state, line, tab) {
|
||||||
var indent = this.$getIndent(line);
|
var indent = this.$getIndent(line);
|
||||||
|
|
||||||
|
|
@ -58,13 +71,11 @@ oop.inherits(Mode, TextMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state == "start") {
|
if (state == "start") {
|
||||||
var match = line.match(/[\(\[]/);
|
var delta = this.$checkBracketDelta(line);
|
||||||
if (match) {
|
if (delta > 0) {
|
||||||
indent += " ";
|
indent += tab;
|
||||||
}
|
} else if (delta < 0) {
|
||||||
match = line.match(/[\)]/);
|
indent = indent.substring(0, indent.length - tab.length);
|
||||||
if (match) {
|
|
||||||
indent = "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue