pmacs3/mode/pipe.py

48 lines
1.4 KiB
Python

import keyinput
from mode import Fundamental
from method import Method
class PipeInsertChr(Method):
_is_method = False
args = []
def __init__(self, i):
self.name = "pipe-insert-chr-%s" % i
self.help = "Insert chr(%d) into the current pipe." % i
self.string = chr(i)
def _execute(self, w, **vargs):
w.buffer.pipe_write(self.string)
class PipeInsertEsc(PipeInsertChr):
def __init__(self, i):
self.name = "pipe-insert-esc-%s" % i
self.help = "Insert ESC + chr(%d) into the current pipe." % i
self.string = chr(27) + chr(i)
class Pipe(Fundamental):
modename = 'pipe'
def __init__(self, w):
Fundamental.__init__(self, w)
keys = self.bindings.keys()
for key in keys:
if key.startswith('C-x') or key.startswith('M-x'):
continue
del self.bindings[key]
for i in range(0, 128):
# skip C-x and ESC
if i in (24, 27):
continue
sym = keyinput.MAP.get(i, chr(i))
obj = PipeInsertChr(i)
w.application.methods[obj.name] = obj
self.add_binding(obj.name, sym)
if i != ord('x'):
sym2 = 'M-%s' % sym
obj2 = PipeInsertEsc(i)
w.application.methods[obj2.name] = obj2
self.add_binding(obj2.name, sym2)
install = Pipe.install