From 4ea1f53a4639c9381fcd0eed629f455064e370c3 Mon Sep 17 00:00:00 2001 From: Erik Osheim Date: Tue, 7 Jul 2009 12:22:49 -0400 Subject: [PATCH] improve python's goto-name support --HG-- branch : pmacs2 --- mode/python.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mode/python.py b/mode/python.py index 7bb02bf..f053119 100644 --- a/mode/python.py +++ b/mode/python.py @@ -486,6 +486,7 @@ class PythonContext(context.Context): blen = len(self.mode.window.buffer.lines) highlights = self.mode.window.get_highlighter() i = y1 + abbrev = {} while i < y2: tokens = highlights.tokens[i] g = highlights.tokens[i] @@ -511,16 +512,22 @@ class PythonContext(context.Context): last = None if len(g[j:]) > 3: - d, found = None, False + found = False if g[j].name == 'python.keyword' and g[j].string == 'class': - d, found = self.classes, True + found = True elif g[j].name == 'python.keyword' and g[j].string == 'def': - d, found = self.functions, True + found = True if found: stack.append([lvl, g[j+2].string]) - curr = '.'.join([x[1] for x in stack]) - d[curr] = i + curr = '.'.join([x[1] for x in stack]) self.names[curr] = i + + for k in range(1, len(stack)): + curr = '.'.join(x[1] for x in stack[k:]) + if curr not in abbrev: + abbrev[curr] = i + else: + abbrev[curr] = None else: curr = '.'.join([x[1] for x in stack]) @@ -530,6 +537,10 @@ class PythonContext(context.Context): self.namelines[i] = (curr, None) i += 1 + for name in abbrev: + if abbrev[name] is not None: + self.names[name] = abbrev[name] + if last is not None and y2 < len(self.namelines): if self.namelines[y2] and self.namelines[y2][0]: n = len(self.namelines[y2][0].split('.'))