Permalink
Browse files

[clike mode] Add statementIndentUnit config option

To specify the amount that continued statements have to be indented.

Closes #1053
  • Loading branch information...
1 parent 4bfa0b5 commit 3e088ab300484b3a1880f22cf7b13892b6ae2715 @marijnh marijnh committed Dec 10, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 mode/clike/clike.js
View
@@ -1,5 +1,6 @@
CodeMirror.defineMode("clike", function(config, parserConfig) {
var indentUnit = config.indentUnit,
+ statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
keywords = parserConfig.keywords || {},
builtin = parserConfig.builtin || {},
blockKeywords = parserConfig.blockKeywords || {},
@@ -89,7 +90,10 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
this.prev = prev;
}
function pushContext(state, col, type) {
- return state.context = new Context(state.indented, col, type, null, state.context);
+ var indent = state.indented;
+ if (state.context && state.context.type == "statement")
+ indent = state.context.indented;
+ return state.context = new Context(indent, col, type, null, state.context);
}
function popContext(state) {
var t = state.context.type;
@@ -144,7 +148,7 @@ CodeMirror.defineMode("clike", function(config, parserConfig) {
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
var closing = firstChar == ctx.type;
- if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
+ if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
else return ctx.indented + (closing ? 0 : indentUnit);
},

0 comments on commit 3e088ab

Please sign in to comment.