branch : pmacs2
This commit is contained in:
moculus 2007-06-26 22:45:27 +00:00
parent 4434f68347
commit cec50f0ad7
1 changed files with 22 additions and 2 deletions

View File

@ -517,8 +517,6 @@ class Window(object):
def point_char(self, p): def point_char(self, p):
return self.xy_char(p.x, p.y) return self.xy_char(p.x, p.y)
def xy_char(self, x, 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]): if x == len(self.buffer.lines[y]):
return "\n" return "\n"
else: else:
@ -534,3 +532,25 @@ class Window(object):
self.buffer.redo() self.buffer.redo()
# highlighting tokens # 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)