diff --git a/application.py b/application.py index c3b50e7..321003b 100755 --- a/application.py +++ b/application.py @@ -7,7 +7,8 @@ from subprocess import Popen, PIPE, STDOUT import buffer, buffer.about, buffer.colors, buffer.console, buffer.data import buffer.fs, buffer.aes -import bufferlist, color, completer, ispell, keyinput, method, minibuffer +import bufferlist, color, completer, ispell, keyinput, method +from minibuffer import MiniBuffer, MiniBufferError import mode, util, window from point import Point @@ -179,6 +180,7 @@ class Application(object): self.last_replace_before = None self.last_replace_after = None self.registers = {} + self.arg_history = {'default': []} # initialize tab handlers completer.set_completer('path', completer.FileCompleter(self)) @@ -399,18 +401,22 @@ class Application(object): def mini_buffer_is_open(self): return self.mini_buffer is not None def open_mini_buffer(self, prompt, cb, method=None, tabber=None, - modename=None, startvalue=None): + modename=None, startvalue=None, queue='default'): if self.mini_buffer_is_open(): self.close_mini_buffer() self.mini_prompt = prompt - self.mini_buffer = minibuffer.MiniBuffer(cb, method, tabber, modename) + self.mini_buffer = MiniBuffer(cb, self, method, tabber, modename, queue) try: w = self.x - 1 - len(self.mini_prompt) - 1 window.Window(self.mini_buffer, self, height=1, width=w) if startvalue: self.mini_buffer.set_data(startvalue) + self.arg_history.setdefault(queue, []) + self.arg_history[queue].append(startvalue or '') + self.mini_buffer.hindex = len(self.arg_history[queue]) - 1 + self.mini_active = True - except minibuffer.MiniBufferError: + except MiniBufferError: self.mini_buffer = None self.mini_prompt = '' def exec_mini_buffer(self): diff --git a/method/__init__.py b/method/__init__.py index 3483dce..1877600 100644 --- a/method/__init__.py +++ b/method/__init__.py @@ -8,12 +8,13 @@ from point import Point class MethodError(Exception): pass -def arg(n, t=type(''), dt=None, p=None, h='', dv=default.none, ld=False): +def arg(n, t=type(''), dt=None, p=None, h='', dv=default.none, ld=False, q='default'): '''convenience function for arguments''' - return Argument(n, type=t, datatype=dt, prompt=p, help=h, default=dv, load_default=ld) + return Argument(n, type=t, datatype=dt, prompt=p, help=h, default=dv, + load_default=ld, queue=q) class Argument(object): def __init__(self, name, type=type(""), datatype=None, prompt=None, help='', - default=default.none, load_default=False): + default=default.none, load_default=False, queue='default'): self.name = name self.type = type self.datatype = datatype @@ -22,9 +23,9 @@ class Argument(object): else: self.prompt = prompt self.help = help - self.load_default = load_default self.default = default + self.queue = queue def coerce_to_type(self, value): if self.type == type(0): @@ -58,7 +59,7 @@ class Argument(object): else: p = self.prompt app.open_mini_buffer(p, return_value, method=method, tabber=tabber, - startvalue=starting_value) + startvalue=starting_value, queue=self.queue) class Method(object): _is_method = True diff --git a/minibuffer.py b/minibuffer.py index e4620c2..ebee996 100644 --- a/minibuffer.py +++ b/minibuffer.py @@ -13,12 +13,16 @@ class MiniBuffer(buffer.Buffer): mini = object.__new__(MiniBuffer) return mini # the callback function should take one argument (window) - def __init__(self, func, method=None, tabber=None, modename=None): + def __init__(self, func, app, method=None, tabber=None, modename=None, + queue=None): buffer.Buffer.__init__(self) + self.app = app self.callback = func self.method = method self.tabber = tabber self.modename = modename + self.queue = queue + def name(self): return "*Minibuffer*" def do_callback(self): diff --git a/mode/mini.py b/mode/mini.py index 610e8f2..2e44f67 100644 --- a/mode/mini.py +++ b/mode/mini.py @@ -19,8 +19,11 @@ def use_completion_window(app, s, candidates): class MiniCallback(Method): def execute(self, w, **vargs): app = w.application + b = w.buffer if app.completion_window_is_open(): app.close_completion_buffer() + s = b.make_string() + app.arg_history[b.queue][-1] = s w.buffer.do_callback() class MiniTabComplete(Method): @@ -37,12 +40,34 @@ class MiniTabComplete(Method): candidates = b.tabber.get_candidates(s1, w) use_completion_window(app, s2, candidates) +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) + class Mini(Fundamental): name = 'Mini' - actions = [MiniCallback, MiniTabComplete] + actions = [MiniCallback, MiniTabComplete, MiniPrevHistory, MiniNextHistory] _bindings = { 'mini-callback': ('RETURN',), 'mini-tab-complete': ('TAB',), + 'mini-next-history': ('D_ARROW', 'C-n'), + 'mini-prev-history': ('U_ARROW', 'C-p'), } install = Mini.install