branch : pmacs2
This commit is contained in:
moculus 2008-05-08 06:57:23 +00:00
parent 7c07ed1e3b
commit 7f7143c491
1 changed files with 11 additions and 10 deletions

View File

@ -303,18 +303,12 @@ class PerlWhichFunction(Method):
'''Show the user what function they are in''' '''Show the user what function they are in'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
cursor = w.logical_cursor() cursor = w.logical_cursor()
i = cursor.y name = w.mode.get_line_function(cursor.y)
name = None
while i >= 0 and name is None:
line = w.buffer.lines[i]
m = regex.perl_function.match(line)
if m:
name = m.group(1)
else:
i -= 1
if name is None: if name is None:
w.application.set_error("None"); w.application.set_error("None");
else: else:
functions = w.mode.get_functions()
i = functions[name] + 1
w.application.set_error("line %d: %s" % (i, name)) w.application.set_error("line %d: %s" % (i, name))
class PerlHashCleanup(Method): class PerlHashCleanup(Method):
@ -710,6 +704,7 @@ class Perl(mode.Fundamental):
self.add_bindings('close-bracket', (']')) self.add_bindings('close-bracket', (']'))
self.add_bindings('close-brace', ('}')) self.add_bindings('close-brace', ('}'))
self.functions = None self.functions = None
self.funclines = None
def build_function_map(self): def build_function_map(self):
self.functions = {} self.functions = {}
@ -717,6 +712,7 @@ class Perl(mode.Fundamental):
highlights = self.window.get_highlighter() highlights = self.window.get_highlighter()
curr, stack = None, [] curr, stack = None, []
for group in highlights.tokens: for group in highlights.tokens:
self.funclines.append(curr)
for t in group: for t in group:
if not curr and t.name == 'sub': if not curr and t.name == 'sub':
curr = t.string curr = t.string
@ -729,7 +725,8 @@ class Perl(mode.Fundamental):
stack.pop() stack.pop()
if not stack: if not stack:
curr = None curr = None
self.funclines.append(curr) if curr:
self.funclines[-1] = curr
def get_functions(self): def get_functions(self):
if self.functions is None: if self.functions is None:
@ -741,5 +738,9 @@ class Perl(mode.Fundamental):
pairs.sort() pairs.sort()
names = [x[1] for x in pairs] names = [x[1] for x in pairs]
return names return names
def get_line_function(self, y):
if self.funclines is None:
self.build_function_map()
return self.funclines[y]
install = Perl.install install = Perl.install