parent
3e9abf3424
commit
f8c2173b5c
|
@ -186,6 +186,7 @@ class Application(object):
|
|||
self.last_search = None
|
||||
self.last_replace_before = None
|
||||
self.last_replace_after = None
|
||||
self.registers = {}
|
||||
|
||||
# initialize tab handlers
|
||||
method.DATATYPES['path'] = completer.FileCompleter()
|
||||
|
@ -364,7 +365,7 @@ class Application(object):
|
|||
self.kill_ring[-1] = self.kill_ring[-1] + s
|
||||
else:
|
||||
self.kill_ring.append(s)
|
||||
if len(self.kill_ring) > KILL_RING_LIMIT:
|
||||
if KILL_RING_LIMIT and len(self.kill_ring) > KILL_RING_LIMIT:
|
||||
self.kill_ring.pop(0)
|
||||
def pop_kill(self):
|
||||
return self.kill_ring.pop(-1)
|
||||
|
|
54
method.py
54
method.py
|
@ -13,6 +13,9 @@ DATATYPES = {
|
|||
"shellcommand": None,
|
||||
}
|
||||
|
||||
class MethodError(Exception):
|
||||
pass
|
||||
|
||||
class Argument:
|
||||
def __init__(self, name, type=type(""), datatype=None, prompt=None, help="",
|
||||
default=default.none, load_default=False):
|
||||
|
@ -89,11 +92,15 @@ class Method:
|
|||
def _args(self):
|
||||
return []
|
||||
|
||||
def pre_execute(self, w, **vargs):
|
||||
def _pre_execute(self, w, **vargs):
|
||||
pass
|
||||
|
||||
def execute(self, w, **vargs):
|
||||
self.pre_execute(w, **vargs)
|
||||
try:
|
||||
self._pre_execute(w, **vargs)
|
||||
except MethodError, e:
|
||||
w.application.set_error(str(e))
|
||||
return
|
||||
for arg in self.args:
|
||||
if arg.name not in vargs:
|
||||
self.old_window = w
|
||||
|
@ -219,9 +226,10 @@ class SwitchBuffer(Method):
|
|||
return [Argument('buffername', datatype="buffer",
|
||||
prompt="Switch To Buffer: ",
|
||||
default=default.last_buffer)]
|
||||
def pre_execute(self, w, **vargs):
|
||||
def _pre_execute(self, w, **vargs):
|
||||
a = w.application
|
||||
assert len(a.bufferlist.buffers) > 1, "No other buffers"
|
||||
if len(a.bufferlist.buffers) < 1:
|
||||
raise Exception, "No other buffers"
|
||||
def _execute(self, w, **vargs):
|
||||
name = vargs['buffername']
|
||||
buf = None
|
||||
|
@ -1381,3 +1389,41 @@ class GetToken(Method):
|
|||
w.application.set_error('No Token')
|
||||
else:
|
||||
w.application.set_error('Token: %r' % token.string)
|
||||
|
||||
class RegisterSave(Method):
|
||||
MAX_TXT = 30
|
||||
MAX_REG = 20
|
||||
'''help here'''
|
||||
def _args(self):
|
||||
return [Argument('name', datatype="str", prompt="Register name: ")]
|
||||
def _pre_execute(self, w, **vargs):
|
||||
if not w.has_kill():
|
||||
raise MethodError, "No text on the kill stack"
|
||||
def _execute(self, w, **vargs):
|
||||
name = vargs['name']
|
||||
text = w.get_kill()
|
||||
w.application.registers[name] = text
|
||||
if len(name) > self.MAX_REG:
|
||||
name = name[:self.MAX_REG] + '...'
|
||||
if len(text) > self.MAX_TXT:
|
||||
text = text[:self.MAX_TXT] + '...'
|
||||
w.set_error('Saved %r into register %r' % (text, name))
|
||||
|
||||
class RegisterRestore(Method):
|
||||
MAX_TXT = 30
|
||||
MAX_REG = 18
|
||||
'''help here'''
|
||||
def _args(self):
|
||||
return [Argument('name', datatype="str", prompt="Register name: ")]
|
||||
def _execute(self, w, **vargs):
|
||||
name = vargs['name']
|
||||
if name not in w.application.registers:
|
||||
w.set_error('Register %r does not exist' % name)
|
||||
return
|
||||
text = app.registers[name]
|
||||
w.push_kill(text)
|
||||
if len(text) > self.MAX_TXT:
|
||||
text = text[0:self.MAX_TXT] + '...'
|
||||
if len(name) > self.MAX_REG:
|
||||
name = name[0:self.MAX_REG] + '...'
|
||||
w.set_error('Restored %r from register %r' % (text2, name2))
|
||||
|
|
10
window2.py
10
window2.py
|
@ -69,6 +69,10 @@ class Window(object):
|
|||
else:
|
||||
return os.path.splitext(path)[1].lower()
|
||||
|
||||
# some useful pass-through to application
|
||||
def set_error(self, s):
|
||||
self.application.set_error(s)
|
||||
|
||||
# mode stuff
|
||||
def set_mode(self, m):
|
||||
self.mode = m
|
||||
|
@ -514,8 +518,14 @@ class Window(object):
|
|||
# yank/pop
|
||||
def yank(self):
|
||||
self.insert_string_at_cursor(self.application.get_kill())
|
||||
def get_kill(self):
|
||||
return self.application.get_kill()
|
||||
def has_kill(self, i=-1):
|
||||
return self.application.has_kill(i)
|
||||
def pop_kill(self):
|
||||
return self.application.pop_kill()
|
||||
def push_kill(self, s):
|
||||
return self.application.push_kill(s)
|
||||
|
||||
# querying
|
||||
def cursor_char(self):
|
||||
|
|
Loading…
Reference in New Issue