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('.'))