diff --git a/mode/javascript.py b/mode/javascript.py index 99d1087..58d4c28 100644 --- a/mode/javascript.py +++ b/mode/javascript.py @@ -67,6 +67,7 @@ class JavascriptGrammar(Grammar): ] class JavascriptTabber2(tab.StackTabber2): + fixed_indent = True open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}} close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}} control_tokens = {'js.keyword': {'if': 1, 'else': 1, 'while': 1, @@ -118,6 +119,7 @@ class JavascriptTagManager(TagManager): class Javascript(Fundamental): name = 'Javascript' extensions = ['.js', '.json'] + tabwidth = 2 grammar = JavascriptGrammar tabbercls = JavascriptTabber2 tagcls = JavascriptTagManager diff --git a/tab.py b/tab.py index 5782950..0fc329e 100644 --- a/tab.py +++ b/tab.py @@ -384,8 +384,23 @@ class StackTabber2(Tabber): raise Exception, msg % (t.string, y, s) else: raise Exception, "what? %r (%r)" % (marker, t) + + # if we start a line with a closing token (e.g. "}") we may want to + # shift the indentation left to "close" the indent. if we're using + # fixed indentation then we may want to do this shift multiple times + # (e.g. "})"). if i == 0: self._save_curr_level() + elif self.fixed_indent: + all_closed = True + for j in xrange(0, i): + if self._is_ignored(tokens[j]) or self._is_close_token(tokens[j]): + pass + else: + all_closed = False + break + if all_closed: + self._save_curr_level() # if we need to end at eof and we're at the EOF and we have a control # token, then we need to pop it.