2008-05-03 22:41:58 -04:00
|
|
|
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')
|
2007-07-21 11:40:53 -04:00
|
|
|
|
|
|
|
class MiniCallback(method.Method):
|
2008-05-03 22:41:58 -04:00
|
|
|
def execute(self, w, **vargs):
|
|
|
|
app = w.application
|
|
|
|
if app.completion_window_is_open():
|
|
|
|
app.close_completion_buffer()
|
|
|
|
w.buffer.do_callback()
|
2007-07-21 11:40:53 -04:00
|
|
|
|
|
|
|
class MiniTabComplete(method.Method):
|
2008-05-03 22:41:58 -04:00
|
|
|
def execute(self, w, **vargs):
|
|
|
|
app = w.application
|
|
|
|
b = w.buffer
|
2007-07-21 11:40:53 -04:00
|
|
|
if b.tabber is None:
|
2008-05-03 22:41:58 -04:00
|
|
|
w.application.set_error("No tab completion")
|
2007-07-21 11:40:53 -04:00
|
|
|
return
|
|
|
|
s1 = b.make_string()
|
2008-05-03 22:41:58 -04:00
|
|
|
s2, exists, complete = b.tabber.tab_string(s1, w)
|
2007-07-21 11:40:53 -04:00
|
|
|
b.set_data(s2)
|
2007-10-19 02:41:33 -04:00
|
|
|
|
2008-05-03 22:41:58 -04:00
|
|
|
if app.completion_window_is_open():
|
|
|
|
w2 = app.get_completion_window()
|
|
|
|
if w2.last_is_visible():
|
|
|
|
w2.goto_beginning()
|
|
|
|
else:
|
|
|
|
w2.page_down()
|
|
|
|
else:
|
|
|
|
candidates = sorted(b.tabber.get_candidates(s1))
|
|
|
|
if len(candidates) > 1:
|
|
|
|
app.open_completion_buffer(s2, candidates)
|
|
|
|
|
2008-04-18 23:32:08 -04:00
|
|
|
class Mini(mode.Fundamental):
|
|
|
|
modename = 'Mini'
|
2008-05-03 22:41:58 -04:00
|
|
|
actions = [MiniCallback, MiniTabComplete, MiniInsertSpace]
|
2008-04-18 23:32:08 -04:00
|
|
|
def __init__(self, w):
|
|
|
|
mode.Fundamental.__init__(self, w)
|
|
|
|
self.add_bindings('mini-callback', ('RETURN',))
|
|
|
|
self.add_bindings('mini-tab-complete', ('TAB',))
|
|
|
|
|
2008-05-03 22:41:58 -04:00
|
|
|
# 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',))
|
|
|
|
|
2007-10-19 02:41:33 -04:00
|
|
|
install = Mini.install
|