preliminary argument history support
--HG-- branch : pmacs2
This commit is contained in:
parent
6b5b2eb244
commit
0ed283b5af
|
@ -7,7 +7,8 @@ from subprocess import Popen, PIPE, STDOUT
|
||||||
|
|
||||||
import buffer, buffer.about, buffer.colors, buffer.console, buffer.data
|
import buffer, buffer.about, buffer.colors, buffer.console, buffer.data
|
||||||
import buffer.fs, buffer.aes
|
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
|
import mode, util, window
|
||||||
from point import Point
|
from point import Point
|
||||||
|
|
||||||
|
@ -179,6 +180,7 @@ class Application(object):
|
||||||
self.last_replace_before = None
|
self.last_replace_before = None
|
||||||
self.last_replace_after = None
|
self.last_replace_after = None
|
||||||
self.registers = {}
|
self.registers = {}
|
||||||
|
self.arg_history = {'default': []}
|
||||||
|
|
||||||
# initialize tab handlers
|
# initialize tab handlers
|
||||||
completer.set_completer('path', completer.FileCompleter(self))
|
completer.set_completer('path', completer.FileCompleter(self))
|
||||||
|
@ -399,18 +401,22 @@ class Application(object):
|
||||||
def mini_buffer_is_open(self):
|
def mini_buffer_is_open(self):
|
||||||
return self.mini_buffer is not None
|
return self.mini_buffer is not None
|
||||||
def open_mini_buffer(self, prompt, cb, method=None, tabber=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():
|
if self.mini_buffer_is_open():
|
||||||
self.close_mini_buffer()
|
self.close_mini_buffer()
|
||||||
self.mini_prompt = prompt
|
self.mini_prompt = prompt
|
||||||
self.mini_buffer = minibuffer.MiniBuffer(cb, method, tabber, modename)
|
self.mini_buffer = MiniBuffer(cb, self, method, tabber, modename, queue)
|
||||||
try:
|
try:
|
||||||
w = self.x - 1 - len(self.mini_prompt) - 1
|
w = self.x - 1 - len(self.mini_prompt) - 1
|
||||||
window.Window(self.mini_buffer, self, height=1, width=w)
|
window.Window(self.mini_buffer, self, height=1, width=w)
|
||||||
if startvalue:
|
if startvalue:
|
||||||
self.mini_buffer.set_data(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
|
self.mini_active = True
|
||||||
except minibuffer.MiniBufferError:
|
except MiniBufferError:
|
||||||
self.mini_buffer = None
|
self.mini_buffer = None
|
||||||
self.mini_prompt = ''
|
self.mini_prompt = ''
|
||||||
def exec_mini_buffer(self):
|
def exec_mini_buffer(self):
|
||||||
|
|
|
@ -8,12 +8,13 @@ from point import Point
|
||||||
class MethodError(Exception):
|
class MethodError(Exception):
|
||||||
pass
|
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'''
|
'''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):
|
class Argument(object):
|
||||||
def __init__(self, name, type=type(""), datatype=None, prompt=None, help='',
|
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.name = name
|
||||||
self.type = type
|
self.type = type
|
||||||
self.datatype = datatype
|
self.datatype = datatype
|
||||||
|
@ -22,9 +23,9 @@ class Argument(object):
|
||||||
else:
|
else:
|
||||||
self.prompt = prompt
|
self.prompt = prompt
|
||||||
self.help = help
|
self.help = help
|
||||||
|
|
||||||
self.load_default = load_default
|
self.load_default = load_default
|
||||||
self.default = default
|
self.default = default
|
||||||
|
self.queue = queue
|
||||||
|
|
||||||
def coerce_to_type(self, value):
|
def coerce_to_type(self, value):
|
||||||
if self.type == type(0):
|
if self.type == type(0):
|
||||||
|
@ -58,7 +59,7 @@ class Argument(object):
|
||||||
else:
|
else:
|
||||||
p = self.prompt
|
p = self.prompt
|
||||||
app.open_mini_buffer(p, return_value, method=method, tabber=tabber,
|
app.open_mini_buffer(p, return_value, method=method, tabber=tabber,
|
||||||
startvalue=starting_value)
|
startvalue=starting_value, queue=self.queue)
|
||||||
|
|
||||||
class Method(object):
|
class Method(object):
|
||||||
_is_method = True
|
_is_method = True
|
||||||
|
|
|
@ -13,12 +13,16 @@ class MiniBuffer(buffer.Buffer):
|
||||||
mini = object.__new__(MiniBuffer)
|
mini = object.__new__(MiniBuffer)
|
||||||
return mini
|
return mini
|
||||||
# the callback function should take one argument (window)
|
# 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)
|
buffer.Buffer.__init__(self)
|
||||||
|
self.app = app
|
||||||
self.callback = func
|
self.callback = func
|
||||||
self.method = method
|
self.method = method
|
||||||
self.tabber = tabber
|
self.tabber = tabber
|
||||||
self.modename = modename
|
self.modename = modename
|
||||||
|
self.queue = queue
|
||||||
|
|
||||||
def name(self):
|
def name(self):
|
||||||
return "*Minibuffer*"
|
return "*Minibuffer*"
|
||||||
def do_callback(self):
|
def do_callback(self):
|
||||||
|
|
27
mode/mini.py
27
mode/mini.py
|
@ -19,8 +19,11 @@ def use_completion_window(app, s, candidates):
|
||||||
class MiniCallback(Method):
|
class MiniCallback(Method):
|
||||||
def execute(self, w, **vargs):
|
def execute(self, w, **vargs):
|
||||||
app = w.application
|
app = w.application
|
||||||
|
b = w.buffer
|
||||||
if app.completion_window_is_open():
|
if app.completion_window_is_open():
|
||||||
app.close_completion_buffer()
|
app.close_completion_buffer()
|
||||||
|
s = b.make_string()
|
||||||
|
app.arg_history[b.queue][-1] = s
|
||||||
w.buffer.do_callback()
|
w.buffer.do_callback()
|
||||||
|
|
||||||
class MiniTabComplete(Method):
|
class MiniTabComplete(Method):
|
||||||
|
@ -37,12 +40,34 @@ class MiniTabComplete(Method):
|
||||||
candidates = b.tabber.get_candidates(s1, w)
|
candidates = b.tabber.get_candidates(s1, w)
|
||||||
use_completion_window(app, s2, candidates)
|
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):
|
class Mini(Fundamental):
|
||||||
name = 'Mini'
|
name = 'Mini'
|
||||||
actions = [MiniCallback, MiniTabComplete]
|
actions = [MiniCallback, MiniTabComplete, MiniPrevHistory, MiniNextHistory]
|
||||||
_bindings = {
|
_bindings = {
|
||||||
'mini-callback': ('RETURN',),
|
'mini-callback': ('RETURN',),
|
||||||
'mini-tab-complete': ('TAB',),
|
'mini-tab-complete': ('TAB',),
|
||||||
|
'mini-next-history': ('D_ARROW', 'C-n'),
|
||||||
|
'mini-prev-history': ('U_ARROW', 'C-p'),
|
||||||
}
|
}
|
||||||
|
|
||||||
install = Mini.install
|
install = Mini.install
|
||||||
|
|
Loading…
Reference in New Issue