From 54c303e07f1a9a721d9e96827e21d419a7e29aa3 Mon Sep 17 00:00:00 2001 From: moculus Date: Mon, 14 Apr 2008 18:27:23 +0000 Subject: [PATCH] improved python console --HG-- branch : pmacs2 --- mode/consolemini.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mode/consolemini.py b/mode/consolemini.py index e143811..c8e9062 100644 --- a/mode/consolemini.py +++ b/mode/consolemini.py @@ -1,4 +1,4 @@ -import code, re, string, StringIO, sys, traceback +import code, re, string, StringIO, sets, sys, traceback import color, completer, lex, method, mode from lex import Grammar, PatternRule from mode.python import PythonGrammar @@ -140,11 +140,14 @@ class ConsoleTab(method.Method): def execute(self, w, **vargs): a = w.application s = w.buffer.make_string() - l = lex.Lexer(w.mode, PythonGrammar) - tokens = list(l.lex([s])) x = w.logical_cursor().x - #raise Exception, repr(x) + if not s or s[:x].isspace(): + w.insert_string_at_cursor(' ' * w.mode.tabwidth) + return + + l = lex.Lexer(w.mode, PythonGrammar) + tokens = list(l.lex([s])) curr_t = None curr_i = None @@ -154,7 +157,6 @@ class ConsoleTab(method.Method): curr_i = i curr_t = t if curr_t is None: - #raise Exception, 'not found: %r %r' % (x, tokens) return first_t = curr_t @@ -172,6 +174,7 @@ class ConsoleTab(method.Method): else: break + #raise Exception, repr(names) obj = None g = globals() i = 0 @@ -191,8 +194,15 @@ class ConsoleTab(method.Method): else: break i += 1 - if obj is not None and i == len(names) - 1: - newnames = dir(obj) + + if i == len(names) - 1: + if obj is not None: + newnames = dir(obj) + else: + newnames = sets.Set() + newnames.update(__builtins__) + newnames.update(w.mode.locals) + newnames.update(w.mode.globals) candidates = [x for x in newnames if x.startswith(name)] if len(candidates) > 1: s = completer.find_common_string(candidates)[len(name):]