app improvement and small python stuff

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-04-11 04:39:34 +00:00
parent e800135795
commit 6ea87b87e4
2 changed files with 33 additions and 49 deletions

View File

@ -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:

View File

@ -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'(?<!\.)(?:zip|xrange|vars|unicode|unichr|type|tuple|super|sum|str|staticmethod|sorted|slice|setattr|set|round|repr|reduce|raw_input|range|property|pow|ord|open|oct|object|max|min|map|long|locals|list|len|iter|issubclass|isinstance|int|input|id|hex|hash|hasattr|globals|getattr|frozenset|float|filter|file|execfile|eval|enumerate|divmod|dir|dict|delattr|complex|compile|coerce|cmp|classmethod|chr|callable|bool)(?![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'(?<!\.)(?:zip|xrange|vars|unicode|unichr|type|tuple|super|sum|str|staticmethod|sorted|slice|setattr|set|round|repr|reduce|raw_input|range|property|pow|ord|open|oct|object|max|min|map|long|locals|list|len|iter|issubclass|isinstance|int|input|id|hex|hash|hasattr|globals|getattr|frozenset|float|filter|file|execfile|eval|enumerate|divmod|dir|dict|delattr|complex|compile|coerce|cmp|classmethod|chr|callable|bool)(?![a-zA-Z0-9_])'),
PatternRule(r'methodcall', r'(?<=\. )[a-zA-Z_][a-zA-Z0-9_]*(?= *\()'),
PatternRule(r'functioncall', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\()'),
PatternRule(r'system_identifier', r'__[a-zA-Z0-9_]+__'),
@ -76,7 +76,7 @@ class PythonGrammar(Grammar):
class PythonTabber(tab.StackTabber):
# NOTE: yield might initially seem like an endlevel name, but it's not one.
# NOTE: return should be an endlevel name but for now it can't b
# NOTE: return should be an endlevel name but for now it can't be one.
endlevel_names = ('pass', 'raise', 'break', 'continue')
startlevel_names = ('if', 'try', 'class', 'def', 'for', 'while', 'try')
def __init__(self, m):
@ -88,9 +88,8 @@ class PythonTabber(tab.StackTabber):
# we always know that line 0 is indented at the 0 level
return True
tokens = self.get_tokens(y)
t0 = tokens[0]
if t0.name == 'python_keyword' and t0.string in self.startlevel_names:
# if a line has no whitespace and beings with something like
if tokens[0].matchs('python.keyword', self.startlevel_names):
# if a line has no whitespace and begins with something like
# 'while','class','def','if',etc. then we can start at it
return True
else:
@ -175,7 +174,7 @@ class PythonTabber(tab.StackTabber):
pass
else:
self._pop()
elif fqname == 'python_keyword':
elif fqname == 'python.keyword':
s = token.string
if s in self.endlevel_names and self.is_leftmost_token(y, i):
# we know we'll unindent at least once
@ -435,22 +434,14 @@ class PythonClassCompleter(completer.Completer):
def _get_dict(self, w):
return w.buffer.method.old_window.mode.context.get_classes()
CLASS_MATCH = And(Optional(Name('spaces')),
Matchs('python_keyword', ('public', 'protected', 'private')),
Name('spaces'),
Match('keyword', 'class'),
Name('spaces'),
Name('identifier'))
CLASS_OFFSET = 1
class PythonContext(context.Context):
empty_match = And(Optional(Name('spaces')), Name('eol'))
class_match = And(Optional(Name('spaces')),
Match('python_keyword', 'class'),
Match('python.keyword', 'class'),
Name('spaces'),
Name('classname'))
func_match = And(Optional(Name('spaces')),
Match('python_keyword', 'def'),
Match('python.keyword', 'def'),
Name('spaces'),
Name('functionname'))
def __init__(self, mode):
@ -519,9 +510,9 @@ class PythonContext(context.Context):
if len(g[j:]) > 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'),