pmacs3/mode/insertmini.py

75 lines
3.0 KiB
Python
Raw Normal View History

import code, re, string, StringIO, sys, traceback
import color, completer, lex, method, mode
from lex import Grammar, PatternRule
from mode.python import PythonGrammar
from point import Point
class InsertMini(mode.Fundamental):
modename = 'InsertMini'
def __init__(self, w):
mode.Fundamental.__init__(self, w)
self.bindings = {}
self.saved_input = ""
self.history = ['']
self.hindex = 0
self.lines = []
self.add_bindings('start-of-line', ('C-a', 'HOME',))
self.add_bindings('end-of-line', ('C-e', 'END',))
self.add_bindings('backward', ('C-b', 'L_ARROW',))
self.add_bindings('forward', ('C-f', 'R_ARROW',))
self.add_bindings('delete-left', ('DELETE', 'BACKSPACE',))
self.add_bindings('delete-left-word', ('M-DELETE', 'M-BACKSPACE',))
self.add_bindings('delete-right', ('C-d',))
self.add_bindings('delete-right-word', ('M-d',))
self.add_bindings('kill-region', ('C-w',))
self.add_bindings('copy-region', ('M-w',))
self.add_bindings('kill', ('C-k',))
self.add_bindings('copy', ('M-k',))
self.add_bindings('yank', ('C-y',))
self.add_bindings('pop-kill', ('M-y',))
self.add_bindings('right-word', ('M-f',))
self.add_bindings('left-word', ('M-b',))
self.add_bindings('set-mark', ('C-@',))
self.add_bindings('switch-mark', ('C-x C-x',))
self.add_bindings('undo', ('C-/', 'C-x u',))
self.add_bindings('redo', ('M-/', 'M-_', 'C-x r',))
self.add_bindings('toggle-margins', ('M-m',))
self.add_bindings('transpose-words', ('M-t',))
self.add_bindings('delete-left-whitespace', ('C-c DELETE', 'C-c BACKSPACE',))
self.add_bindings('delete-right-whitespace', ('C-c d',))
self.add_bindings('insert-space', ('SPACE',))
self.add_bindings('insert-tab', ('TAB',))
self.add_action_and_bindings(InsertExec(), ('RETURN',))
self.add_action_and_bindings(InsertComplete(), ('M-RETURN',))
self.add_action_and_bindings(InsertCancel(), ('C-]',))
self.add_action_and_bindings(InsertTab(), ('TAB',))
for c in string.letters + string.digits + string.punctuation:
self.add_binding('insert-string-%s' % c, c)
class InsertTab(method.Method):
def _execute(self, w, **vargs):
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
class InsertExec(method.Method):
def _execute(self, w, **vargs):
s = w.buffer.make_string()
w.mode.lines.append(s)
w.buffer.set_data('')
w.mode.history[-1] = s
w.mode.history.append('')
w.mode.hindex = len(w.mode.history) - 1
class InsertComplete(method.Method):
def execute(self, w, **vargs):
s = '\n'.join(w.mode.lines)
w.buffer.callback(s)
w.application.close_mini_buffer()
class InsertCancel(method.Method):
def execute(self, w, **vargs):
w.application.close_mini_buffer()
install = InsertMini.install