diff --git a/src/codemirror-sos.ts b/src/codemirror-sos.ts index 63f985b..b14a042 100644 --- a/src/codemirror-sos.ts +++ b/src/codemirror-sos.ts @@ -362,8 +362,20 @@ CodeMirror.defineMode("sos", function(conf: CodeMirror.EditorConfiguration, pars for (var i = 0; i < sosActions.length; i++) { if (stream.match(sosActions[i])) { // switch to submode? - state.sos_state = 'start ' + stream.current().slice(0, -1); - state.overlay_state.sigil = null; + if (stream.eol()) { + // really + let mode = findMode(stream.current().slice(0, -1).toLowerCase()); + if (mode) { + state.sos_state = null; + state.inner_mode = CodeMirror.getMode(conf, mode); + state.inner_state = CodeMirror.startState(state.inner_mode); + } else { + state.sos_state = 'nomanland'; + } + } else { + state.sos_state = 'start ' + stream.current().slice(0, -1); + state.overlay_state.sigil = null; + } return "builtin strong"; } } @@ -420,11 +432,14 @@ CodeMirror.defineMode("sos", function(conf: CodeMirror.EditorConfiguration, pars let found = stream.match(/expand\s*=\s*"(\S+) (\S+)"/, false); if (!found) found = stream.match(/expand\s*=\s*'(\S+) (\S+)'/, false); - if (found) + if (found) { state.overlay_state.sigil = { 'left': found[1], 'right': found[2] } + } else { + state.overlay_state.sigil = null; + } } // if it is end of line, ending the starting switch mode if (stream.eol() && sl !== ',') { @@ -479,7 +494,7 @@ CodeMirror.defineMode("sos", function(conf: CodeMirror.EditorConfiguration, pars indent: function(state, textAfter) { // inner indent if (state.inner_mode) { - return state.inner_mode.indent(state.inner_mode, textAfter) + 4; + return state.inner_mode.indent(state.inner_mode, textAfter) + 2; } else { return 0; } @@ -493,7 +508,8 @@ CodeMirror.defineMode("sos", function(conf: CodeMirror.EditorConfiguration, pars }, lineComment: "#", - fold: "indent" + fold: "indent", + electricInput: /^\s*[\}\]\)]$/, }; }; }, "python"); diff --git a/src/sos-mode.js b/src/sos-mode.js index fae4439..7cf8d27 100644 --- a/src/sos-mode.js +++ b/src/sos-mode.js @@ -275,7 +275,6 @@ // inner indent if (!state.sos_mode) { if (!base_mode.indent) return CodeMirror.Pass; - // inner mode will autoamtically indent + 4 return base_mode.indent(state.base_state, textAfter); } else { // sos mode has no indent @@ -365,8 +364,20 @@ for (var i = 0; i < sosActions.length; i++) { if (stream.match(sosActions[i])) { // switch to submode? - state.sos_state = 'start ' + stream.current().slice(0, -1); - state.overlay_state.sigil = null; + if (stream.eol()) { + // really + let mode = findMode(stream.current().slice(0, -1).toLowerCase()); + if (mode) { + state.sos_state = null; + state.inner_mode = CodeMirror.getMode(conf, mode); + state.inner_state = CodeMirror.startState(state.inner_mode); + } else { + state.sos_state = 'nomanland'; + } + } else { + state.sos_state = 'start ' + stream.current().slice(0, -1); + state.overlay_state.sigil = null; + } return "builtin strong"; } } @@ -423,11 +434,15 @@ let found = stream.match(/expand\s*=\s*"(\S+) (\S+)"/, false); if (!found) found = stream.match(/expand\s*=\s*'(\S+) (\S+)'/, false); - if (found) + if (found) { state.overlay_state.sigil = { 'left': found[1], 'right': found[2] } + } else { + state.overlay_state.sigil = null; + } + } // if it is end of line, ending the starting switch mode if (stream.eol() && sl !== ',') { @@ -482,9 +497,10 @@ indent: function(state, textAfter) { // inner indent if (state.inner_mode) { - return state.inner_mode.indent(state.inner_mode, textAfter) + 4; + if (!state.inner_mode.indent) return CodeMirror.Pass; + return state.inner_mode.indent(state.inner_mode, textAfter) + 2; } else { - return 0; + return base_mode.indent(state.base_state, textAfter); } }, @@ -496,7 +512,8 @@ }, lineComment: "#", - fold: "indent" + fold: "indent", + electricInput: /^\s*[\}\]\)]$/, }; }; }, "python");