         else 'apl-glb'
       else 'apl-err'
 
-  electricInput: /(?::else|:end|:andif|:orif|:case|\})$/
+  electricInput: /(?::else|:end|:andif|:orif|:case|\})$/ # when the user enters one of these, a re-indent is triggered
 
   indent: (state, textAfter) ->
-    state.indentStack[state.indentStack.length - 1] + config.indentUnit * !(
-      if state.dfnDepth then /^\s*\}/.test textAfter
-      else /^\s*:(?:end|else|andif|orif|case)/i.test textAfter
-    )
+    re = if state.dfnDepth then /^\s*\}/ else /^\s*:(?:end|else|andif|orif|case)/i
+    state.inds[-1..][0] + config.indentUnit * !re.test textAfter

{qw} = require './util'

letter = @letter = 'A-Z_a-zÀ-ÖØ-Ýß-öø-üþ∆⍙Ⓐ-Ⓩ'
name0 = ///[#{letter}]///

      else if c == '←' then 'apl-asgn'
      else if c == "'" then (if stream.match /^(?:[^'\r\n]|'')*'/ then 'apl-str' else stream.skipToEnd(); 'apl-err')
      else if c == '⍬' then 'apl-zld'
      else if c == '(' then state.brs += c; 'apl-par'
      else if c == '[' then state.brs += c; 'apl-sqbr'
      else if c == '{' then state.brs += c; state.inds.push stream.indentation(); "apl-dfn#{++state.dfnDepth} apl-dfn"
      else if c == ')' then (if state.brs[-1..] == '(' then state.brs = state.brs[...-1]; 'apl-par'  else 'apl-err')
      else if c == ']' then (if state.brs[-1..] == '[' then state.brs = state.brs[...-1]; 'apl-sqbr' else 'apl-err')
      else if c == '}'
        if state.brs[-1..] == '{'
          state.brs = state.brs[...-1]; state.inds.pop(); "apl-dfn apl-dfn#{state.dfnDepth--}"
        else
          'apl-err'
      else if c == ';' then 'apl-semi'
