Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

multiline indentation for javascript. #1397

Closed
wants to merge 1 commit into from

2 participants

@pydichandra

No description provided.

@marijnh
Owner

What does this accomplish?

@pydichandra
@marijnh
Owner

Your patch has several problems

  • It looks for the option in the config rather than parserConfig object. That will only hold editor-wide options, whereas this is clearly a mode-specific one.
  • It completely breaks the mode when the option is not specified.
  • It removes support for the current model, which I personally find a lot saner.
@pydichandra
@marijnh marijnh closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2013
  1. @pydichandra
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 2 deletions.
  1. +6 −2 mode/javascript/javascript.js
View
8 mode/javascript/javascript.js
@@ -2,6 +2,7 @@
CodeMirror.defineMode("javascript", function(config, parserConfig) {
var indentUnit = config.indentUnit;
+ var statementIndentUnit = config.statementIndentUnit;
var jsonMode = parserConfig.json;
var isTS = parserConfig.typescript;
@@ -227,7 +228,10 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
function pushlex(type, info) {
var result = function() {
var state = cx.state;
- state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info);
+ var indent = state.indented;
+ if (state.lexical.type == "stat")
+ indent = state.lexical.indented;
+ state.lexical = new JSLexical(indent, cx.stream.column(), type, null, state.lexical, info);
};
result.lex = true;
return result;
@@ -415,7 +419,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
else if (type == "form" && firstChar == "{") return lexical.indented;
else if (type == "form") return lexical.indented + indentUnit;
else if (type == "stat")
- return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? indentUnit : 0);
+ return lexical.indented + (state.lastType == "operator" || state.lastType == "," ? statementIndentUnit : 0);
else if (lexical.info == "switch" && !closing)
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
Something went wrong with that request. Please try again.