2009-03-29 20:50:27 -04:00
|
|
|
from method import Method
|
|
|
|
from mode import Fundamental
|
2008-05-03 22:41:58 -04:00
|
|
|
|
2008-05-15 03:20:41 -04:00
|
|
|
def use_completion_window(app, s, candidates):
|
|
|
|
if app.completion_window_is_open():
|
|
|
|
w = app.get_completion_window()
|
|
|
|
if w.buffer._completion != s:
|
|
|
|
app.close_completion_buffer()
|
|
|
|
|
|
|
|
if app.completion_window_is_open():
|
|
|
|
w = app.get_completion_window()
|
|
|
|
if w.last_is_visible():
|
|
|
|
w.goto_beginning()
|
|
|
|
else:
|
|
|
|
w.page_down()
|
|
|
|
elif len(candidates) > 1:
|
|
|
|
app.open_completion_buffer(s, sorted(candidates))
|
|
|
|
|
2009-03-29 20:50:27 -04:00
|
|
|
class MiniCallback(Method):
|
2008-05-03 22:41:58 -04:00
|
|
|
def execute(self, w, **vargs):
|
|
|
|
app = w.application
|
2009-07-06 22:48:34 -04:00
|
|
|
b = w.buffer
|
2008-05-03 22:41:58 -04:00
|
|
|
if app.completion_window_is_open():
|
|
|
|
app.close_completion_buffer()
|
2009-07-06 22:48:34 -04:00
|
|
|
s = b.make_string()
|
|
|
|
app.arg_history[b.queue][-1] = s
|
2008-05-03 22:41:58 -04:00
|
|
|
w.buffer.do_callback()
|
2007-07-21 11:40:53 -04:00
|
|
|
|
2009-03-29 20:50:27 -04:00
|
|
|
class MiniTabComplete(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-15 03:20:41 -04:00
|
|
|
candidates = b.tabber.get_candidates(s1, w)
|
|
|
|
use_completion_window(app, s2, candidates)
|
2008-05-03 22:41:58 -04:00
|
|
|
|
2009-07-06 22:48:34 -04:00
|
|
|
class MiniPrevHistory(Method):
|
|
|
|
def execute(self, w, **vargs):
|
|
|
|
b = w.buffer
|
|
|
|
if b.hindex > 0:
|
|
|
|
s = b.make_string()
|
|
|
|
b.app.arg_history[b.queue][b.hindex] = s
|
|
|
|
b.hindex -= 1
|
|
|
|
s = b.app.arg_history[b.queue][b.hindex]
|
|
|
|
b.set_data(s)
|
|
|
|
|
|
|
|
class MiniNextHistory(Method):
|
|
|
|
def execute(self, w, **vargs):
|
|
|
|
b = w.buffer
|
|
|
|
if b.hindex < len(b.app.arg_history[b.queue]) - 1:
|
|
|
|
s = b.make_string()
|
|
|
|
b.app.arg_history[b.queue][b.hindex] = s
|
|
|
|
b.hindex += 1
|
|
|
|
s = b.app.arg_history[b.queue][b.hindex]
|
|
|
|
b.set_data(s)
|
|
|
|
|
2009-03-29 20:50:27 -04:00
|
|
|
class Mini(Fundamental):
|
|
|
|
name = 'Mini'
|
2009-07-06 22:48:34 -04:00
|
|
|
actions = [MiniCallback, MiniTabComplete, MiniPrevHistory, MiniNextHistory]
|
2009-03-29 20:50:27 -04:00
|
|
|
_bindings = {
|
|
|
|
'mini-callback': ('RETURN',),
|
|
|
|
'mini-tab-complete': ('TAB',),
|
2009-07-06 22:48:34 -04:00
|
|
|
'mini-next-history': ('D_ARROW', 'C-n'),
|
|
|
|
'mini-prev-history': ('U_ARROW', 'C-p'),
|
2009-03-29 20:50:27 -04:00
|
|
|
}
|
2008-04-18 23:32:08 -04:00
|
|
|
|
2007-10-19 02:41:33 -04:00
|
|
|
install = Mini.install
|