From 6a3002fa6c585b85f0a080bf1e26d42d8c5f50fa Mon Sep 17 00:00:00 2001 From: moculus Date: Wed, 22 Oct 2008 22:25:45 +0000 Subject: [PATCH] tab errors --HG-- branch : pmacs2 --- mode/python.py | 2 +- tab.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/mode/python.py b/mode/python.py index 3a0350f..5cb0544 100644 --- a/mode/python.py +++ b/mode/python.py @@ -179,7 +179,7 @@ class PythonTabber(tab.StackTabber): self._append(token.string, currlvl + w) elif token.string in ('elif', 'else') and self.is_leftmost_token(y, i): # we know we'll unindent at least to the first if/elif - if not self.popped and not self.last_popped: + if not self.popped and not self.last_popped and self._peek_until('if', 'elif'): self._pop_until('if', 'elif') currlvl = self.get_curr_level() self._append(token.string, currlvl + w) diff --git a/tab.py b/tab.py index 6ec719c..d8a8403 100644 --- a/tab.py +++ b/tab.py @@ -188,6 +188,13 @@ class StackTabber(Tabber): return self.markers[-1] else: return None + def _peek_until(self, *names): + for i in range(1, len(self.markers) + 1): + x = self.markers[-i] + if x.name in names: + return x + return None + def _peek_name(self): if self.markers: return self.markers[-1].name @@ -310,6 +317,12 @@ class StackTabber2(Tabber): return self.stack[-1] else: return None + def _peek_until(self, *names): + for i in range(1, len(self.stack) + 1): + x = self.stack[-i] + if x.name in names: + return x + return None def _get_tokens(self, y): return self.mode.window.buffer.highlights[self.name].tokens[y]