parent
4fb7ca5c53
commit
baede0a71c
25
context.py
25
context.py
|
@ -39,6 +39,22 @@ class Context(object):
|
||||||
if name and name in self.names:
|
if name and name in self.names:
|
||||||
del self.names[name]
|
del self.names[name]
|
||||||
self.namelines[y] = (None, None)
|
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):
|
def rebuild_name_map(self, y1, y2):
|
||||||
for y in range(y1, y2):
|
for y in range(y1, y2):
|
||||||
(name, info) = self.namelines[y]
|
(name, info) = self.namelines[y]
|
||||||
|
@ -47,12 +63,9 @@ class Context(object):
|
||||||
if y1 == 0:
|
if y1 == 0:
|
||||||
self._build_name_map(y1, y2, None, None, [])
|
self._build_name_map(y1, y2, None, None, [])
|
||||||
else:
|
else:
|
||||||
last, curr, stack = None, self.namelines[y1 - 1][0], []
|
last = self._regen_last(y1)
|
||||||
count = 0
|
curr = self._regen_curr(y1)
|
||||||
if curr:
|
stack = self._regen_stack(y1)
|
||||||
for part in curr.split('.'):
|
|
||||||
stack.append([count, part])
|
|
||||||
count += self.mode.tabwidth
|
|
||||||
self._build_name_map(y1, y2, last, curr, stack)
|
self._build_name_map(y1, y2, last, curr, stack)
|
||||||
|
|
||||||
def _build_name_map(self, y1, y2, last, curr, stack):
|
def _build_name_map(self, y1, y2, last, curr, stack):
|
||||||
|
|
|
@ -6,6 +6,18 @@ from point import Point
|
||||||
|
|
||||||
from method import DATATYPES, Method, Argument
|
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):
|
class DumpRegions(Method):
|
||||||
'''debug region highlighting'''
|
'''debug region highlighting'''
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
|
@ -25,7 +37,7 @@ class DumpMarkers(Method):
|
||||||
keys.sort()
|
keys.sort()
|
||||||
for i in keys:
|
for i in keys:
|
||||||
line = w.mode.tabber.lines[i]
|
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]))
|
lines.append(" %s" % repr(w.mode.tabber.record[i]))
|
||||||
else:
|
else:
|
||||||
lines.append("no tokens")
|
lines.append("no tokens")
|
||||||
|
@ -40,7 +52,7 @@ class DumpTokens(Method):
|
||||||
if modename in w.buffer.highlights:
|
if modename in w.buffer.highlights:
|
||||||
tokens = w.buffer.highlights[modename].tokens
|
tokens = w.buffer.highlights[modename].tokens
|
||||||
for i in range(0, len(tokens)):
|
for i in range(0, len(tokens)):
|
||||||
lines.append("LINE %d" % i)
|
lines.append("LINE %d" % i + 1)
|
||||||
group = tokens[i]
|
group = tokens[i]
|
||||||
for token in group:
|
for token in group:
|
||||||
fqname = token.fqname()
|
fqname = token.fqname()
|
||||||
|
|
40
mode/perl.py
40
mode/perl.py
|
@ -278,7 +278,7 @@ class PerlViewWordPerldoc(Method):
|
||||||
class PerlInitFunctions(Method):
|
class PerlInitFunctions(Method):
|
||||||
'''Jump to a function defined in this module'''
|
'''Jump to a function defined in this module'''
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
w.mode.build_function_map()
|
w.mode.context.build_name_map()
|
||||||
w.application.set_error("Initialized function map")
|
w.application.set_error("Initialized function map")
|
||||||
|
|
||||||
class PerlGotoFunction(Method):
|
class PerlGotoFunction(Method):
|
||||||
|
@ -519,32 +519,49 @@ class PerlFunctionCompleter(completer.Completer):
|
||||||
return [n for n in functions if n.startswith(s)]
|
return [n for n in functions if n.startswith(s)]
|
||||||
|
|
||||||
class PerlContext(context.Context):
|
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):
|
def _build_name_map(self, y1, y2, last, curr, stack):
|
||||||
blen = len(self.mode.window.buffer.lines)
|
blen = len(self.mode.window.buffer.lines)
|
||||||
highlights = self.mode.window.get_highlighter()
|
highlights = self.mode.window.get_highlighter()
|
||||||
i = y1
|
i = y1
|
||||||
|
#starting = False
|
||||||
|
starting = bool(stack)
|
||||||
while i < y2:
|
while i < y2:
|
||||||
g = highlights.tokens[i]
|
g = highlights.tokens[i]
|
||||||
if (not stack and len(g) > 2 and g[0].name == 'perl_keyword' and
|
if (not stack and len(g) > 2 and g[0].name == 'perl_keyword' and
|
||||||
g[0].string == 'sub' and g[2].name == 'sub'):
|
g[0].string == 'sub' and g[2].name == 'sub'):
|
||||||
curr = g[2].string
|
curr = g[2].string
|
||||||
self.names[curr] = i
|
self.names[curr] = i
|
||||||
|
starting = True
|
||||||
|
|
||||||
if i == y2 - 1 and curr != self.namelines[i][0] and y2 < blen:
|
if i == y2 - 1 and curr != self.namelines[i][0] and y2 < blen:
|
||||||
y2 += 1
|
y2 += 1
|
||||||
if curr:
|
#if curr:
|
||||||
self.namelines[i] = (curr, tuple(stack))
|
# self.namelines[i] = (curr, tuple(stack))
|
||||||
i += 1
|
|
||||||
|
|
||||||
m = self.mode
|
m = self.mode
|
||||||
for t in g:
|
for t in g:
|
||||||
if t.name in m.opentokens and t.string in m.opentags:
|
if t.name in m.opentokens and t.string in m.opentags:
|
||||||
stack.append(t.string)
|
stack.append(t.string)
|
||||||
|
if(t.string == '{'):
|
||||||
|
starting = False
|
||||||
elif t.name in m.closetokens and t.string in m.closetags:
|
elif t.name in m.closetokens and t.string in m.closetags:
|
||||||
if stack and stack[-1] == m.closetags[t.string]:
|
#assert stack and stack[-1] == m.closetags[t.string]:
|
||||||
stack.pop(-1)
|
stack.pop(-1)
|
||||||
if t.string == '}' and not stack:
|
if not starting and not stack:
|
||||||
curr = None
|
curr = None
|
||||||
|
if curr:
|
||||||
|
self.namelines[i] = (curr, tuple(stack))
|
||||||
|
i += 1
|
||||||
|
|
||||||
class Perl(mode.Fundamental):
|
class Perl(mode.Fundamental):
|
||||||
modename = 'Perl'
|
modename = 'Perl'
|
||||||
|
@ -656,7 +673,8 @@ class Perl(mode.Fundamental):
|
||||||
completers = {
|
completers = {
|
||||||
'perlfunction': PerlFunctionCompleter(),
|
'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):
|
def get_status_names(self):
|
||||||
w = self.window
|
w = self.window
|
||||||
c = w.logical_cursor()
|
c = w.logical_cursor()
|
||||||
|
@ -667,7 +685,7 @@ class Perl(mode.Fundamental):
|
||||||
'perc': self._get_perc(),
|
'perc': self._get_perc(),
|
||||||
'cursor': '(%d,%d)' % (c.y + 1, c.x + 1),
|
'cursor': '(%d,%d)' % (c.y + 1, c.x + 1),
|
||||||
'mark': self._get_mark(),
|
'mark': self._get_mark(),
|
||||||
'func': self.get_line_function(c.y),
|
#'func': self.get_line_function(c.y),
|
||||||
}
|
}
|
||||||
return names
|
return names
|
||||||
def __init__(self, w):
|
def __init__(self, w):
|
||||||
|
@ -685,7 +703,7 @@ class Perl(mode.Fundamental):
|
||||||
self.add_bindings('close-paren', (')'))
|
self.add_bindings('close-paren', (')'))
|
||||||
self.add_bindings('close-bracket', (']'))
|
self.add_bindings('close-bracket', (']'))
|
||||||
self.add_bindings('close-brace', ('}'))
|
self.add_bindings('close-brace', ('}'))
|
||||||
self.context = PerlContext(self)
|
#self.context = PerlContext(self)
|
||||||
self.functions = None
|
self.functions = None
|
||||||
self.funclines = None
|
self.funclines = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue