pmacs3/mode_which.py

55 lines
1.7 KiB
Python

import sets, string
import color, method, minibuffer, mode, point
import random
class Which(mode.Fundamental):
'''This is the default mode'''
def __init__(self, w):
mode.Fundamental.__init__(self, w)
old_mode = w.buffer.method.old_window.mode
self.actions = dict(old_mode.actions)
self.bindings = dict(old_mode.bindings)
for name in self.actions.keys():
old_method = self.actions[name]
new_method = HelpWrapper(old_method)
self.actions[name] = new_method
def name(self):
return "Which"
def handle_token(self, t):
'''self.handle_token(token): handles input "token"'''
self.window.active_point = None
try:
act = mode.Handler.handle_token(self, t)
if act is None:
return
else:
self.window.application.clear_error()
act.execute(self.window)
self.window.application.last_action = act.name
except Exception, e:
self.window.application.set_error('%r is not bound to anything' % self.last_sequence)
_end(self.window)
class HelpWrapper(method.Method):
def __init__(self, m):
self.name = "help-for-%s" % m.name
self.args = []
self.help = 'provide help for the %r command' % m.name
self._m_name = m.name
self._m_help = m.help
def _execute(self, window, **vargs):
seq = window.mode.last_sequence
s = '%r is %r: %s' % (seq, self._m_name, self._m_help)
window.application.set_error(s)
_end(window)
def _end(window):
window.application.close_mini_buffer()
window.buffer.method.old_cursor = None
window.buffer.method.old_window = None