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