branch : pmacs2
This commit is contained in:
moculus 2007-07-03 00:29:27 +00:00
parent 3e9abf3424
commit f8c2173b5c
3 changed files with 67 additions and 10 deletions

View File

@ -180,12 +180,13 @@ class Application(object):
method.GotoLine().execute(w, lineno=jump_to_line) method.GotoLine().execute(w, lineno=jump_to_line)
# initialize our kill ring and last action # initialize our kill ring and last action
self.kill_ring = [] self.kill_ring = []
self.kill_commands = ['kill', 'kill-region'] self.kill_commands = ['kill', 'kill-region']
self.last_action = None self.last_action = None
self.last_search = None self.last_search = None
self.last_replace_before = None self.last_replace_before = None
self.last_replace_after = None self.last_replace_after = None
self.registers = {}
# initialize tab handlers # initialize tab handlers
method.DATATYPES['path'] = completer.FileCompleter() method.DATATYPES['path'] = completer.FileCompleter()
@ -364,7 +365,7 @@ class Application(object):
self.kill_ring[-1] = self.kill_ring[-1] + s self.kill_ring[-1] = self.kill_ring[-1] + s
else: else:
self.kill_ring.append(s) 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) self.kill_ring.pop(0)
def pop_kill(self): def pop_kill(self):
return self.kill_ring.pop(-1) return self.kill_ring.pop(-1)

View File

@ -13,6 +13,9 @@ DATATYPES = {
"shellcommand": None, "shellcommand": None,
} }
class MethodError(Exception):
pass
class Argument: class Argument:
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):
@ -89,11 +92,15 @@ class Method:
def _args(self): def _args(self):
return [] return []
def pre_execute(self, w, **vargs): def _pre_execute(self, w, **vargs):
pass pass
def execute(self, w, **vargs): 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: for arg in self.args:
if arg.name not in vargs: if arg.name not in vargs:
self.old_window = w self.old_window = w
@ -219,9 +226,10 @@ class SwitchBuffer(Method):
return [Argument('buffername', datatype="buffer", return [Argument('buffername', datatype="buffer",
prompt="Switch To Buffer: ", prompt="Switch To Buffer: ",
default=default.last_buffer)] default=default.last_buffer)]
def pre_execute(self, w, **vargs): def _pre_execute(self, w, **vargs):
a = w.application 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): def _execute(self, w, **vargs):
name = vargs['buffername'] name = vargs['buffername']
buf = None buf = None
@ -1381,3 +1389,41 @@ class GetToken(Method):
w.application.set_error('No Token') w.application.set_error('No Token')
else: else:
w.application.set_error('Token: %r' % token.string) 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))

View File

@ -69,6 +69,10 @@ class Window(object):
else: else:
return os.path.splitext(path)[1].lower() 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 # mode stuff
def set_mode(self, m): def set_mode(self, m):
self.mode = m self.mode = m
@ -514,8 +518,14 @@ class Window(object):
# yank/pop # yank/pop
def yank(self): def yank(self):
self.insert_string_at_cursor(self.application.get_kill()) 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): def pop_kill(self):
return self.application.pop_kill() return self.application.pop_kill()
def push_kill(self, s):
return self.application.push_kill(s)
# querying # querying
def cursor_char(self): def cursor_char(self):