pmacs3/mode/insertmini.py

72 lines
2.9 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',))
2008-04-06 22:31:13 -04:00
self.add_action_and_bindings(InsertLine(), ('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)
2008-04-06 22:31:13 -04:00
def insert_line(w):
s = w.buffer.make_string()
w.mode.lines.append(s)
w.buffer.set_data('')
class InsertTab(method.Method):
def _execute(self, w, **vargs):
w.insert_string_at_cursor(' ' * w.mode.tabwidth)
2008-04-06 22:31:13 -04:00
class InsertLine(method.Method):
def _execute(self, w, **vargs):
2008-04-06 22:31:13 -04:00
insert_line(w)
class InsertComplete(method.Method):
def execute(self, w, **vargs):
2008-04-06 22:31:13 -04:00
insert_line(w)
w.buffer.callback('\n'.join(w.mode.lines))
w.application.close_mini_buffer()
class InsertCancel(method.Method):
def execute(self, w, **vargs):
w.application.close_mini_buffer()
install = InsertMini.install