From bb90c034085c9e62b2d27a883f892f8c6c3ab70a Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 4 May 2008 06:40:30 +0000 Subject: [PATCH] more better mini-buffer/completion buffer --HG-- branch : pmacs2 --- BUGS | 1 - application.py | 6 +++--- bufferlist.py | 3 +-- mode/__init__.py | 4 ++-- mode/consolemini.py | 4 ++-- mode/mini.py | 36 ++++++------------------------------ 6 files changed, 14 insertions(+), 40 deletions(-) diff --git a/BUGS b/BUGS index f31070c..15066a2 100644 --- a/BUGS +++ b/BUGS @@ -15,6 +15,5 @@ known deficiencies: 1. a single action (global search and replace) may produce N actions that need to be individually "undone". This is annoying. 3. opening files larger than 5-10k lines can be very slow - 5. tab completion, etc doesn't pop-open a completion buffer like it might 6. if you get confused in the mini buffer it can be annoying (usually you just need to start hammering C-] to cancel whatever is happening). diff --git a/application.py b/application.py index 2bbeec3..db0fd12 100755 --- a/application.py +++ b/application.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import curses, curses.ascii, getpass, os, re, string, sets, sys, termios, time +import curses, curses.ascii, getpass, os, re, string, sys, termios, time import traceback from subprocess import Popen, PIPE, STDOUT @@ -956,8 +956,8 @@ if __name__ == "__main__": # open each path using our callback to get a buffer, open that buffer, etc. buffers = [] - names = sets.Set() - paths = sets.Set() + names = set() + paths = set() for path in args: path = os.path.abspath(os.path.realpath(util.expand_tilde(path))) diff --git a/bufferlist.py b/bufferlist.py index a598edb..22c6779 100644 --- a/bufferlist.py +++ b/bufferlist.py @@ -1,4 +1,3 @@ -import sets import window class Slot(object): @@ -30,7 +29,7 @@ class BufferList(object): def __init__(self, height, width, buffers=()): self.height = height self.width = width - self.buffers = sets.Set() + self.buffers = set() self.buffer_names = {} self.hidden_buffers = [] self.slots = [] diff --git a/mode/__init__.py b/mode/__init__.py index 3c15e44..d0d1703 100644 --- a/mode/__init__.py +++ b/mode/__init__.py @@ -1,4 +1,4 @@ -import math, os, sets, string +import math, os, string import color, method from lex import Lexer from point import Point @@ -11,7 +11,7 @@ class ActionError(Exception): class Handler(object): def __init__(self): - self.prefixes = sets.Set(["C-x", "C-c", "C-u"]) + self.prefixes = set(["C-x", "C-c", "C-u"]) self.last_sequence = '' self.curr_tokens = [] self.bindings = {} diff --git a/mode/consolemini.py b/mode/consolemini.py index b80c890..f16e2e0 100644 --- a/mode/consolemini.py +++ b/mode/consolemini.py @@ -1,4 +1,4 @@ -import code, re, string, StringIO, sets, sys, traceback +import code, re, string, StringIO, sys, traceback import color, completer, lex, method, mode from lex import Grammar, PatternRule from mode.python import PythonGrammar @@ -151,7 +151,7 @@ class ConsoleTab(method.Method): if obj is not None: newnames = dir(obj) else: - newnames = sets.Set() + newnames = set() newnames.update(__builtins__) newnames.update(w.mode.locals) newnames.update(w.mode.globals) diff --git a/mode/mini.py b/mode/mini.py index fa4e9fe..b8787b7 100644 --- a/mode/mini.py +++ b/mode/mini.py @@ -1,30 +1,6 @@ import string import buffer, method, mode, window -class MiniInsertString(method.InsertString): - _is_method = False - def __init__(self, s): - method.InsertString.__init__(self, s) - self.name = "mini-insert-string-%s" % s - def _execute(self, w, **vargs): - try: - app = w.application - w.insert_string_at_cursor(self.string) - if app.completion_window_is_open(): - app.close_completion_buffer() - except buffer.ReadOnlyError: - w.set_error('Buffer is read-only') - -class MiniInsertSpace(method.Method): - def _execute(self, w, **vargs): - try: - app = w.application - w.insert_string_at_cursor(' ') - if app.completion_window_is_open(): - app.close_completion_buffer() - except buffer.ReadOnlyError: - w.set_error('Buffer is read-only') - class MiniCallback(method.Method): def execute(self, w, **vargs): app = w.application @@ -43,6 +19,11 @@ class MiniTabComplete(method.Method): s2, exists, complete = b.tabber.tab_string(s1, w) b.set_data(s2) + if app.completion_window_is_open(): + w2 = app.get_completion_window() + if w2.buffer._completion != s2: + app.close_completion_buffer() + if app.completion_window_is_open(): w2 = app.get_completion_window() if w2.last_is_visible(): @@ -56,15 +37,10 @@ class MiniTabComplete(method.Method): class Mini(mode.Fundamental): modename = 'Mini' - actions = [MiniCallback, MiniTabComplete, MiniInsertSpace] + actions = [MiniCallback, MiniTabComplete] def __init__(self, w): mode.Fundamental.__init__(self, w) self.add_bindings('mini-callback', ('RETURN',)) self.add_bindings('mini-tab-complete', ('TAB',)) - # create all the insert actions for the basic text input - for c in string.letters + string.digits + string.punctuation: - self.add_action_and_bindings(MiniInsertString(c), (c,)) - self.add_bindings('mini-insert-space', ('SPACE',)) - install = Mini.install