49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from method import Method
|
|
from mode import Fundamental
|
|
|
|
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))
|
|
|
|
class MiniCallback(Method):
|
|
def execute(self, w, **vargs):
|
|
app = w.application
|
|
if app.completion_window_is_open():
|
|
app.close_completion_buffer()
|
|
w.buffer.do_callback()
|
|
|
|
class MiniTabComplete(Method):
|
|
def execute(self, w, **vargs):
|
|
app = w.application
|
|
b = w.buffer
|
|
if b.tabber is None:
|
|
w.application.set_error("No tab completion")
|
|
return
|
|
s1 = b.make_string()
|
|
s2, exists, complete = b.tabber.tab_string(s1, w)
|
|
b.set_data(s2)
|
|
|
|
candidates = b.tabber.get_candidates(s1, w)
|
|
use_completion_window(app, s2, candidates)
|
|
|
|
class Mini(Fundamental):
|
|
name = 'Mini'
|
|
actions = [MiniCallback, MiniTabComplete]
|
|
_bindings = {
|
|
'mini-callback': ('RETURN',),
|
|
'mini-tab-complete': ('TAB',),
|
|
}
|
|
|
|
install = Mini.install
|