From 482ef39720148110a779bcf1c811ab97b6c3d8f1 Mon Sep 17 00:00:00 2001 From: moculus Date: Tue, 3 Feb 2009 19:16:38 +0000 Subject: [PATCH] fixed super annoying long-line bug --HG-- branch : pmacs2 --- BUGS | 2 ++ application.py | 11 ++++++++--- mode/java.py | 42 +++++++++++++++++++++++++----------------- mode/python.py | 4 +++- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/BUGS b/BUGS index 0f091c2..12707ef 100644 --- a/BUGS +++ b/BUGS @@ -13,6 +13,7 @@ 2008/06/25: * occasionally when the "first" point is wrapped things get confused. + (fixed 2009/02/03) * the "last visible" calculation doesn't handle long lines correctly. this affects page-up/page-down/etc. @@ -29,6 +30,7 @@ 2008/05/03: first-visible/cursor syncing with drawn window may be buggy. + (fixed 2009/02/03) 2007/09/14: known deficiencies: diff --git a/application.py b/application.py index 3489bbc..f1a325c 100755 --- a/application.py +++ b/application.py @@ -1,5 +1,6 @@ #!/usr/bin/env python import curses, curses.ascii, getpass, os, re, string, sys, termios, time +import math import traceback from subprocess import Popen, PIPE, STDOUT @@ -715,6 +716,9 @@ class Application(object): 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]): @@ -828,15 +832,16 @@ class Application(object): lm, rm = w.mode.lmargin, w.mode.rmargin lines = w.buffer.lines count = w.mode.header - k = x // (slot.width - lm - rm) + swidth = slot.width - lm - rm + k = (x + swidth - 1) // swidth modename = w.mode.name() lit = w.mode.name() in w.buffer.highlights ended = False while count < slot.height: if lit: - rlines = w.render_line_lit(y, slot.width - lm - rm) + rlines = w.render_line_lit(y, swidth) else: - rlines = w.render_line_raw(y, slot.width - lm - rm) + rlines = w.render_line_raw(y, swidth) for j in range(k, len(rlines)): if lm: lcont = j > 0 diff --git a/mode/java.py b/mode/java.py index a1b71cd..75df4c9 100644 --- a/mode/java.py +++ b/mode/java.py @@ -37,6 +37,25 @@ class JavaGrammar(Grammar): PatternRule(r"eol", r"\n$"), ] + +CLASS_MATCH = And(Optional(Name('spaces')), + Matchs('keyword', ('public', 'protected', 'private')), + Name('spaces'), + Match('keyword', 'class'), + Name('spaces'), + Name('identifier')) +CLASS_OFFSET = 1 +METHOD_MATCH = And(Optional(Name('spaces')), + Matchs('keyword', ('public', 'protected', 'private')), + Name('spaces'), + Optional(And(Match('keyword', 'static'), Name('spaces'))), + Any(), + Name('spaces'), + Name('identifier'), + Optional(Name('spaces')), + Match('delimiter', '(')) +METHOD_OFFSET = 2 + class JavaTabber2(tab.StackTabber2): open_tokens = {'delimiter': {'{': '}', '(': ')', '[': ']'}} close_tokens = {'delimiter': {'}': '{', ')': '(', ']': '['}} @@ -61,23 +80,10 @@ class JavaTabber2(tab.StackTabber2): 'comment.data', 'comment.null', 'comment.end') class JavaContext(context.Context): - class_match = And(Optional(Name('spaces')), - Matchs('keyword', ('public', 'protected', 'private')), - Name('spaces'), - Match('keyword', 'class'), - Name('spaces'), - Name('identifier')) - class_offset = 1 - method_match = And(Optional(Name('spaces')), - Matchs('keyword', ('public', 'protected', 'private')), - Name('spaces'), - Optional(And(Match('keyword', 'static'), Name('spaces'))), - Any(), - Name('spaces'), - Name('identifier'), - Optional(Name('spaces')), - Match('delimiter', '(')) - method_offset = 2 + class_match = CLASS_MATCH + class_offset = CLASS_OFFSET + method_match = METHOD_MATCH + method_offset = METHOD_OFFSET def _regen_stack(self, y): if y > 0 and self.namelines[y - 1][1]: return list(self.namelines[y - 1][1]) @@ -149,10 +155,12 @@ class Java(mode.Fundamental): } format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(func)s]" + #format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(first)s %(perc)s [%(func)s]" def get_status_names(self): names = mode.Fundamental.get_status_names(self) c = self.window.logical_cursor() names['func'] = self.get_line_function(c.y) + #names['first'] = self.window.first.xy() return names def __init__(self, w): diff --git a/mode/python.py b/mode/python.py index a1bb916..55a8ff1 100644 --- a/mode/python.py +++ b/mode/python.py @@ -545,12 +545,14 @@ class Python(mode.Fundamental): "pythonclass": PythonClassCompleter(None), } - format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(name)s]" + #format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(mark)s %(perc)s [%(name)s]" + format = "%(flag)s %(bname)-18s (%(mname)s) %(indent)s %(cursor)s/%(first)s %(perc)s [%(name)s]" def get_status_names(self): names = mode.Fundamental.get_status_names(self) c = self.window.logical_cursor() names['name'] = self.context.get_line_name(c.y) + names['first'] = self.window.first.xy() return names def __init__(self, w):