pmacs3/mode/mini.py

49 lines
1.5 KiB
Python
Raw Normal View History

import string
import buffer, method, mode, window
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))
2007-07-21 11:40:53 -04:00
class MiniCallback(method.Method):
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):
def execute(self, w, **vargs):
app = w.application
b = w.buffer
2007-07-21 11:40:53 -04:00
if b.tabber is None:
w.application.set_error("No tab completion")
2007-07-21 11:40:53 -04:00
return
s1 = b.make_string()
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
candidates = b.tabber.get_candidates(s1, w)
use_completion_window(app, s2, candidates)
2008-04-18 23:32:08 -04:00
class Mini(mode.Fundamental):
name = 'Mini'
actions = [MiniCallback, MiniTabComplete]
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',))
2007-10-19 02:41:33 -04:00
install = Mini.install