branch : pmacs2
This commit is contained in:
moculus 2008-05-12 22:12:56 +00:00
parent 4fb7ca5c53
commit baede0a71c
3 changed files with 62 additions and 19 deletions

View File

@ -39,6 +39,22 @@ class Context(object):
if name and name in self.names:
del self.names[name]
self.namelines[y] = (None, None)
def _regen_curr(self, y):
return self.namelines[y - 1][0]
def _regen_last(self, y):
return None
def _regen_stack(self, y):
assert y > 0
stack = []
curr = self.namelines[y - 1][0]
count = 0
if curr:
for part in curr.split('.'):
stack.append([count, part])
count += self.mode.tabwidth
return stack
def rebuild_name_map(self, y1, y2):
for y in range(y1, y2):
(name, info) = self.namelines[y]
@ -47,12 +63,9 @@ class Context(object):
if y1 == 0:
self._build_name_map(y1, y2, None, None, [])
else:
last, curr, stack = None, self.namelines[y1 - 1][0], []
count = 0
if curr:
for part in curr.split('.'):
stack.append([count, part])
count += self.mode.tabwidth
last = self._regen_last(y1)
curr = self._regen_curr(y1)
stack = self._regen_stack(y1)
self._build_name_map(y1, y2, last, curr, stack)
def _build_name_map(self, y1, y2, last, curr, stack):

View File

@ -6,6 +6,18 @@ from point import Point
from method import DATATYPES, Method, Argument
class DumpContext(Method):
'''debug context'''
def _execute(self, w, **vargs):
lines = []
if w.mode.context:
for i in range(0, len(w.mode.context.namelines)):
lines.append("LINE %d: %r" % (i + 1, repr(w.mode.context.namelines[i])))
else:
lines.append("no context")
output = "\n".join(lines)
w.application.data_buffer("context-dump", output, switch_to=True)
class DumpRegions(Method):
'''debug region highlighting'''
def _execute(self, w, **vargs):
@ -25,7 +37,7 @@ class DumpMarkers(Method):
keys.sort()
for i in keys:
line = w.mode.tabber.lines[i]
lines.append("LINE %d: %r" % (i, line))
lines.append("LINE %d: %r" % (i + 1, line))
lines.append(" %s" % repr(w.mode.tabber.record[i]))
else:
lines.append("no tokens")
@ -40,7 +52,7 @@ class DumpTokens(Method):
if modename in w.buffer.highlights:
tokens = w.buffer.highlights[modename].tokens
for i in range(0, len(tokens)):
lines.append("LINE %d" % i)
lines.append("LINE %d" % i + 1)
group = tokens[i]
for token in group:
fqname = token.fqname()

View File

@ -278,7 +278,7 @@ class PerlViewWordPerldoc(Method):
class PerlInitFunctions(Method):
'''Jump to a function defined in this module'''
def _execute(self, w, **vargs):
w.mode.build_function_map()
w.mode.context.build_name_map()
w.application.set_error("Initialized function map")
class PerlGotoFunction(Method):
@ -519,32 +519,49 @@ class PerlFunctionCompleter(completer.Completer):
return [n for n in functions if n.startswith(s)]
class PerlContext(context.Context):
def _regen_stack(self, y):
if y > 0:
if self.namelines[y - 1][1]:
return list(self.namelines[y - 1][1])
else:
#xyz
return []
else:
return []
def _build_name_map(self, y1, y2, last, curr, stack):
blen = len(self.mode.window.buffer.lines)
highlights = self.mode.window.get_highlighter()
i = y1
#starting = False
starting = bool(stack)
while i < y2:
g = highlights.tokens[i]
if (not stack and len(g) > 2 and g[0].name == 'perl_keyword' and
g[0].string == 'sub' and g[2].name == 'sub'):
curr = g[2].string
self.names[curr] = i
starting = True
if i == y2 - 1 and curr != self.namelines[i][0] and y2 < blen:
y2 += 1
if curr:
self.namelines[i] = (curr, tuple(stack))
i += 1
#if curr:
# self.namelines[i] = (curr, tuple(stack))
m = self.mode
for t in g:
if t.name in m.opentokens and t.string in m.opentags:
stack.append(t.string)
if(t.string == '{'):
starting = False
elif t.name in m.closetokens and t.string in m.closetags:
if stack and stack[-1] == m.closetags[t.string]:
stack.pop(-1)
if t.string == '}' and not stack:
curr = None
#assert stack and stack[-1] == m.closetags[t.string]:
stack.pop(-1)
if not starting and not stack:
curr = None
if curr:
self.namelines[i] = (curr, tuple(stack))
i += 1
class Perl(mode.Fundamental):
modename = 'Perl'
@ -656,7 +673,8 @@ class Perl(mode.Fundamental):
completers = {
'perlfunction': PerlFunctionCompleter(),
}
format = "%(flag)s %(bname)-18s (%(mname)s) %(cursor)s/%(mark)s %(perc)s [%(func)s]"
#format = "%(flag)s %(bname)-18s (%(mname)s) %(cursor)s/%(mark)s %(perc)s [%(func)s]"
format = "%(flag)s %(bname)-18s (%(mname)s) %(cursor)s/%(mark)s %(perc)s"
def get_status_names(self):
w = self.window
c = w.logical_cursor()
@ -667,7 +685,7 @@ class Perl(mode.Fundamental):
'perc': self._get_perc(),
'cursor': '(%d,%d)' % (c.y + 1, c.x + 1),
'mark': self._get_mark(),
'func': self.get_line_function(c.y),
#'func': self.get_line_function(c.y),
}
return names
def __init__(self, w):
@ -685,7 +703,7 @@ class Perl(mode.Fundamental):
self.add_bindings('close-paren', (')'))
self.add_bindings('close-bracket', (']'))
self.add_bindings('close-brace', ('}'))
self.context = PerlContext(self)
#self.context = PerlContext(self)
self.functions = None
self.funclines = None