implemented insert-multiline-text function
--HG-- branch : pmacs2
This commit is contained in:
parent
6f6a666d99
commit
cfac74acab
|
@ -115,7 +115,8 @@ class Application(object):
|
|||
'dir', 'elisp', 'hex', 'html', 'java', 'javascript', 'lisp',
|
||||
'make', 'mini', 'mutt', 'nasm', 'ocaml', 'perl', 'python',
|
||||
'replace', 'rst', 'scheme', 'search', 'sh', 'sql', 'tt',
|
||||
'text', 'text2', 'which', 'xml', 'cheetah', 'colortext', 'latex')
|
||||
'text', 'text2', 'which', 'xml', 'cheetah', 'colortext',
|
||||
'latex', 'insertmini')
|
||||
for name in names:
|
||||
exec("import mode.%s; mode.%s.install(self)" % (name, name))
|
||||
|
||||
|
|
|
@ -198,6 +198,11 @@ class InsertText2(Method):
|
|||
text = text.replace('\\t', ' ')
|
||||
text = text.replace('\\\\', '\\')
|
||||
w.insert_string_at_cursor(text)
|
||||
class InsertMultilineText(Method):
|
||||
'''Insert multiple lines into the buffer (M-RETURN to end; C-] to cancel)'''
|
||||
def _execute(self, w, **vargs):
|
||||
f = lambda s: w.insert_string_at_cursor(s)
|
||||
w.application.open_mini_buffer('Multi-Insert: ', f, self, None, 'insertmini')
|
||||
|
||||
# killing/copying/etc.
|
||||
class Kill(Method):
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
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
|
Loading…
Reference in New Issue