From 6ea87b87e48ecde2264dfdcfcd9cad8bdc85a3bd Mon Sep 17 00:00:00 2001 From: moculus Date: Sat, 11 Apr 2009 04:39:34 +0000 Subject: [PATCH] app improvement and small python stuff --HG-- branch : pmacs2 --- application.py | 45 +++++++++++++++++++-------------------------- mode/python.py | 37 ++++++++++++++----------------------- 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/application.py b/application.py index 836ed4e..ce6d73a 100755 --- a/application.py +++ b/application.py @@ -703,19 +703,29 @@ class Application(object): self.try_manual_resize() - # NOTE: this is totally broken - def map_point(self, w, p): - count = 0 - x, y = w.first.xy() + # NOTE: this is taken from the cursor code + def map_point(self, slot, p): + w = slot.window + swidth = slot.width - w.mode.lmargin - w.mode.rmargin + blen = len(w.buffer.lines) + count = w.mode.header + (x, y) = w.first.xy() + (vy, vx) = (None, None) while count < slot.height: - if p1.y == y and p1.x >= x and p1.x - x < slot.width: - return (count, x) - if x + slot.width > len(w.buffer.lines[y]): + if p.y == y and p.x >= x and p.x <= x + swidth: + vy, vx = slot.y_offset + count, p.x - x + w.mode.lmargin + if vx == swidth and p.x < len(w.buffer.lines[y]): + vx = 0 + vy += 1 + break + + if y >= blen or x + swidth >= len(w.buffer.lines[y]): x = 0 y += 1 else: - x += slot.width + x += swidth count += 1 + return vx, vy def draw_cursor(self): if self.mini_active: @@ -741,24 +751,7 @@ class Application(object): else: p = w.logical_cursor() - blen = len(w.buffer.lines) - count = w.mode.header - (x, y) = w.first.xy() - (vy, vx) = (None, None) - while count < slot.height: - if p.y == y and p.x >= x and p.x <= x + swidth: - vy, vx = slot.y_offset + count, p.x - x + w.mode.lmargin - if vx == swidth and p.x < len(w.buffer.lines[y]): - vx = 0 - vy += 1 - break - - if y >= blen or x + swidth >= len(w.buffer.lines[y]): - x = 0 - y += 1 - else: - x += swidth - count += 1 + vx, vy = self.map_point(slot, p) if vy is None or vx is None: return try: diff --git a/mode/python.py b/mode/python.py index a4564ec..0440ab7 100644 --- a/mode/python.py +++ b/mode/python.py @@ -41,9 +41,9 @@ class PythonGrammar(Grammar): rules = [ PatternRule(r'functionname', r'(?<=def )[a-zA-Z_][a-zA-Z0-9_]*'), PatternRule(r'classname', r'(?<=class )[a-zA-Z_][a-zA-Z0-9_]*'), - PatternRule(r'python_reserved', r'(?:True|None|False|Exception|self)(?![a-zA-Z0-9_])'), - PatternRule(r'python_keyword', r'(?:yield|while|try|return|raise|print|pass|or|not|lambda|is|in|import|if|global|from|for|finally|exec|except|else|elif|del|def|continue|class|break|assert|as|and)(?![a-zA-Z0-9_])'), - PatternRule(r"python_builtin", r'(? 3: d, found = None, False - if g[j].name == 'python_keyword' and g[j].string == 'class': + if g[j].name == 'python.keyword' and g[j].string == 'class': d, found = self.classes, True - elif g[j].name == 'python_keyword' and g[j].string == 'def': + elif g[j].name == 'python.keyword' and g[j].string == 'def': d, found = self.functions, True if found: stack.append([lvl, g[j+2].string]) @@ -565,9 +556,9 @@ class Python(mode.Fundamental): closetags = {')': '(', ']': '[', '}': '{'} commentc = '#' colors = { - 'python_keyword': ('cyan', 'default', 'bold'), - 'python_reserved': ('magenta', 'default', 'bold'), - 'python_builtin': ('cyan', 'default', 'bold'), + 'python.keyword': ('cyan', 'default', 'bold'), + 'python.reserved': ('magenta', 'default', 'bold'), + 'python.builtin': ('cyan', 'default', 'bold'), 'functionname': ('blue', 'default', 'bold'), 'classname': ('green', 'default', 'bold'), 'rawstring.start': ('green', 'default', 'bold'),