mirror of
https://github.com/wassname/pyreadline.git
synced 2026-06-27 16:10:38 +08:00
Fixed last functions in emacs mode that use console directly. Implemented digit_argument.
Made changes to TextLine and ReadLineTextLine classes to handle argument in insert_text Added DigitArgumentMode to handle digit_arguments
This commit is contained in:
@@ -267,7 +267,8 @@ class TextLine(object):
|
||||
def end_of_line(self):
|
||||
self.point = len(self.line_buffer)
|
||||
|
||||
def _insert_text(self, text):
|
||||
def _insert_text(self, text, argument=1):
|
||||
text=text*argument
|
||||
if self.overwrite:
|
||||
for c in text:
|
||||
#if self.point:
|
||||
@@ -406,10 +407,10 @@ class ReadLineTextBuffer(TextLine):
|
||||
return 'ReadLineTextBuffer("%s",point=%s,mark=%s,selection_mark=%s)'%(self.line_buffer,self.point,self.mark,self.selection_mark)
|
||||
|
||||
|
||||
def insert_text(self,char):
|
||||
def insert_text(self, char, argument=1):
|
||||
self.delete_selection()
|
||||
self.selection_mark=-1
|
||||
self._insert_text(char)
|
||||
self._insert_text(char, argument)
|
||||
|
||||
def to_clipboard(self):
|
||||
if self.enable_win32_clipboard:
|
||||
|
||||
@@ -20,6 +20,7 @@ in_ironpython="IronPython" in sys.version
|
||||
class BaseMode(object):
|
||||
mode="base"
|
||||
def __init__(self,rlobj):
|
||||
self.argument=0
|
||||
self.rlobj=rlobj
|
||||
self.exit_dispatch = {}
|
||||
self.key_dispatch = {}
|
||||
@@ -71,7 +72,9 @@ class BaseMode(object):
|
||||
|
||||
def _argreset(self):
|
||||
val=self.argument
|
||||
self.argument=1
|
||||
self.argument=0
|
||||
if val==0:
|
||||
val=1
|
||||
return val
|
||||
argument_reset=property(_argreset)
|
||||
|
||||
@@ -126,6 +129,12 @@ class BaseMode(object):
|
||||
####################################
|
||||
|
||||
|
||||
def finalize(self):
|
||||
"""Every bindable command should call this function for cleanup.
|
||||
Except those that want to set argument to a non-zero value.
|
||||
"""
|
||||
self.argument=0
|
||||
|
||||
|
||||
def add_history(self, text):
|
||||
self._history.add_history(lineobj.ReadLineTextBuffer(text))
|
||||
@@ -255,11 +264,13 @@ class BaseMode(object):
|
||||
self._bell()
|
||||
else:
|
||||
self._bell()
|
||||
self.finalize()
|
||||
|
||||
def possible_completions(self, e): # (M-?)
|
||||
"""List the possible completions of the text before point. """
|
||||
completions = self._get_completions()
|
||||
self._display_completions(completions)
|
||||
self.finalize()
|
||||
|
||||
def insert_completions(self, e): # (M-*)
|
||||
"""Insert all completions of the text before point that would have
|
||||
@@ -274,6 +285,7 @@ class BaseMode(object):
|
||||
b += len(rep)
|
||||
e = b
|
||||
self.line_cursor = b
|
||||
self.finalize()
|
||||
|
||||
def menu_complete(self, e): # ()
|
||||
"""Similar to complete, but replaces the word to be completed with a
|
||||
@@ -285,87 +297,104 @@ class BaseMode(object):
|
||||
positions forward in the list of matches; a negative argument may be
|
||||
used to move backward through the list. This command is intended to
|
||||
be bound to TAB, but is unbound by default."""
|
||||
pass
|
||||
self.finalize()
|
||||
|
||||
### Methods below here are bindable emacs functions
|
||||
|
||||
|
||||
def insert_text(self, string):
|
||||
"""Insert text into the command line."""
|
||||
self.l_buffer.insert_text(string)
|
||||
self.l_buffer.insert_text(string, self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def beginning_of_line(self, e): # (C-a)
|
||||
"""Move to the start of the current line. """
|
||||
self.l_buffer.beginning_of_line()
|
||||
self.finalize()
|
||||
|
||||
def end_of_line(self, e): # (C-e)
|
||||
"""Move to the end of the line. """
|
||||
self.l_buffer.end_of_line()
|
||||
self.finalize()
|
||||
|
||||
def forward_char(self, e): # (C-f)
|
||||
"""Move forward a character. """
|
||||
self.l_buffer.forward_char(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def backward_char(self, e): # (C-b)
|
||||
"""Move back a character. """
|
||||
self.l_buffer.backward_char(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def forward_word(self, e): # (M-f)
|
||||
"""Move forward to the end of the next word. Words are composed of
|
||||
letters and digits."""
|
||||
self.l_buffer.forward_word(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def backward_word(self, e): # (M-b)
|
||||
"""Move back to the start of the current or previous word. Words are
|
||||
composed of letters and digits."""
|
||||
self.l_buffer.backward_word(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def forward_word_end(self, e): # ()
|
||||
"""Move forward to the end of the next word. Words are composed of
|
||||
letters and digits."""
|
||||
self.l_buffer.forward_word_end(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def backward_word_end(self, e): # ()
|
||||
"""Move forward to the end of the next word. Words are composed of
|
||||
letters and digits."""
|
||||
self.l_buffer.backward_word_end(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
### Movement with extend selection
|
||||
def beginning_of_line_extend_selection(self, e): #
|
||||
"""Move to the start of the current line. """
|
||||
self.l_buffer.beginning_of_line_extend_selection()
|
||||
self.finalize()
|
||||
|
||||
def end_of_line_extend_selection(self, e): #
|
||||
"""Move to the end of the line. """
|
||||
self.l_buffer.end_of_line_extend_selection()
|
||||
self.finalize()
|
||||
|
||||
def forward_char_extend_selection(self, e): #
|
||||
"""Move forward a character. """
|
||||
self.l_buffer.forward_char_extend_selection(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def backward_char_extend_selection(self, e): #
|
||||
"""Move back a character. """
|
||||
self.l_buffer.backward_char_extend_selection(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def forward_word_extend_selection(self, e): #
|
||||
"""Move forward to the end of the next word. Words are composed of
|
||||
letters and digits."""
|
||||
self.l_buffer.forward_word_extend_selection(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def backward_word_extend_selection(self, e): #
|
||||
"""Move back to the start of the current or previous word. Words are
|
||||
composed of letters and digits."""
|
||||
self.l_buffer.backward_word_extend_selection(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def forward_word_end_extend_selection(self, e): #
|
||||
"""Move forward to the end of the next word. Words are composed of
|
||||
letters and digits."""
|
||||
self.l_buffer.forward_word_end_extend_selection(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def backward_word_end_extend_selection(self, e): #
|
||||
"""Move forward to the end of the next word. Words are composed of
|
||||
letters and digits."""
|
||||
self.l_buffer.forward_word_end_extend_selection(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
|
||||
######## Change case
|
||||
@@ -374,16 +403,19 @@ class BaseMode(object):
|
||||
"""Uppercase the current (or following) word. With a negative
|
||||
argument, uppercase the previous word, but do not move the cursor."""
|
||||
self.l_buffer.upcase_word()
|
||||
self.finalize()
|
||||
|
||||
def downcase_word(self, e): # (M-l)
|
||||
"""Lowercase the current (or following) word. With a negative
|
||||
argument, lowercase the previous word, but do not move the cursor."""
|
||||
self.l_buffer.downcase_word()
|
||||
self.finalize()
|
||||
|
||||
def capitalize_word(self, e): # (M-c)
|
||||
"""Capitalize the current (or following) word. With a negative
|
||||
argument, capitalize the previous word, but do not move the cursor."""
|
||||
self.l_buffer.capitalize_word()
|
||||
self.finalize()
|
||||
|
||||
|
||||
########
|
||||
@@ -391,48 +423,55 @@ class BaseMode(object):
|
||||
"""Clear the screen and redraw the current line, leaving the current
|
||||
line at the top of the screen."""
|
||||
self.console.page()
|
||||
self.finalize()
|
||||
|
||||
def redraw_current_line(self, e): # ()
|
||||
"""Refresh the current line. By default, this is unbound."""
|
||||
pass
|
||||
self.finalize()
|
||||
|
||||
def accept_line(self, e): # (Newline or Return)
|
||||
"""Accept the line regardless of where the cursor is. If this line
|
||||
is non-empty, it may be added to the history list for future recall
|
||||
with add_history(). If this line is a modified history line, the
|
||||
history line is restored to its original state."""
|
||||
self.finalize()
|
||||
return True
|
||||
|
||||
|
||||
def delete_char(self, e): # (C-d)
|
||||
"""Delete the character at point. If point is at the beginning of
|
||||
the line, there are no characters in the line, and the last
|
||||
character typed was not bound to delete-char, then return EOF."""
|
||||
self.l_buffer.delete_char(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def backward_delete_char(self, e): # (Rubout)
|
||||
"""Delete the character behind the cursor. A numeric argument means
|
||||
to kill the characters instead of deleting them."""
|
||||
self.l_buffer.backward_delete_char(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def backward_delete_word(self, e): # (Control-Rubout)
|
||||
"""Delete the character behind the cursor. A numeric argument means
|
||||
to kill the characters instead of deleting them."""
|
||||
self.l_buffer.backward_delete_word(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def forward_delete_word(self, e): # (Control-Delete)
|
||||
"""Delete the character behind the cursor. A numeric argument means
|
||||
to kill the characters instead of deleting them."""
|
||||
self.l_buffer.forward_delete_word(self.argument_reset)
|
||||
self.finalize()
|
||||
|
||||
def delete_horizontal_space(self, e): # ()
|
||||
"""Delete all spaces and tabs around point. By default, this is unbound. """
|
||||
self.l_buffer.delete_horizontal_space()
|
||||
self.finalize()
|
||||
|
||||
def self_insert(self, e): # (a, b, A, 1, !, ...)
|
||||
"""Insert yourself. """
|
||||
if e.char and ord(e.char)!=0: #don't insert null character in buffer, can happen with dead keys.
|
||||
self.insert_text(e.char)
|
||||
self.finalize()
|
||||
|
||||
|
||||
# Paste from clipboard
|
||||
@@ -445,6 +484,7 @@ class BaseMode(object):
|
||||
txt=txt.split("\n")[0].strip("\r").strip("\n")
|
||||
log("paste: >%s<"%map(ord,txt))
|
||||
self.insert_text(txt)
|
||||
self.finalize()
|
||||
|
||||
def paste_mulitline_code(self,e):
|
||||
"""Paste windows clipboard as multiline code.
|
||||
@@ -462,6 +502,7 @@ class BaseMode(object):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
self.finalize()
|
||||
|
||||
def ipython_paste(self,e):
|
||||
"""Paste windows clipboard. If enable_ipython_paste_list_of_lists is
|
||||
@@ -475,19 +516,23 @@ class BaseMode(object):
|
||||
if len(txt)<300 and ("\t" not in txt) and ("\n" not in txt):
|
||||
txt=txt.replace("\\","/").replace(" ",r"\ ")
|
||||
self.insert_text(txt)
|
||||
self.finalize()
|
||||
|
||||
|
||||
def copy_region_to_clipboard(self, e): # ()
|
||||
"""Copy the text in the region to the windows clipboard."""
|
||||
self.l_buffer.copy_region_to_clipboard()
|
||||
self.finalize()
|
||||
|
||||
def copy_selection_to_clipboard(self, e): # ()
|
||||
"""Copy the text in the region to the windows clipboard."""
|
||||
self.l_buffer.copy_selection_to_clipboard()
|
||||
self.finalize()
|
||||
|
||||
def cut_selection_to_clipboard(self, e): # ()
|
||||
"""Copy the text in the region to the windows clipboard."""
|
||||
self.l_buffer.cut_selection_to_clipboard()
|
||||
self.finalize()
|
||||
|
||||
def dump_functions(self, e): # ()
|
||||
"""Print all of the functions and their key bindings to the Readline
|
||||
@@ -498,6 +543,7 @@ class BaseMode(object):
|
||||
txt="\n".join(self.rl_settings_to_string())
|
||||
print txt
|
||||
self._print_prompt()
|
||||
self.finalize()
|
||||
|
||||
def commonprefix(m):
|
||||
"Given a list of pathnames, returns the longest common leading component"
|
||||
|
||||
+210
-158
@@ -88,6 +88,10 @@ class IncrementalSearchPromptMode(object):
|
||||
else:
|
||||
self.line=""
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class SearchPromptMode(object):
|
||||
def __init__(self, rlobj):
|
||||
pass
|
||||
@@ -143,12 +147,58 @@ class SearchPromptMode(object):
|
||||
for a string supplied by the user.'''
|
||||
return self._init_non_i_search(1)
|
||||
|
||||
class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode):
|
||||
class LeaveModeTryNext(Exception): pass
|
||||
|
||||
class DigitArgumentMode(object):
|
||||
def __init__(self, rlobj):
|
||||
pass
|
||||
|
||||
def _process_digit_argument_keyevent(self, keyinfo):
|
||||
log_sock("_process_digit_argument_keyevent %s"%keyinfo)
|
||||
keytuple=keyinfo.tuple()
|
||||
log_sock("%s %s"%(keyinfo,keytuple))
|
||||
if keyinfo.keyname in ['return']:
|
||||
self.prompt=self._digit_argument_oldprompt
|
||||
self.process_keyevent_queue=self.process_keyevent_queue[:-1]
|
||||
return True
|
||||
elif keyinfo.keyname:
|
||||
pass
|
||||
elif keyinfo.char in "0123456789" and keyinfo.control==False and keyinfo.meta==False :
|
||||
log_sock("arg %s %s"%(self.argument,keyinfo.char))
|
||||
self.argument=self.argument*10+int(keyinfo.char)
|
||||
else:
|
||||
self.prompt=self._digit_argument_oldprompt
|
||||
raise LeaveModeTryNext
|
||||
self.prompt="(arg: %s) "%self.argument
|
||||
|
||||
def _init_digit_argument(self, keyinfo):
|
||||
"""Initialize search prompt
|
||||
"""
|
||||
c = self.console
|
||||
line = self.l_buffer.get_line_text()
|
||||
self._digit_argument_oldprompt = self.prompt
|
||||
self.process_keyevent_queue.append(self._process_digit_argument_keyevent)
|
||||
|
||||
if keyinfo.char=="-":
|
||||
self.argument=-1
|
||||
elif keyinfo.char in "0123456789":
|
||||
self.argument=int(keyinfo.char)
|
||||
log_sock("<%s> %s"%(self.argument,type(self.argument)))
|
||||
self.prompt="(arg: %s) "%self.argument
|
||||
log_sock("arg-init %s %s"%(self.argument,keyinfo.char))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode):
|
||||
mode="emacs"
|
||||
def __init__(self, rlobj):
|
||||
basemode.BaseMode.__init__(self, rlobj)
|
||||
IncrementalSearchPromptMode.__init__(self, rlobj)
|
||||
SearchPromptMode.__init__(self, rlobj)
|
||||
DigitArgumentMode.__init__(self, rlobj)
|
||||
self._keylog=(lambda x,y: None)
|
||||
self.previous_func=None
|
||||
self.prompt=">>>"
|
||||
@@ -165,7 +215,11 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
self._keylog=logfun
|
||||
|
||||
def process_keyevent(self, keyinfo):
|
||||
r=self.process_keyevent_queue[-1](keyinfo)
|
||||
try:
|
||||
r=self.process_keyevent_queue[-1](keyinfo)
|
||||
except LeaveModeTryNext:
|
||||
self.process_keyevent_queue=self.process_keyevent_queue[:-1]
|
||||
r=self.process_keyevent(keyinfo)
|
||||
if r:
|
||||
self.add_history(self.l_buffer.copy())
|
||||
return True
|
||||
@@ -175,6 +229,7 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
"""return True when line is final
|
||||
"""
|
||||
#Process exit keys. Only exit on empty line
|
||||
log_sock("_process_keyevent %s"%keyinfo)
|
||||
def nop(e):
|
||||
pass
|
||||
if self.next_meta:
|
||||
@@ -185,6 +240,7 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
if self._insert_verbatim:
|
||||
self.insert_text(keyinfo)
|
||||
self._insert_verbatim=False
|
||||
self.argument=0
|
||||
return False
|
||||
|
||||
if keytuple in self.exit_dispatch:
|
||||
@@ -209,36 +265,40 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
self.previous_func = dispatch_func
|
||||
return r
|
||||
|
||||
|
||||
######### History commands
|
||||
def previous_history(self, e): # (C-p)
|
||||
'''Move back through the history list, fetching the previous command. '''
|
||||
self._history.previous_history(self.l_buffer)
|
||||
self.l_buffer.point=lineobj.EndOfLine
|
||||
self.finalize()
|
||||
|
||||
def next_history(self, e): # (C-n)
|
||||
'''Move forward through the history list, fetching the next command. '''
|
||||
self._history.next_history(self.l_buffer)
|
||||
self.finalize()
|
||||
|
||||
def beginning_of_history(self, e): # (M-<)
|
||||
'''Move to the first line in the history.'''
|
||||
self._history.beginning_of_history()
|
||||
self.finalize()
|
||||
|
||||
def end_of_history(self, e): # (M->)
|
||||
'''Move to the end of the input history, i.e., the line currently
|
||||
being entered.'''
|
||||
self._history.end_of_history(self.l_buffer)
|
||||
|
||||
self.finalize()
|
||||
|
||||
def reverse_search_history(self, e): # (C-r)
|
||||
'''Search backward starting at the current line and moving up
|
||||
through the history as necessary. This is an incremental search.'''
|
||||
self._init_incremental_search(self._history.reverse_search_history, -1, e)
|
||||
self.finalize()
|
||||
|
||||
def forward_search_history(self, e): # (C-s)
|
||||
'''Search forward starting at the current line and moving down
|
||||
through the the history as necessary. This is an incremental search.'''
|
||||
self._init_incremental_search(self._history.forward_search_history, 1, e)
|
||||
self.finalize()
|
||||
|
||||
def history_search_forward(self, e): # ()
|
||||
'''Search forward through the history for the string of characters
|
||||
@@ -251,6 +311,7 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
q=self._history.history_search_forward(self.l_buffer)
|
||||
self.l_buffer=q
|
||||
self.l_buffer.point=q.point
|
||||
self.finalize()
|
||||
|
||||
def history_search_backward(self, e): # ()
|
||||
'''Search backward through the history for the string of characters
|
||||
@@ -263,6 +324,7 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
q=self._history.history_search_backward(self.l_buffer)
|
||||
self.l_buffer=q
|
||||
self.l_buffer.point=q.point
|
||||
self.finalize()
|
||||
|
||||
|
||||
def yank_nth_arg(self, e): # (M-C-y)
|
||||
@@ -271,30 +333,32 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
insert the nth word from the previous command (the words in the
|
||||
previous command begin with word 0). A negative argument inserts the
|
||||
nth word from the end of the previous command.'''
|
||||
pass
|
||||
self.finalize()
|
||||
|
||||
def yank_last_arg(self, e): # (M-. or M-_)
|
||||
'''Insert last argument to the previous command (the last word of
|
||||
the previous history entry). With an argument, behave exactly like
|
||||
yank-nth-arg. Successive calls to yank-last-arg move back through
|
||||
the history list, inserting the last argument of each line in turn.'''
|
||||
pass
|
||||
self.finalize()
|
||||
|
||||
def forward_backward_delete_char(self, e): # ()
|
||||
'''Delete the character under the cursor, unless the cursor is at
|
||||
the end of the line, in which case the character behind the cursor
|
||||
is deleted. By default, this is not bound to a key.'''
|
||||
pass
|
||||
self.finalize()
|
||||
|
||||
def quoted_insert(self, e): # (C-q or C-v)
|
||||
'''Add the next character typed to the line verbatim. This is how to
|
||||
insert key sequences like C-q, for example.'''
|
||||
self._insert_verbatim=True
|
||||
self.finalize()
|
||||
|
||||
def tab_insert(self, e): # (M-TAB)
|
||||
'''Insert a tab character. '''
|
||||
ws = ' ' * (self.tabstop - (self.l_buffer.point%self.tabstop))
|
||||
self.insert_text(ws)
|
||||
self.finalize()
|
||||
|
||||
def transpose_chars(self, e): # (C-t)
|
||||
'''Drag the character before the cursor forward over the character
|
||||
@@ -302,12 +366,14 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
point is at the end of the line, then this transposes the last two
|
||||
characters of the line. Negative arguments have no effect.'''
|
||||
self.l_buffer.transpose_chars()
|
||||
self.finalize()
|
||||
|
||||
def transpose_words(self, e): # (M-t)
|
||||
'''Drag the word before point past the word after point, moving
|
||||
point past that word as well. If the insertion point is at the end
|
||||
of the line, this transposes the last two words on the line.'''
|
||||
self.l_buffer.transpose_words()
|
||||
self.finalize()
|
||||
|
||||
def overwrite_mode(self, e): # ()
|
||||
'''Toggle overwrite mode. With an explicit positive numeric
|
||||
@@ -318,115 +384,195 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
bound to self-insert replace the text at point rather than pushing
|
||||
the text to the right. Characters bound to backward-delete-char
|
||||
replace the character before point with a space.'''
|
||||
pass
|
||||
self.finalize()
|
||||
|
||||
def kill_line(self, e): # (C-k)
|
||||
'''Kill the text from point to the end of the line. '''
|
||||
self.l_buffer.kill_line()
|
||||
self.finalize()
|
||||
|
||||
def backward_kill_line(self, e): # (C-x Rubout)
|
||||
'''Kill backward to the beginning of the line. '''
|
||||
self.l_buffer.backward_kill_line()
|
||||
self.finalize()
|
||||
|
||||
def unix_line_discard(self, e): # (C-u)
|
||||
'''Kill backward from the cursor to the beginning of the current line. '''
|
||||
# how is this different from backward_kill_line?
|
||||
self.l_buffer.unix_line_discard()
|
||||
self.finalize()
|
||||
|
||||
def kill_whole_line(self, e): # ()
|
||||
'''Kill all characters on the current line, no matter where point
|
||||
is. By default, this is unbound.'''
|
||||
self.l_buffer.kill_whole_line()
|
||||
self.finalize()
|
||||
|
||||
def kill_word(self, e): # (M-d)
|
||||
'''Kill from point to the end of the current word, or if between
|
||||
words, to the end of the next word. Word boundaries are the same as
|
||||
forward-word.'''
|
||||
self.l_buffer.kill_word()
|
||||
self.finalize()
|
||||
|
||||
forward_kill_word=kill_word
|
||||
|
||||
|
||||
def backward_kill_word(self, e): # (M-DEL)
|
||||
'''Kill the word behind point. Word boundaries are the same as
|
||||
backward-word. '''
|
||||
self.l_buffer.backward_kill_word()
|
||||
|
||||
self.finalize()
|
||||
|
||||
def unix_word_rubout(self, e): # (C-w)
|
||||
'''Kill the word behind point, using white space as a word
|
||||
boundary. The killed text is saved on the kill-ring.'''
|
||||
self.l_buffer.unix_word_rubout()
|
||||
|
||||
self.finalize()
|
||||
|
||||
def kill_region(self, e): # ()
|
||||
'''Kill the text in the current region. By default, this command is unbound. '''
|
||||
pass
|
||||
|
||||
self.finalize()
|
||||
|
||||
def copy_region_as_kill(self, e): # ()
|
||||
'''Copy the text in the region to the kill buffer, so it can be
|
||||
yanked right away. By default, this command is unbound.'''
|
||||
pass
|
||||
|
||||
self.finalize()
|
||||
|
||||
def copy_backward_word(self, e): # ()
|
||||
'''Copy the word before point to the kill buffer. The word
|
||||
boundaries are the same as backward-word. By default, this command
|
||||
is unbound.'''
|
||||
pass
|
||||
|
||||
self.finalize()
|
||||
|
||||
def copy_forward_word(self, e): # ()
|
||||
'''Copy the word following point to the kill buffer. The word
|
||||
boundaries are the same as forward-word. By default, this command is
|
||||
unbound.'''
|
||||
pass
|
||||
|
||||
self.finalize()
|
||||
|
||||
|
||||
def yank(self, e): # (C-y)
|
||||
'''Yank the top of the kill ring into the buffer at point. '''
|
||||
self.l_buffer.yank()
|
||||
|
||||
self.finalize()
|
||||
|
||||
def yank_pop(self, e): # (M-y)
|
||||
'''Rotate the kill-ring, and yank the new top. You can only do this
|
||||
if the prior command is yank or yank-pop.'''
|
||||
self.l_buffer.yank_pop()
|
||||
self.finalize()
|
||||
|
||||
def delete_char_or_list(self, e): # ()
|
||||
'''Deletes the character under the cursor if not at the beginning or
|
||||
end of the line (like delete-char). If at the end of the line,
|
||||
behaves identically to possible-completions. This command is unbound
|
||||
by default.'''
|
||||
self.finalize()
|
||||
|
||||
def start_kbd_macro(self, e): # (C-x ()
|
||||
'''Begin saving the characters typed into the current keyboard macro. '''
|
||||
self.finalize()
|
||||
|
||||
def end_kbd_macro(self, e): # (C-x ))
|
||||
'''Stop saving the characters typed into the current keyboard macro
|
||||
and save the definition.'''
|
||||
self.finalize()
|
||||
|
||||
def call_last_kbd_macro(self, e): # (C-x e)
|
||||
'''Re-execute the last keyboard macro defined, by making the
|
||||
characters in the macro appear as if typed at the keyboard.'''
|
||||
self.finalize()
|
||||
|
||||
def re_read_init_file(self, e): # (C-x C-r)
|
||||
'''Read in the contents of the inputrc file, and incorporate any
|
||||
bindings or variable assignments found there.'''
|
||||
self.finalize()
|
||||
|
||||
def abort(self, e): # (C-g)
|
||||
'''Abort the current editing command and ring the terminals bell
|
||||
(subject to the setting of bell-style).'''
|
||||
self._bell()
|
||||
self.finalize()
|
||||
|
||||
def do_uppercase_version(self, e): # (M-a, M-b, M-x, ...)
|
||||
'''If the metafied character x is lowercase, run the command that is
|
||||
bound to the corresponding uppercase character.'''
|
||||
self.finalize()
|
||||
|
||||
def prefix_meta(self, e): # (ESC)
|
||||
'''Metafy the next character typed. This is for keyboards without a
|
||||
meta key. Typing ESC f is equivalent to typing M-f. '''
|
||||
self.next_meta = True
|
||||
self.finalize()
|
||||
|
||||
def undo(self, e): # (C-_ or C-x C-u)
|
||||
'''Incremental undo, separately remembered for each line.'''
|
||||
self.l_buffer.pop_undo()
|
||||
self.finalize()
|
||||
|
||||
def revert_line(self, e): # (M-r)
|
||||
'''Undo all changes made to this line. This is like executing the
|
||||
undo command enough times to get back to the beginning.'''
|
||||
self.finalize()
|
||||
|
||||
def tilde_expand(self, e): # (M-~)
|
||||
'''Perform tilde expansion on the current word.'''
|
||||
self.finalize()
|
||||
|
||||
def set_mark(self, e): # (C-@)
|
||||
'''Set the mark to the point. If a numeric argument is supplied, the
|
||||
mark is set to that position.'''
|
||||
self.l_buffer.set_mark()
|
||||
self.finalize()
|
||||
|
||||
def exchange_point_and_mark(self, e): # (C-x C-x)
|
||||
'''Swap the point with the mark. The current cursor position is set
|
||||
to the saved position, and the old cursor position is saved as the
|
||||
mark.'''
|
||||
self.finalize()
|
||||
|
||||
def character_search(self, e): # (C-])
|
||||
'''A character is read and point is moved to the next occurrence of
|
||||
that character. A negative count searches for previous occurrences.'''
|
||||
self.finalize()
|
||||
|
||||
def character_search_backward(self, e): # (M-C-])
|
||||
'''A character is read and point is moved to the previous occurrence
|
||||
of that character. A negative count searches for subsequent
|
||||
occurrences.'''
|
||||
self.finalize()
|
||||
|
||||
def insert_comment(self, e): # (M-#)
|
||||
'''Without a numeric argument, the value of the comment-begin
|
||||
variable is inserted at the beginning of the current line. If a
|
||||
numeric argument is supplied, this command acts as a toggle: if the
|
||||
characters at the beginning of the line do not match the value of
|
||||
comment-begin, the value is inserted, otherwise the characters in
|
||||
comment-begin are deleted from the beginning of the line. In either
|
||||
case, the line is accepted as if a newline had been typed.'''
|
||||
self.finalize()
|
||||
|
||||
def dump_variables(self, e): # ()
|
||||
'''Print all of the settable variables and their values to the
|
||||
Readline output stream. If a numeric argument is supplied, the
|
||||
output is formatted in such a way that it can be made part of an
|
||||
inputrc file. This command is unbound by default.'''
|
||||
self.finalize()
|
||||
|
||||
def dump_macros(self, e): # ()
|
||||
'''Print all of the Readline key sequences bound to macros and the
|
||||
strings they output. If a numeric argument is supplied, the output
|
||||
is formatted in such a way that it can be made part of an inputrc
|
||||
file. This command is unbound by default.'''
|
||||
self.finalize()
|
||||
|
||||
|
||||
|
||||
def digit_argument(self, e): # (M-0, M-1, ... M--)
|
||||
'''Add this digit to the argument already accumulating, or start a
|
||||
new argument. M-- starts a negative argument.'''
|
||||
args=e.char
|
||||
|
||||
c = self.console
|
||||
line = self.l_buffer.get_line_text()
|
||||
oldprompt=self.prompt
|
||||
def nop(e):
|
||||
pass
|
||||
while 1:
|
||||
x, y = self.prompt_end_pos
|
||||
c.pos(0, y)
|
||||
self.prompt="(arg: %s) "%args
|
||||
self._print_prompt()
|
||||
self._update_line()
|
||||
|
||||
event = c.getkeypress()
|
||||
if event.keyinfo.keyname == 'enter':
|
||||
break
|
||||
elif event.char in "0123456789":
|
||||
args+=event.char
|
||||
else:
|
||||
self.argument=int(args)
|
||||
keyinfo=event.keyinfo.tuple()
|
||||
if len(keyinfo[-1])>1:
|
||||
default=nop
|
||||
else:
|
||||
default=self.self_insert
|
||||
dispatch_func = self.key_dispatch.get(keyinfo,default)
|
||||
dispatch_func(event)
|
||||
break
|
||||
self.prompt=oldprompt
|
||||
x, y = self.prompt_end_pos
|
||||
c.pos(0, y)
|
||||
self._print_prompt()
|
||||
self._update_line()
|
||||
|
||||
|
||||
|
||||
self._init_digit_argument(e)
|
||||
#Should not finalize
|
||||
|
||||
def universal_argument(self, e): # ()
|
||||
'''This is another way to specify an argument. If this command is
|
||||
@@ -440,107 +586,7 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
executing this function the first time makes the argument count
|
||||
four, a second time makes the argument count sixteen, and so on. By
|
||||
default, this is not bound to a key.'''
|
||||
pass
|
||||
|
||||
def delete_char_or_list(self, e): # ()
|
||||
'''Deletes the character under the cursor if not at the beginning or
|
||||
end of the line (like delete-char). If at the end of the line,
|
||||
behaves identically to possible-completions. This command is unbound
|
||||
by default.'''
|
||||
pass
|
||||
|
||||
def start_kbd_macro(self, e): # (C-x ()
|
||||
'''Begin saving the characters typed into the current keyboard macro. '''
|
||||
pass
|
||||
|
||||
def end_kbd_macro(self, e): # (C-x ))
|
||||
'''Stop saving the characters typed into the current keyboard macro
|
||||
and save the definition.'''
|
||||
pass
|
||||
|
||||
def call_last_kbd_macro(self, e): # (C-x e)
|
||||
'''Re-execute the last keyboard macro defined, by making the
|
||||
characters in the macro appear as if typed at the keyboard.'''
|
||||
pass
|
||||
|
||||
def re_read_init_file(self, e): # (C-x C-r)
|
||||
'''Read in the contents of the inputrc file, and incorporate any
|
||||
bindings or variable assignments found there.'''
|
||||
pass
|
||||
|
||||
def abort(self, e): # (C-g)
|
||||
'''Abort the current editing command and ring the terminals bell
|
||||
(subject to the setting of bell-style).'''
|
||||
self._bell()
|
||||
|
||||
def do_uppercase_version(self, e): # (M-a, M-b, M-x, ...)
|
||||
'''If the metafied character x is lowercase, run the command that is
|
||||
bound to the corresponding uppercase character.'''
|
||||
pass
|
||||
|
||||
def prefix_meta(self, e): # (ESC)
|
||||
'''Metafy the next character typed. This is for keyboards without a
|
||||
meta key. Typing ESC f is equivalent to typing M-f. '''
|
||||
self.next_meta = True
|
||||
|
||||
def undo(self, e): # (C-_ or C-x C-u)
|
||||
'''Incremental undo, separately remembered for each line.'''
|
||||
self.l_buffer.pop_undo()
|
||||
|
||||
def revert_line(self, e): # (M-r)
|
||||
'''Undo all changes made to this line. This is like executing the
|
||||
undo command enough times to get back to the beginning.'''
|
||||
pass
|
||||
|
||||
def tilde_expand(self, e): # (M-~)
|
||||
'''Perform tilde expansion on the current word.'''
|
||||
pass
|
||||
|
||||
def set_mark(self, e): # (C-@)
|
||||
'''Set the mark to the point. If a numeric argument is supplied, the
|
||||
mark is set to that position.'''
|
||||
self.l_buffer.set_mark()
|
||||
|
||||
def exchange_point_and_mark(self, e): # (C-x C-x)
|
||||
'''Swap the point with the mark. The current cursor position is set
|
||||
to the saved position, and the old cursor position is saved as the
|
||||
mark.'''
|
||||
pass
|
||||
|
||||
def character_search(self, e): # (C-])
|
||||
'''A character is read and point is moved to the next occurrence of
|
||||
that character. A negative count searches for previous occurrences.'''
|
||||
pass
|
||||
|
||||
def character_search_backward(self, e): # (M-C-])
|
||||
'''A character is read and point is moved to the previous occurrence
|
||||
of that character. A negative count searches for subsequent
|
||||
occurrences.'''
|
||||
pass
|
||||
|
||||
def insert_comment(self, e): # (M-#)
|
||||
'''Without a numeric argument, the value of the comment-begin
|
||||
variable is inserted at the beginning of the current line. If a
|
||||
numeric argument is supplied, this command acts as a toggle: if the
|
||||
characters at the beginning of the line do not match the value of
|
||||
comment-begin, the value is inserted, otherwise the characters in
|
||||
comment-begin are deleted from the beginning of the line. In either
|
||||
case, the line is accepted as if a newline had been typed.'''
|
||||
pass
|
||||
|
||||
def dump_variables(self, e): # ()
|
||||
'''Print all of the settable variables and their values to the
|
||||
Readline output stream. If a numeric argument is supplied, the
|
||||
output is formatted in such a way that it can be made part of an
|
||||
inputrc file. This command is unbound by default.'''
|
||||
pass
|
||||
|
||||
def dump_macros(self, e): # ()
|
||||
'''Print all of the Readline key sequences bound to macros and the
|
||||
strings they output. If a numeric argument is supplied, the output
|
||||
is formatted in such a way that it can be made part of an inputrc
|
||||
file. This command is unbound by default.'''
|
||||
pass
|
||||
#Should not finalize
|
||||
|
||||
|
||||
#Create key bindings:
|
||||
@@ -622,6 +668,12 @@ class EmacsMode(IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode
|
||||
self._bind_key("divide", self.self_insert)
|
||||
self._bind_key("vk_decimal", self.self_insert)
|
||||
log("RUNNING INIT EMACS")
|
||||
for i in range(0,10):
|
||||
self._bind_key("alt-%d"%i, self.digit_argument)
|
||||
self._bind_key("alt--", self.digit_argument)
|
||||
|
||||
|
||||
|
||||
|
||||
# make it case insensitive
|
||||
def commonprefix(m):
|
||||
|
||||
Reference in New Issue
Block a user