From 61d34834de26903a5bd3b724c84b6fb3a03438fc Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Thu, 13 Sep 2012 22:32:48 -0600 Subject: [PATCH] more indentation fixes --HG-- branch : pmacs2 --- mode/scala.py | 7 ++++--- tab.py | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/mode/scala.py b/mode/scala.py index dc2347b..5bb408e 100644 --- a/mode/scala.py +++ b/mode/scala.py @@ -31,9 +31,10 @@ class StringGrammar(Grammar): class SubTypeGrammar(Grammar): pass SubTypeGrammar.rules = [ RegionRule('sub', r'\[', SubTypeGrammar, r'\]'), - PatternRule('scala.type', '[A-Z][a-zA-Z0-9_.]*'), + PatternRule('scala.type', '[a-zA-Z_][a-zA-Z0-9_.#]*'), PatternRule('spaces', ' +'), - PatternRule('scala.annotation', '@[a-zA-Z_][a-zA-Z0-9_]*'), + PatternRule('delimiter', r'(?:;|=>|{|}|\(|\)|,|\.|<(?![a-zA-Z_])|>|:|/|\+|-|\*|=|#)'), + PatternRule('scala.annotation', '@[a-zA-Z_][a-zA-Z0-9_.]*'), RegionRule('scala.string', '"', StringGrammar, '"'), ] @@ -66,7 +67,7 @@ class ScalaGrammar(Grammar): RegionRule('sub', r'\[', SubTypeGrammar, r'\]'), # match various scala delimiters and operators - PatternRule('delimiter', r'(?:;|=>|{|}|\(|\)|,|\.|<(?![a-zA-Z_])|>|:|/|\+|-|\*|=)'), + PatternRule('delimiter', r'(?:;|=>|{|}|\(|\)|,|\.|<(?![a-zA-Z_])|>|:|/|\+|-|\*|=|#)'), # semi-hack to support XML RegionRule('scala.inline', r'(?:^| )(?=<[a-zA-Z_])', XMLGrammar, '^[ \t]*$'), diff --git a/tab.py b/tab.py index 2fd5774..fed1fce 100644 --- a/tab.py +++ b/tab.py @@ -375,6 +375,11 @@ class StackTabber2(Tabber): marker = self.stack[-1] if marker.name in ('control', 'continue', 'pre-control'): self.stack.pop() + elif marker.name == 'case': + if t.string in self.close_scope_tokens.get(t.fqname(), empty): + self.stack.pop() + else: + break elif marker.name in self.open_tokens.get(marker.type_, empty): s = self.open_tokens[marker.type_][marker.name] if s in (None, t.string): @@ -454,12 +459,16 @@ class StackTabber2(Tabber): else: self.stack.pop() - if t.string in self.open_scope_tokens.get(t.name, empty): + open_scope = t.string in self.open_scope_tokens.get(t.name, empty) + + if open_scope: self._pop('continue', 'control') - if i == 0 and t.string in self.open_scope_tokens.get(t.name, empty): - self._save_curr_level() - - if i == end - start or self.fixed_indent: + if i == 0: + self._save_curr_level() + + if not open_scope and self.stack and self._peek().name == 'case': + level = self._get_curr_level() + elif i == end - start or self.fixed_indent: level = self._get_next_level() else: level = tokens[i + 1].x