From cec50f0ad727be49011ab20bbefeb2ea99ebce5f Mon Sep 17 00:00:00 2001 From: moculus Date: Tue, 26 Jun 2007 22:45:27 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- window2.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/window2.py b/window2.py index d60e978..b3a1880 100644 --- a/window2.py +++ b/window2.py @@ -517,8 +517,6 @@ class Window(object): def point_char(self, p): return self.xy_char(p.x, p.y) def xy_char(self, x, y): - #assert 0 <= y and y < len(self.buffer.lines) - #assert 0 <= x and x <= len(self.buffer.lines[y]) if x == len(self.buffer.lines[y]): return "\n" else: @@ -534,3 +532,25 @@ class Window(object): self.buffer.redo() # highlighting tokens + def get_next_token_by_lambda(self, p, f): + for token in self.get_highlighter().tokens[p.y]: + if token.x < p.x: + continue + if f(token.name): + return token + return None + def get_next_token_by_type(self, p, name): + return self.get_next_token_by_lambda(p, lambda t: t.name == name) + def get_next_token_except_type(self, p, name): + return self.get_next_token_by_lambda(p, lambda t: t.name != name) + def get_next_token_by_type_regex(self, p, name, regex): + l = lambda t: t.name == name and regex.match(t.string) + return self.get_next_token_by_lambda(p, l) + def get_next_token_except_type_regex(self, p, name, regex): + l = lambda t: t.name != name or regex.match(t.string) + return self.get_next_token_by_lambda(p, l) + + def get_next_token_by_types(self, p, *names): + return self.get_next_token_by_lambda(p, lambda t: t.name in names) + def get_next_token_except_types(self, p, *names): + return self.get_next_token_by_lambda(p, lambda t: t.name not in names)