mirror of
https://github.com/wassname/pyreadline.git
synced 2026-08-18 12:20:32 +08:00
Changed all strings to unicodestrings
This commit is contained in:
@@ -15,10 +15,10 @@ import pyreadline.lineeditor.history as history
|
||||
import pyreadline.clipboard as clipboard
|
||||
from pyreadline.error import ReadlineError,GetSetError
|
||||
from pyreadline.unicode_helper import ensure_str, ensure_unicode
|
||||
in_ironpython="IronPython" in sys.version
|
||||
in_ironpython=u"IronPython" in sys.version
|
||||
|
||||
class BaseMode(object):
|
||||
mode="base"
|
||||
mode=u"base"
|
||||
def __init__(self,rlobj):
|
||||
self.argument=0
|
||||
self.rlobj=rlobj
|
||||
@@ -28,9 +28,9 @@ class BaseMode(object):
|
||||
self.prevargument=None
|
||||
self.l_buffer=lineobj.ReadLineTextBuffer("")
|
||||
self._history=history.LineHistory()
|
||||
self.completer_delims = " \t\n\"\\'`@$><=;|&{("
|
||||
self.show_all_if_ambiguous = 'off'
|
||||
self.mark_directories = 'on'
|
||||
self.completer_delims = u" \t\n\"\\'`@$><=;|&{("
|
||||
self.show_all_if_ambiguous = u'off'
|
||||
self.mark_directories = u'on'
|
||||
self.completer = None
|
||||
self.begidx = 0
|
||||
self.endidx = 0
|
||||
@@ -40,7 +40,7 @@ class BaseMode(object):
|
||||
self.first_prompt = True
|
||||
self.cursor_size=25
|
||||
|
||||
self.prompt = ">>>"
|
||||
self.prompt = u">>> "
|
||||
|
||||
#Paste settings
|
||||
#assumes data on clipboard is path if shorter than 300 characters and doesn't contain \t or \n
|
||||
@@ -57,7 +57,7 @@ class BaseMode(object):
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "<BaseMode>"
|
||||
return u"<BaseMode>"
|
||||
|
||||
def _gs(x):
|
||||
def g(self):
|
||||
@@ -80,29 +80,29 @@ class BaseMode(object):
|
||||
argument_reset=property(_argreset)
|
||||
|
||||
#used in readline
|
||||
ctrl_c_tap_time_interval=property(*_gs("ctrl_c_tap_time_interval"))
|
||||
allow_ctrl_c=property(*_gs("allow_ctrl_c"))
|
||||
_print_prompt=property(_g("_print_prompt"))
|
||||
_update_line=property(_g("_update_line"))
|
||||
console=property(_g("console"))
|
||||
prompt_begin_pos=property(_g("prompt_begin_pos"))
|
||||
prompt_end_pos=property(_g("prompt_end_pos"))
|
||||
ctrl_c_tap_time_interval=property(*_gs(u"ctrl_c_tap_time_interval"))
|
||||
allow_ctrl_c=property(*_gs(u"allow_ctrl_c"))
|
||||
_print_prompt=property(_g(u"_print_prompt"))
|
||||
_update_line=property(_g(u"_update_line"))
|
||||
console=property(_g(u"console"))
|
||||
prompt_begin_pos=property(_g(u"prompt_begin_pos"))
|
||||
prompt_end_pos=property(_g(u"prompt_end_pos"))
|
||||
|
||||
#used in completer _completions
|
||||
# completer_delims=property(*_gs("completer_delims"))
|
||||
_bell=property(_g("_bell"))
|
||||
bell_style=property(_g("bell_style"))
|
||||
_bell=property(_g(u"_bell"))
|
||||
bell_style=property(_g(u"bell_style"))
|
||||
|
||||
#used in emacs
|
||||
_clear_after=property(_g("_clear_after"))
|
||||
_update_prompt_pos=property(_g("_update_prompt_pos"))
|
||||
_clear_after=property(_g(u"_clear_after"))
|
||||
_update_prompt_pos=property(_g(u"_update_prompt_pos"))
|
||||
|
||||
#not used in basemode or emacs
|
||||
|
||||
def process_keyevent(self, keyinfo):
|
||||
raise NotImplementedError
|
||||
|
||||
def readline_setup(self, prompt=''):
|
||||
def readline_setup(self, prompt=u''):
|
||||
self.l_buffer.selection_mark=-1
|
||||
if self.first_prompt:
|
||||
self.first_prompt = False
|
||||
@@ -110,7 +110,7 @@ class BaseMode(object):
|
||||
try:
|
||||
self.startup_hook()
|
||||
except:
|
||||
print 'startup hook failed'
|
||||
print u'startup hook failed'
|
||||
traceback.print_exc()
|
||||
|
||||
self.l_buffer.reset_line()
|
||||
@@ -120,7 +120,7 @@ class BaseMode(object):
|
||||
try:
|
||||
self.pre_input_hook()
|
||||
except:
|
||||
print 'pre_input_hook failed'
|
||||
print u'pre_input_hook failed'
|
||||
traceback.print_exc()
|
||||
self.pre_input_hook = None
|
||||
|
||||
@@ -129,7 +129,7 @@ class BaseMode(object):
|
||||
|
||||
|
||||
def finalize(self):
|
||||
"""Every bindable command should call this function for cleanup.
|
||||
u"""Every bindable command should call this function for cleanup.
|
||||
Except those that want to set argument to a non-zero value.
|
||||
"""
|
||||
self.argument=0
|
||||
@@ -141,12 +141,12 @@ class BaseMode(object):
|
||||
|
||||
#Create key bindings:
|
||||
def rl_settings_to_string(self):
|
||||
out=["%-20s: %s"%("show all if ambigous",self.show_all_if_ambiguous)]
|
||||
out.append("%-20s: %s"%("mark_directories",self.mark_directories))
|
||||
out.append("%-20s: %s"%("bell_style",self.bell_style))
|
||||
out.append("------------- key bindings ------------")
|
||||
tablepat="%-7s %-7s %-7s %-15s %-15s "
|
||||
out.append(tablepat%("Control","Meta","Shift","Keycode/char","Function"))
|
||||
out=[u"%-20s: %s"%(u"show all if ambigous",self.show_all_if_ambiguous)]
|
||||
out.append(u"%-20s: %s"%(u"mark_directories",self.mark_directories))
|
||||
out.append(u"%-20s: %s"%(u"bell_style",self.bell_style))
|
||||
out.append(u"------------- key bindings ------------")
|
||||
tablepat=u"%-7s %-7s %-7s %-15s %-15s "
|
||||
out.append(tablepat%(u"Control",u"Meta",u"Shift",u"Keycode/char",u"Function"))
|
||||
bindings=[(k[0],k[1],k[2],k[3],v.__name__) for k,v in self.key_dispatch.iteritems()]
|
||||
bindings.sort()
|
||||
for key in bindings:
|
||||
@@ -155,16 +155,16 @@ class BaseMode(object):
|
||||
|
||||
|
||||
def _bind_key(self, key, func):
|
||||
"""setup the mapping from key to call the function."""
|
||||
u"""setup the mapping from key to call the function."""
|
||||
if type(func) != type(self._bind_key):
|
||||
print "Trying to bind non method to keystroke:%s,%s"%(key,func)
|
||||
raise PyreadlineError("Trying to bind non method to keystroke:%s,%s,%s,%s"%(key,func,type(func),type(self._bind_key)))
|
||||
print u"Trying to bind non method to keystroke:%s,%s"%(key,func)
|
||||
raise PyreadlineError(u"Trying to bind non method to keystroke:%s,%s,%s,%s"%(key,func,type(func),type(self._bind_key)))
|
||||
keyinfo = make_KeyPress_from_keydescr(key.lower()).tuple()
|
||||
log(">>>%s -> %s<<<"%(keyinfo,func.__name__))
|
||||
log(u">>>%s -> %s<<<"%(keyinfo,func.__name__))
|
||||
self.key_dispatch[keyinfo] = func
|
||||
|
||||
def _bind_exit_key(self, key):
|
||||
"""setup the mapping from key to call the function."""
|
||||
u"""setup the mapping from key to call the function."""
|
||||
keyinfo = make_KeyPress_from_keydescr(key.lower()).tuple()
|
||||
self.exit_dispatch[keyinfo] = None
|
||||
|
||||
@@ -189,8 +189,8 @@ class BaseMode(object):
|
||||
if buf[self.begidx] in self.completer_delims:
|
||||
self.begidx += 1
|
||||
break
|
||||
text = ensure_str(''.join(buf[self.begidx:self.endidx]))
|
||||
log('complete text="%s"' % text)
|
||||
text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
|
||||
log(u'complete text="%s"' % text)
|
||||
i = 0
|
||||
while 1:
|
||||
try:
|
||||
@@ -202,18 +202,18 @@ class BaseMode(object):
|
||||
completions.append(r)
|
||||
else:
|
||||
break
|
||||
log('text completions=<%s>' % completions)
|
||||
log(u'text completions=<%s>' % completions)
|
||||
if not completions:
|
||||
# get the filename to complete
|
||||
while self.begidx > 0:
|
||||
self.begidx -= 1
|
||||
if buf[self.begidx] in ' \t\n':
|
||||
if buf[self.begidx] in u' \t\n':
|
||||
self.begidx += 1
|
||||
break
|
||||
text = ensure_str(''.join(buf[self.begidx:self.endidx]))
|
||||
log('file complete text="%s"' % text)
|
||||
text = ensure_str(u''.join(buf[self.begidx:self.endidx]))
|
||||
log(u'file complete text="%s"' % text)
|
||||
completions = map(ensure_unicode, glob.glob(os.path.expanduser(text) + '*'))
|
||||
if self.mark_directories == 'on':
|
||||
if self.mark_directories == u'on':
|
||||
mc = []
|
||||
for f in completions:
|
||||
if os.path.isdir(f):
|
||||
@@ -221,32 +221,32 @@ class BaseMode(object):
|
||||
else:
|
||||
mc.append(f)
|
||||
completions = mc
|
||||
log('fnames=<%s>' % completions)
|
||||
log(u'fnames=<%s>' % completions)
|
||||
return completions
|
||||
|
||||
|
||||
def _display_completions(self, completions):
|
||||
if not completions:
|
||||
return
|
||||
self.console.write('\n')
|
||||
self.console.write(u'\n')
|
||||
wmax = max(map(len, completions))
|
||||
w, h = self.console.size()
|
||||
cols = max(1, int((w-1) / (wmax+1)))
|
||||
rows = int(math.ceil(float(len(completions)) / cols))
|
||||
for row in range(rows):
|
||||
s = ''
|
||||
s = u''
|
||||
for col in range(cols):
|
||||
i = col*rows + row
|
||||
if i < len(completions):
|
||||
self.console.write(completions[i].ljust(wmax+1))
|
||||
self.console.write('\n')
|
||||
self.console.write(u'\n')
|
||||
if in_ironpython:
|
||||
self.prompt=sys.ps1
|
||||
self._print_prompt()
|
||||
|
||||
|
||||
def complete(self, e): # (TAB)
|
||||
"""Attempt to perform completion on the text before point. The
|
||||
u"""Attempt to perform completion on the text before point. The
|
||||
actual completion performed is application-specific. The default is
|
||||
filename completion."""
|
||||
completions = self._get_completions()
|
||||
@@ -257,7 +257,7 @@ class BaseMode(object):
|
||||
self.l_buffer[self.begidx:self.endidx] = rep
|
||||
self.l_buffer.point = point + len(rep) - (self.endidx - self.begidx)
|
||||
if len(completions) > 1:
|
||||
if self.show_all_if_ambiguous == 'on':
|
||||
if self.show_all_if_ambiguous == u'on':
|
||||
self._display_completions(completions)
|
||||
else:
|
||||
self._bell()
|
||||
@@ -266,13 +266,13 @@ class BaseMode(object):
|
||||
self.finalize()
|
||||
|
||||
def possible_completions(self, e): # (M-?)
|
||||
"""List the possible completions of the text before point. """
|
||||
u"""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
|
||||
u"""Insert all completions of the text before point that would have
|
||||
been generated by possible-completions."""
|
||||
completions = self._get_completions()
|
||||
b = self.begidx
|
||||
@@ -287,7 +287,7 @@ class BaseMode(object):
|
||||
self.finalize()
|
||||
|
||||
def menu_complete(self, e): # ()
|
||||
"""Similar to complete, but replaces the word to be completed with a
|
||||
u"""Similar to complete, but replaces the word to be completed with a
|
||||
single match from the list of possible completions. Repeated
|
||||
execution of menu-complete steps through the list of possible
|
||||
completions, inserting each match in turn. At the end of the list of
|
||||
@@ -302,95 +302,95 @@ class BaseMode(object):
|
||||
|
||||
|
||||
def insert_text(self, string):
|
||||
"""Insert text into the command line."""
|
||||
u"""Insert text into the command line."""
|
||||
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. """
|
||||
u"""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. """
|
||||
u"""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. """
|
||||
u"""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. """
|
||||
u"""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
|
||||
u"""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
|
||||
u"""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
|
||||
u"""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
|
||||
u"""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. """
|
||||
u"""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. """
|
||||
u"""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. """
|
||||
u"""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. """
|
||||
u"""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
|
||||
u"""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
|
||||
u"""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
|
||||
u"""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
|
||||
u"""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()
|
||||
@@ -399,19 +399,19 @@ class BaseMode(object):
|
||||
######## Change case
|
||||
|
||||
def upcase_word(self, e): # (M-u)
|
||||
"""Uppercase the current (or following) word. With a negative
|
||||
u"""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
|
||||
u"""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
|
||||
u"""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()
|
||||
@@ -419,17 +419,17 @@ class BaseMode(object):
|
||||
|
||||
########
|
||||
def clear_screen(self, e): # (C-l)
|
||||
"""Clear the screen and redraw the current line, leaving the current
|
||||
u"""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."""
|
||||
u"""Refresh the current line. By default, this is unbound."""
|
||||
self.finalize()
|
||||
|
||||
def accept_line(self, e): # (Newline or Return)
|
||||
"""Accept the line regardless of where the cursor is. If this line
|
||||
u"""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."""
|
||||
@@ -437,37 +437,37 @@ class BaseMode(object):
|
||||
return True
|
||||
|
||||
def delete_char(self, e): # (C-d)
|
||||
"""Delete the character at point. If point is at the beginning of
|
||||
u"""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
|
||||
u"""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
|
||||
u"""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
|
||||
u"""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. """
|
||||
u"""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. """
|
||||
u"""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()
|
||||
@@ -476,7 +476,7 @@ class BaseMode(object):
|
||||
# Paste from clipboard
|
||||
|
||||
def paste(self,e):
|
||||
"""Paste windows clipboard.
|
||||
u"""Paste windows clipboard.
|
||||
Assume single line strip other lines and end of line markers and trailing spaces""" #(Control-v)
|
||||
if self.enable_win32_clipboard:
|
||||
txt=clipboard.get_clipboard_text_and_convert(False)
|
||||
@@ -486,7 +486,7 @@ class BaseMode(object):
|
||||
self.finalize()
|
||||
|
||||
def paste_mulitline_code(self,e):
|
||||
"""Paste windows clipboard as multiline code.
|
||||
u"""Paste windows clipboard as multiline code.
|
||||
Removes any empty lines in the code"""
|
||||
reg=re.compile("\r?\n")
|
||||
if self.enable_win32_clipboard:
|
||||
@@ -504,7 +504,7 @@ class BaseMode(object):
|
||||
self.finalize()
|
||||
|
||||
def ipython_paste(self,e):
|
||||
"""Paste windows clipboard. If enable_ipython_paste_list_of_lists is
|
||||
u"""Paste windows clipboard. If enable_ipython_paste_list_of_lists is
|
||||
True then try to convert tabseparated data to repr of list of lists or
|
||||
repr of array.
|
||||
If enable_ipython_paste_for_paths==True then change \\ to / and spaces to \space"""
|
||||
@@ -519,22 +519,22 @@ class BaseMode(object):
|
||||
|
||||
|
||||
def copy_region_to_clipboard(self, e): # ()
|
||||
"""Copy the text in the region to the windows clipboard."""
|
||||
u"""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."""
|
||||
u"""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."""
|
||||
u"""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
|
||||
u"""Print all of the functions and their key bindings 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."""
|
||||
@@ -545,13 +545,13 @@ class BaseMode(object):
|
||||
self.finalize()
|
||||
|
||||
def commonprefix(m):
|
||||
"Given a list of pathnames, returns the longest common leading component"
|
||||
if not m: return ''
|
||||
u"Given a list of pathnames, returns the longest common leading component"
|
||||
if not m: return u''
|
||||
prefix = m[0]
|
||||
for item in m:
|
||||
for i in range(len(prefix)):
|
||||
if prefix[:i+1].lower() != item[:i+1].lower():
|
||||
prefix = prefix[:i]
|
||||
if i == 0: return ''
|
||||
if i == 0: return u''
|
||||
break
|
||||
return prefix
|
||||
|
||||
+159
-159
@@ -22,8 +22,8 @@ def format(keyinfo):
|
||||
else:
|
||||
k=keyinfo+(ord(keyinfo[-1]),)
|
||||
|
||||
return "(%s,%s,%s,%s,%x)"%k
|
||||
in_ironpython="IronPython" in sys.version
|
||||
return u"(%s,%s,%s,%s,%x)"%k
|
||||
in_ironpython=u"IronPython" in sys.version
|
||||
|
||||
class IncrementalSearchPromptMode(object):
|
||||
def __init__(self, rlobj):
|
||||
@@ -31,20 +31,20 @@ class IncrementalSearchPromptMode(object):
|
||||
|
||||
def _process_incremental_search_keyevent(self, keyinfo):
|
||||
keytuple=keyinfo.tuple()
|
||||
log("IncrementalSearchPromptMode %s %s"%(keyinfo,keytuple))
|
||||
if keyinfo.keyname == 'backspace':
|
||||
log(u"IncrementalSearchPromptMode %s %s"%(keyinfo,keytuple))
|
||||
if keyinfo.keyname == u'backspace':
|
||||
self.subsearch_query = self.subsearch_query[:-1]
|
||||
if len(self.subsearch_query) > 0:
|
||||
self.line=self.subsearch_fun(self.subsearch_query)
|
||||
else:
|
||||
self._bell()
|
||||
self.line="" #empty query means no search result
|
||||
elif keyinfo.keyname in ['return', 'escape']:
|
||||
elif keyinfo.keyname in [u'return', u'escape']:
|
||||
self._bell()
|
||||
self.prompt=self.subsearch_oldprompt
|
||||
self.process_keyevent_queue=self.process_keyevent_queue[:-1]
|
||||
self._history.history_cursor=len(self._history.history)
|
||||
if keyinfo.keyname == 'escape':
|
||||
if keyinfo.keyname == u'escape':
|
||||
self.l_buffer.set_line(self.subsearch_old_line)
|
||||
return False
|
||||
elif keyinfo.keyname:
|
||||
@@ -61,11 +61,11 @@ class IncrementalSearchPromptMode(object):
|
||||
self.l_buffer.set_line(self.line)
|
||||
|
||||
def _init_incremental_search(self, searchfun, direction, init_event):
|
||||
"""Initialize search prompt
|
||||
u"""Initialize search prompt
|
||||
"""
|
||||
self.subsearch_init_event=init_event.tuple()
|
||||
self.subsearch_direction=direction
|
||||
self.subsearch_query = ''
|
||||
self.subsearch_query = u''
|
||||
self.subsearch_fun = searchfun
|
||||
self.subsearch_old_line = self.l_buffer.get_line_text()
|
||||
|
||||
@@ -75,18 +75,18 @@ class IncrementalSearchPromptMode(object):
|
||||
|
||||
if (self.previous_func != self.history_search_forward and
|
||||
self.previous_func != self.history_search_backward):
|
||||
self.subsearch_query = ''.join(self.l_buffer[0:Point].get_line_text())
|
||||
self.subsearch_query = u''.join(self.l_buffer[0:Point].get_line_text())
|
||||
|
||||
|
||||
if self.subsearch_direction < 0:
|
||||
self.subsearch_prompt = "reverse-i-search`%s': "
|
||||
self.subsearch_prompt = u"reverse-i-search`%s': "
|
||||
else:
|
||||
self.subsearch_prompt = "forward-i-search`%s': "
|
||||
self.subsearch_prompt = u"forward-i-search`%s': "
|
||||
self.prompt=self.subsearch_prompt%""
|
||||
if self.subsearch_query:
|
||||
self.line=self._process_search_keyevent(init_event)
|
||||
else:
|
||||
self.line=""
|
||||
self.line=u""
|
||||
|
||||
class SearchPromptMode(object):
|
||||
def __init__(self, rlobj):
|
||||
@@ -94,11 +94,11 @@ class SearchPromptMode(object):
|
||||
|
||||
def _process_non_incremental_search_keyevent(self, keyinfo):
|
||||
keytuple=keyinfo.tuple()
|
||||
log("SearchPromptMode %s %s"%(keyinfo,keytuple))
|
||||
log(u"SearchPromptMode %s %s"%(keyinfo,keytuple))
|
||||
|
||||
if keyinfo.keyname == 'backspace':
|
||||
if keyinfo.keyname == u'backspace':
|
||||
self.non_inc_query = self.non_inc_query[:-1]
|
||||
elif keyinfo.keyname in ['return', 'escape']:
|
||||
elif keyinfo.keyname in [u'return', u'escape']:
|
||||
if self.non_inc_query:
|
||||
if self.non_inc_direction==-1:
|
||||
res=self._history.reverse_search_history(self.non_inc_query)
|
||||
@@ -109,7 +109,7 @@ class SearchPromptMode(object):
|
||||
self.prompt=self.non_inc_oldprompt
|
||||
self.process_keyevent_queue=self.process_keyevent_queue[:-1]
|
||||
self._history.history_cursor=len(self._history.history)
|
||||
if keyinfo.keyname == 'escape':
|
||||
if keyinfo.keyname == u'escape':
|
||||
self.l_buffer=self.non_inc_oldline
|
||||
else:
|
||||
self.l_buffer.set_line(res)
|
||||
@@ -120,25 +120,25 @@ class SearchPromptMode(object):
|
||||
self.non_inc_query += keyinfo.char
|
||||
else:
|
||||
pass
|
||||
self.prompt=self.non_inc_oldprompt+":"+self.non_inc_query
|
||||
self.prompt=self.non_inc_oldprompt+u":"+self.non_inc_query
|
||||
|
||||
def _init_non_i_search(self, direction):
|
||||
self.non_inc_direction = direction
|
||||
self.non_inc_query = ""
|
||||
self.non_inc_query = u""
|
||||
self.non_inc_oldprompt=self.prompt
|
||||
self.non_inc_oldline=self.l_buffer.copy()
|
||||
self.l_buffer.reset_line()
|
||||
self.prompt=self.non_inc_oldprompt+":"
|
||||
self.prompt=self.non_inc_oldprompt+u":"
|
||||
self.process_keyevent_queue.append(self._process_non_incremental_search_keyevent)
|
||||
|
||||
def non_incremental_reverse_search_history(self, e): # (M-p)
|
||||
'''Search backward starting at the current line and moving up
|
||||
u'''Search backward starting at the current line and moving up
|
||||
through the history as necessary using a non-incremental search for
|
||||
a string supplied by the user.'''
|
||||
return self._init_non_i_search(-1)
|
||||
|
||||
def non_incremental_forward_search_history(self, e): # (M-n)
|
||||
'''Search forward starting at the current line and moving down
|
||||
u'''Search forward starting at the current line and moving down
|
||||
through the the history as necessary using a non-incremental search
|
||||
for a string supplied by the user.'''
|
||||
return self._init_non_i_search(1)
|
||||
@@ -150,22 +150,22 @@ class DigitArgumentMode(object):
|
||||
pass
|
||||
|
||||
def _process_digit_argument_keyevent(self, keyinfo):
|
||||
log("DigitArgumentMode.keyinfo %s"%keyinfo)
|
||||
log(u"DigitArgumentMode.keyinfo %s"%keyinfo)
|
||||
keytuple=keyinfo.tuple()
|
||||
log("DigitArgumentMode.keytuple %s %s"%(keyinfo,keytuple))
|
||||
log(u"DigitArgumentMode.keytuple %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("arg %s %s"%(self.argument,keyinfo.char))
|
||||
elif keyinfo.char in u"0123456789" and keyinfo.control==False and keyinfo.meta==False :
|
||||
log(u"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
|
||||
self.prompt=u"(arg: %s) "%self.argument
|
||||
|
||||
def _init_digit_argument(self, keyinfo):
|
||||
"""Initialize search prompt
|
||||
@@ -177,11 +177,11 @@ class DigitArgumentMode(object):
|
||||
|
||||
if keyinfo.char=="-":
|
||||
self.argument=-1
|
||||
elif keyinfo.char in "0123456789":
|
||||
elif keyinfo.char in u"0123456789":
|
||||
self.argument=int(keyinfo.char)
|
||||
log("<%s> %s"%(self.argument,type(self.argument)))
|
||||
self.prompt="(arg: %s) "%self.argument
|
||||
log("arg-init %s %s"%(self.argument,keyinfo.char))
|
||||
log(u"<%s> %s"%(self.argument,type(self.argument)))
|
||||
self.prompt=u"(arg: %s) "%self.argument
|
||||
log(u"arg-init %s %s"%(self.argument,keyinfo.char))
|
||||
|
||||
|
||||
class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode, basemode.BaseMode):
|
||||
@@ -193,17 +193,17 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
DigitArgumentMode.__init__(self, rlobj)
|
||||
self._keylog=(lambda x,y: None)
|
||||
self.previous_func=None
|
||||
self.prompt=">>>"
|
||||
self.prompt=u">>> "
|
||||
self._insert_verbatim=False
|
||||
self.next_meta = False # True to force meta on next character
|
||||
|
||||
self.process_keyevent_queue=[self._process_keyevent]
|
||||
|
||||
def __repr__(self):
|
||||
return "<EmacsMode>"
|
||||
return u"<EmacsMode>"
|
||||
|
||||
def add_key_logger(self, logfun):
|
||||
"""logfun should be function that takes disp_fun and line_buffer object """
|
||||
u"""logfun should be function that takes disp_fun and line_buffer object """
|
||||
self._keylog=logfun
|
||||
|
||||
def process_keyevent(self, keyinfo):
|
||||
@@ -218,10 +218,10 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
return False
|
||||
|
||||
def _process_keyevent(self, keyinfo):
|
||||
"""return True when line is final
|
||||
u"""return True when line is final
|
||||
"""
|
||||
#Process exit keys. Only exit on empty line
|
||||
log("_process_keyevent <%s>"%keyinfo)
|
||||
log(u"_process_keyevent <%s>"%keyinfo)
|
||||
def nop(e):
|
||||
pass
|
||||
if self.next_meta:
|
||||
@@ -236,7 +236,7 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
return False
|
||||
|
||||
if keytuple in self.exit_dispatch:
|
||||
log("exit_dispatch:<%s, %s>"%(self.l_buffer, lineobj.EndOfLine(self.l_buffer)))
|
||||
log(u"exit_dispatch:<%s, %s>"%(self.l_buffer, lineobj.EndOfLine(self.l_buffer)))
|
||||
if lineobj.EndOfLine(self.l_buffer) == 0:
|
||||
raise EOFError
|
||||
if keyinfo.keyname or keyinfo.control or keyinfo.meta:
|
||||
@@ -245,7 +245,7 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
default=self.self_insert
|
||||
dispatch_func = self.key_dispatch.get(keytuple, default)
|
||||
|
||||
log("readline from keyboard:<%s,%s>"%(keytuple, dispatch_func))
|
||||
log(u"readline from keyboard:<%s,%s>"%(keytuple, dispatch_func))
|
||||
|
||||
r = None
|
||||
if dispatch_func:
|
||||
@@ -258,7 +258,7 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
|
||||
######### History commands
|
||||
def previous_history(self, e): # (C-p)
|
||||
'''Move back through the history list, fetching the previous command. '''
|
||||
u'''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()
|
||||
@@ -269,30 +269,30 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
self.finalize()
|
||||
|
||||
def beginning_of_history(self, e): # (M-<)
|
||||
'''Move to the first line in the history.'''
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''Search forward through the history for the string of characters
|
||||
between the start of the current line and the point. This is a
|
||||
non-incremental search. By default, this command is unbound.'''
|
||||
if self.previous_func and hasattr(self._history,self.previous_func.__name__):
|
||||
@@ -305,7 +305,7 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
self.finalize()
|
||||
|
||||
def history_search_backward(self, e): # ()
|
||||
'''Search backward through the history for the string of characters
|
||||
u'''Search backward through the history for the string of characters
|
||||
between the start of the current line and the point. This is a
|
||||
non-incremental search. By default, this command is unbound.'''
|
||||
if self.previous_func and hasattr(self._history,self.previous_func.__name__):
|
||||
@@ -319,7 +319,7 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
|
||||
|
||||
def yank_nth_arg(self, e): # (M-C-y)
|
||||
'''Insert the first argument to the previous command (usually the
|
||||
u'''Insert the first argument to the previous command (usually the
|
||||
second word on the previous line) at point. With an argument n,
|
||||
insert the nth word from the previous command (the words in the
|
||||
previous command begin with word 0). A negative argument inserts the
|
||||
@@ -327,33 +327,33 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
self.finalize()
|
||||
|
||||
def yank_last_arg(self, e): # (M-. or M-_)
|
||||
'''Insert last argument to the previous command (the last word of
|
||||
u'''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.'''
|
||||
self.finalize()
|
||||
|
||||
def forward_backward_delete_char(self, e): # ()
|
||||
'''Delete the character under the cursor, unless the cursor is at
|
||||
u'''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.'''
|
||||
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
|
||||
u'''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. '''
|
||||
u'''Insert a tab character. '''
|
||||
cursor = min(self.l_buffer.point, len(self.l_buffer.line_buffer))
|
||||
ws = ' ' * (self.tabstop - (cursor % 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
|
||||
u'''Drag the character before the cursor forward over the character
|
||||
at the cursor, moving the cursor forward as well. If the insertion
|
||||
point is at the end of the line, then this transposes the last two
|
||||
characters of the line. Negative arguments have no effect.'''
|
||||
@@ -361,14 +361,14 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
self.finalize()
|
||||
|
||||
def transpose_words(self, e): # (M-t)
|
||||
'''Drag the word before point past the word after point, moving
|
||||
u'''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
|
||||
u'''Toggle overwrite mode. With an explicit positive numeric
|
||||
argument, switches to overwrite mode. With an explicit non-positive
|
||||
numeric argument, switches to insert mode. This command affects only
|
||||
emacs mode; vi mode does overwrite differently. Each call to
|
||||
@@ -379,29 +379,29 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
self.finalize()
|
||||
|
||||
def kill_line(self, e): # (C-k)
|
||||
'''Kill the text from point to the end of the line. '''
|
||||
u'''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. '''
|
||||
u'''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. '''
|
||||
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
|
||||
u'''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
|
||||
u'''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()
|
||||
@@ -410,132 +410,132 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
forward_kill_word=kill_word
|
||||
|
||||
def backward_kill_word(self, e): # (M-DEL)
|
||||
'''Kill the word behind point. Word boundaries are the same as
|
||||
u'''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
|
||||
u'''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. '''
|
||||
u'''Kill the text in the current region. By default, this command is unbound. '''
|
||||
self.finalize()
|
||||
|
||||
def copy_region_as_kill(self, e): # ()
|
||||
'''Copy the text in the region to the kill buffer, so it can be
|
||||
u'''Copy the text in the region to the kill buffer, so it can be
|
||||
yanked right away. By default, this command is unbound.'''
|
||||
self.finalize()
|
||||
|
||||
def copy_backward_word(self, e): # ()
|
||||
'''Copy the word before point to the kill buffer. The word
|
||||
u'''Copy the word before point to the kill buffer. The word
|
||||
boundaries are the same as backward-word. By default, this command
|
||||
is unbound.'''
|
||||
self.finalize()
|
||||
|
||||
def copy_forward_word(self, e): # ()
|
||||
'''Copy the word following point to the kill buffer. The word
|
||||
u'''Copy the word following point to the kill buffer. The word
|
||||
boundaries are the same as forward-word. By default, this command is
|
||||
unbound.'''
|
||||
self.finalize()
|
||||
|
||||
|
||||
def yank(self, e): # (C-y)
|
||||
'''Yank the top of the kill ring into the buffer at point. '''
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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. '''
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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.'''
|
||||
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
|
||||
u'''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.'''
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
@@ -545,14 +545,14 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
self.finalize()
|
||||
|
||||
def dump_variables(self, e): # ()
|
||||
'''Print all of the settable variables and their values to the
|
||||
u'''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
|
||||
u'''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.'''
|
||||
@@ -561,13 +561,13 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
|
||||
|
||||
def digit_argument(self, e): # (M-0, M-1, ... M--)
|
||||
'''Add this digit to the argument already accumulating, or start a
|
||||
u'''Add this digit to the argument already accumulating, or start a
|
||||
new argument. M-- starts a negative argument.'''
|
||||
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
|
||||
u'''This is another way to specify an argument. If this command is
|
||||
followed by one or more digits, optionally with a leading minus
|
||||
sign, those digits define the argument. If the command is followed
|
||||
by digits, executing universal-argument again ends the numeric
|
||||
@@ -584,99 +584,99 @@ class EmacsMode(DigitArgumentMode, IncrementalSearchPromptMode, SearchPromptMode
|
||||
#Create key bindings:
|
||||
|
||||
def init_editing_mode(self, e): # (C-e)
|
||||
'''When in vi command mode, this causes a switch to emacs editing
|
||||
u'''When in vi command mode, this causes a switch to emacs editing
|
||||
mode.'''
|
||||
self._bind_exit_key('Control-d')
|
||||
self._bind_exit_key('Control-z')
|
||||
self._bind_exit_key(u'Control-d')
|
||||
self._bind_exit_key(u'Control-z')
|
||||
|
||||
# I often accidentally hold the shift or control while typing space
|
||||
self._bind_key('space', self.self_insert)
|
||||
self._bind_key('Shift-space', self.self_insert)
|
||||
self._bind_key('Control-space', self.self_insert)
|
||||
self._bind_key('Return', self.accept_line)
|
||||
self._bind_key('Left', self.backward_char)
|
||||
self._bind_key('Control-b', self.backward_char)
|
||||
self._bind_key('Right', self.forward_char)
|
||||
self._bind_key('Control-f', self.forward_char)
|
||||
self._bind_key('BackSpace', self.backward_delete_char)
|
||||
self._bind_key('Control-BackSpace', self.backward_delete_word)
|
||||
self._bind_key(u'space', self.self_insert)
|
||||
self._bind_key(u'Shift-space', self.self_insert)
|
||||
self._bind_key(u'Control-space', self.self_insert)
|
||||
self._bind_key(u'Return', self.accept_line)
|
||||
self._bind_key(u'Left', self.backward_char)
|
||||
self._bind_key(u'Control-b', self.backward_char)
|
||||
self._bind_key(u'Right', self.forward_char)
|
||||
self._bind_key(u'Control-f', self.forward_char)
|
||||
self._bind_key(u'BackSpace', self.backward_delete_char)
|
||||
self._bind_key(u'Control-BackSpace', self.backward_delete_word)
|
||||
|
||||
self._bind_key('Home', self.beginning_of_line)
|
||||
self._bind_key('End', self.end_of_line)
|
||||
self._bind_key('Delete', self.delete_char)
|
||||
self._bind_key('Control-d', self.delete_char)
|
||||
self._bind_key('Clear', self.clear_screen)
|
||||
self._bind_key('Alt-f', self.forward_word)
|
||||
self._bind_key('Alt-b', self.backward_word)
|
||||
self._bind_key('Control-l', self.clear_screen)
|
||||
self._bind_key('Control-p', self.previous_history)
|
||||
self._bind_key('Up', self.history_search_backward)
|
||||
self._bind_key('Control-n', self.next_history)
|
||||
self._bind_key('Down', self.history_search_forward)
|
||||
self._bind_key('Control-a', self.beginning_of_line)
|
||||
self._bind_key('Control-e', self.end_of_line)
|
||||
self._bind_key('Alt-<', self.beginning_of_history)
|
||||
self._bind_key('Alt->', self.end_of_history)
|
||||
self._bind_key('Control-r', self.reverse_search_history)
|
||||
self._bind_key('Control-s', self.forward_search_history)
|
||||
self._bind_key('Alt-p', self.non_incremental_reverse_search_history)
|
||||
self._bind_key('Alt-n', self.non_incremental_forward_search_history)
|
||||
self._bind_key('Control-z', self.undo)
|
||||
self._bind_key('Control-_', self.undo)
|
||||
self._bind_key('Escape', self.kill_whole_line)
|
||||
self._bind_key('Meta-d', self.kill_word)
|
||||
self._bind_key('Control-Delete', self.forward_delete_word)
|
||||
self._bind_key('Control-w', self.unix_word_rubout)
|
||||
self._bind_key(u'Home', self.beginning_of_line)
|
||||
self._bind_key(u'End', self.end_of_line)
|
||||
self._bind_key(u'Delete', self.delete_char)
|
||||
self._bind_key(u'Control-d', self.delete_char)
|
||||
self._bind_key(u'Clear', self.clear_screen)
|
||||
self._bind_key(u'Alt-f', self.forward_word)
|
||||
self._bind_key(u'Alt-b', self.backward_word)
|
||||
self._bind_key(u'Control-l', self.clear_screen)
|
||||
self._bind_key(u'Control-p', self.previous_history)
|
||||
self._bind_key(u'Up', self.history_search_backward)
|
||||
self._bind_key(u'Control-n', self.next_history)
|
||||
self._bind_key(u'Down', self.history_search_forward)
|
||||
self._bind_key(u'Control-a', self.beginning_of_line)
|
||||
self._bind_key(u'Control-e', self.end_of_line)
|
||||
self._bind_key(u'Alt-<', self.beginning_of_history)
|
||||
self._bind_key(u'Alt->', self.end_of_history)
|
||||
self._bind_key(u'Control-r', self.reverse_search_history)
|
||||
self._bind_key(u'Control-s', self.forward_search_history)
|
||||
self._bind_key(u'Alt-p', self.non_incremental_reverse_search_history)
|
||||
self._bind_key(u'Alt-n', self.non_incremental_forward_search_history)
|
||||
self._bind_key(u'Control-z', self.undo)
|
||||
self._bind_key(u'Control-_', self.undo)
|
||||
self._bind_key(u'Escape', self.kill_whole_line)
|
||||
self._bind_key(u'Meta-d', self.kill_word)
|
||||
self._bind_key(u'Control-Delete', self.forward_delete_word)
|
||||
self._bind_key(u'Control-w', self.unix_word_rubout)
|
||||
#self._bind_key('Control-Shift-v', self.quoted_insert)
|
||||
self._bind_key('Control-v', self.paste)
|
||||
self._bind_key('Alt-v', self.ipython_paste)
|
||||
self._bind_key('Control-y', self.yank)
|
||||
self._bind_key('Control-k', self.kill_line)
|
||||
self._bind_key('Control-m', self.set_mark)
|
||||
self._bind_key('Control-q', self.copy_region_to_clipboard)
|
||||
self._bind_key(u'Control-v', self.paste)
|
||||
self._bind_key(u'Alt-v', self.ipython_paste)
|
||||
self._bind_key(u'Control-y', self.yank)
|
||||
self._bind_key(u'Control-k', self.kill_line)
|
||||
self._bind_key(u'Control-m', self.set_mark)
|
||||
self._bind_key(u'Control-q', self.copy_region_to_clipboard)
|
||||
# self._bind_key('Control-shift-k', self.kill_whole_line)
|
||||
self._bind_key('Control-Shift-v', self.paste_mulitline_code)
|
||||
self._bind_key("Control-Right", self.forward_word_end)
|
||||
self._bind_key("Control-Left", self.backward_word)
|
||||
self._bind_key("Shift-Right", self.forward_char_extend_selection)
|
||||
self._bind_key("Shift-Left", self.backward_char_extend_selection)
|
||||
self._bind_key("Shift-Control-Right", self.forward_word_end_extend_selection)
|
||||
self._bind_key("Shift-Control-Left", self.backward_word_extend_selection)
|
||||
self._bind_key("Shift-Home", self.beginning_of_line_extend_selection)
|
||||
self._bind_key("Shift-End", self.end_of_line_extend_selection)
|
||||
self._bind_key("numpad0", self.self_insert)
|
||||
self._bind_key("numpad1", self.self_insert)
|
||||
self._bind_key("numpad2", self.self_insert)
|
||||
self._bind_key("numpad3", self.self_insert)
|
||||
self._bind_key("numpad4", self.self_insert)
|
||||
self._bind_key("numpad5", self.self_insert)
|
||||
self._bind_key("numpad6", self.self_insert)
|
||||
self._bind_key("numpad7", self.self_insert)
|
||||
self._bind_key("numpad8", self.self_insert)
|
||||
self._bind_key("numpad9", self.self_insert)
|
||||
self._bind_key("add", self.self_insert)
|
||||
self._bind_key("subtract", self.self_insert)
|
||||
self._bind_key("multiply", self.self_insert)
|
||||
self._bind_key("divide", self.self_insert)
|
||||
self._bind_key("vk_decimal", self.self_insert)
|
||||
log("RUNNING INIT EMACS")
|
||||
self._bind_key(u'Control-Shift-v', self.paste_mulitline_code)
|
||||
self._bind_key(u"Control-Right", self.forward_word_end)
|
||||
self._bind_key(u"Control-Left", self.backward_word)
|
||||
self._bind_key(u"Shift-Right", self.forward_char_extend_selection)
|
||||
self._bind_key(u"Shift-Left", self.backward_char_extend_selection)
|
||||
self._bind_key(u"Shift-Control-Right", self.forward_word_end_extend_selection)
|
||||
self._bind_key(u"Shift-Control-Left", self.backward_word_extend_selection)
|
||||
self._bind_key(u"Shift-Home", self.beginning_of_line_extend_selection)
|
||||
self._bind_key(u"Shift-End", self.end_of_line_extend_selection)
|
||||
self._bind_key(u"numpad0", self.self_insert)
|
||||
self._bind_key(u"numpad1", self.self_insert)
|
||||
self._bind_key(u"numpad2", self.self_insert)
|
||||
self._bind_key(u"numpad3", self.self_insert)
|
||||
self._bind_key(u"numpad4", self.self_insert)
|
||||
self._bind_key(u"numpad5", self.self_insert)
|
||||
self._bind_key(u"numpad6", self.self_insert)
|
||||
self._bind_key(u"numpad7", self.self_insert)
|
||||
self._bind_key(u"numpad8", self.self_insert)
|
||||
self._bind_key(u"numpad9", self.self_insert)
|
||||
self._bind_key(u"add", self.self_insert)
|
||||
self._bind_key(u"subtract", self.self_insert)
|
||||
self._bind_key(u"multiply", self.self_insert)
|
||||
self._bind_key(u"divide", self.self_insert)
|
||||
self._bind_key(u"vk_decimal", self.self_insert)
|
||||
log(u"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)
|
||||
self._bind_key(u"alt-%d"%i, self.digit_argument)
|
||||
self._bind_key(u"alt--", self.digit_argument)
|
||||
|
||||
|
||||
|
||||
|
||||
# make it case insensitive
|
||||
def commonprefix(m):
|
||||
"Given a list of pathnames, returns the longest common leading component"
|
||||
u"Given a list of pathnames, returns the longest common leading component"
|
||||
if not m: return ''
|
||||
prefix = m[0]
|
||||
for item in m:
|
||||
for i in range(len(prefix)):
|
||||
if prefix[:i+1].lower() != item[:i+1].lower():
|
||||
prefix = prefix[:i]
|
||||
if i == 0: return ''
|
||||
if i == 0: return u''
|
||||
break
|
||||
return prefix
|
||||
|
||||
|
||||
+115
-115
@@ -14,12 +14,12 @@ import pyreadline.lineeditor.history as history
|
||||
import basemode
|
||||
|
||||
class NotEmacsMode(basemode.BaseMode):
|
||||
mode="notemacs"
|
||||
mode=u"notemacs"
|
||||
def __init__(self,rlobj):
|
||||
super(NotEmacsMode,self).__init__(rlobj)
|
||||
|
||||
def __repr__(self):
|
||||
return "<NotEmacsMode>"
|
||||
return u"<NotEmacsMode>"
|
||||
|
||||
def _readline_from_keyboard(self):
|
||||
c=self.console
|
||||
@@ -37,7 +37,7 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
raise EOFError
|
||||
|
||||
dispatch_func = self.key_dispatch.get(event.keyinfo,self.self_insert)
|
||||
log("readline from keyboard:%s"%(event.keyinfo,))
|
||||
log(u"readline from keyboard:%s"%(event.keyinfo,))
|
||||
r = None
|
||||
if dispatch_func:
|
||||
r = dispatch_func(event)
|
||||
@@ -49,7 +49,7 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
break
|
||||
|
||||
def readline(self, prompt=''):
|
||||
'''Try to act like GNU readline.'''
|
||||
u'''Try to act like GNU readline.'''
|
||||
# handle startup_hook
|
||||
if self.first_prompt:
|
||||
self.first_prompt = False
|
||||
@@ -57,7 +57,7 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
try:
|
||||
self.startup_hook()
|
||||
except:
|
||||
print 'startup hook failed'
|
||||
print u'startup hook failed'
|
||||
traceback.print_exc()
|
||||
|
||||
c = self.console
|
||||
@@ -69,64 +69,64 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
try:
|
||||
self.pre_input_hook()
|
||||
except:
|
||||
print 'pre_input_hook failed'
|
||||
print u'pre_input_hook failed'
|
||||
traceback.print_exc()
|
||||
self.pre_input_hook = None
|
||||
|
||||
log("in readline: %s"%self.paste_line_buffer)
|
||||
log(u"in readline: %s"%self.paste_line_buffer)
|
||||
if len(self.paste_line_buffer)>0:
|
||||
self.l_buffer=lineobj.ReadlineTextBuffer(self.paste_line_buffer[0])
|
||||
self._update_line()
|
||||
self.paste_line_buffer=self.paste_line_buffer[1:]
|
||||
c.write('\r\n')
|
||||
c.write(u'\r\n')
|
||||
else:
|
||||
self._readline_from_keyboard()
|
||||
c.write('\r\n')
|
||||
c.write(u'\r\n')
|
||||
|
||||
self.add_history(self.l_buffer.copy())
|
||||
|
||||
log('returning(%s)' % self.l_buffer.get_line_text())
|
||||
log(u'returning(%s)' % self.l_buffer.get_line_text())
|
||||
return self.l_buffer.get_line_text() + '\n'
|
||||
|
||||
### Methods below here are bindable emacs functions
|
||||
|
||||
def beginning_of_line(self, e): # (C-a)
|
||||
'''Move to the start of the current line. '''
|
||||
u'''Move to the start of the current line. '''
|
||||
self.l_buffer.beginning_of_line()
|
||||
|
||||
def end_of_line(self, e): # (C-e)
|
||||
'''Move to the end of the line. '''
|
||||
u'''Move to the end of the line. '''
|
||||
self.l_buffer.end_of_line()
|
||||
|
||||
def forward_char(self, e): # (C-f)
|
||||
'''Move forward a character. '''
|
||||
u'''Move forward a character. '''
|
||||
self.l_buffer.forward_char()
|
||||
|
||||
def backward_char(self, e): # (C-b)
|
||||
'''Move back a character. '''
|
||||
u'''Move back a character. '''
|
||||
self.l_buffer.backward_char()
|
||||
|
||||
def forward_word(self, e): # (M-f)
|
||||
'''Move forward to the end of the next word. Words are composed of
|
||||
u'''Move forward to the end of the next word. Words are composed of
|
||||
letters and digits.'''
|
||||
self.l_buffer.forward_word()
|
||||
|
||||
def backward_word(self, e): # (M-b)
|
||||
'''Move back to the start of the current or previous word. Words are
|
||||
u'''Move back to the start of the current or previous word. Words are
|
||||
composed of letters and digits.'''
|
||||
self.l_buffer.backward_word()
|
||||
|
||||
def clear_screen(self, e): # (C-l)
|
||||
'''Clear the screen and redraw the current line, leaving the current
|
||||
u'''Clear the screen and redraw the current line, leaving the current
|
||||
line at the top of the screen.'''
|
||||
self.console.page()
|
||||
|
||||
def redraw_current_line(self, e): # ()
|
||||
'''Refresh the current line. By default, this is unbound.'''
|
||||
u'''Refresh the current line. By default, this is unbound.'''
|
||||
pass
|
||||
|
||||
def accept_line(self, e): # (Newline or Return)
|
||||
'''Accept the line regardless of where the cursor is. If this line
|
||||
u'''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.'''
|
||||
@@ -134,47 +134,47 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
|
||||
######### History commands
|
||||
def previous_history(self, e): # (C-p)
|
||||
'''Move back through the history list, fetching the previous command. '''
|
||||
u'''Move back through the history list, fetching the previous command. '''
|
||||
self._history.previous_history(self.l_buffer)
|
||||
|
||||
def next_history(self, e): # (C-n)
|
||||
'''Move forward through the history list, fetching the next command. '''
|
||||
u'''Move forward through the history list, fetching the next command. '''
|
||||
self._history.next_history(self.l_buffer)
|
||||
|
||||
def beginning_of_history(self, e): # (M-<)
|
||||
'''Move to the first line in the history.'''
|
||||
u'''Move to the first line in the history.'''
|
||||
self._history.beginning_of_history()
|
||||
|
||||
def end_of_history(self, e): # (M->)
|
||||
'''Move to the end of the input history, i.e., the line currently
|
||||
u'''Move to the end of the input history, i.e., the line currently
|
||||
being entered.'''
|
||||
self._history.end_of_history(self.l_buffer)
|
||||
|
||||
def _i_search(self, searchfun, direction, init_event):
|
||||
c = self.console
|
||||
line = self.get_line_buffer()
|
||||
query = ''
|
||||
query = u''
|
||||
hc_start = self._history.history_cursor #+ direction
|
||||
while 1:
|
||||
x, y = self.prompt_end_pos
|
||||
c.pos(0, y)
|
||||
if direction < 0:
|
||||
prompt = 'reverse-i-search'
|
||||
prompt = u'reverse-i-search'
|
||||
else:
|
||||
prompt = 'forward-i-search'
|
||||
prompt = u'forward-i-search'
|
||||
|
||||
scroll = c.write_scrolling("%s`%s': %s" % (prompt, query, line))
|
||||
scroll = c.write_scrolling(u"%s`%s': %s" % (prompt, query, line))
|
||||
self._update_prompt_pos(scroll)
|
||||
self._clear_after()
|
||||
|
||||
event = c.getkeypress()
|
||||
if event.keysym == 'BackSpace':
|
||||
if event.keysym == u'BackSpace':
|
||||
if len(query) > 0:
|
||||
query = query[:-1]
|
||||
self._history.history_cursor = hc_start
|
||||
else:
|
||||
self._bell()
|
||||
elif event.char in string.letters + string.digits + string.punctuation + ' ':
|
||||
elif event.char in string.letters + string.digits + string.punctuation + u' ':
|
||||
self._history.history_cursor = hc_start
|
||||
query += event.char
|
||||
elif event.keyinfo == init_event.keyinfo:
|
||||
@@ -182,7 +182,7 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
line=searchfun(query)
|
||||
pass
|
||||
else:
|
||||
if event.keysym != 'Return':
|
||||
if event.keysym != u'Return':
|
||||
self._bell()
|
||||
break
|
||||
line=searchfun(query)
|
||||
@@ -194,14 +194,14 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
self._history.history_cursor=len(self._history.history)
|
||||
|
||||
def reverse_search_history(self, e): # (C-r)
|
||||
'''Search backward starting at the current line and moving up
|
||||
u'''Search backward starting at the current line and moving up
|
||||
through the history as necessary. This is an incremental search.'''
|
||||
# print "HEJ"
|
||||
# self.console.bell()
|
||||
self._i_search(self._history.reverse_search_history, -1, e)
|
||||
|
||||
def forward_search_history(self, e): # (C-s)
|
||||
'''Search forward starting at the current line and moving down
|
||||
u'''Search forward starting at the current line and moving down
|
||||
through the the history as necessary. This is an incremental search.'''
|
||||
# print "HEJ"
|
||||
# self.console.bell()
|
||||
@@ -209,31 +209,31 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
|
||||
|
||||
def non_incremental_reverse_search_history(self, e): # (M-p)
|
||||
'''Search backward starting at the current line and moving up
|
||||
u'''Search backward starting at the current line and moving up
|
||||
through the history as necessary using a non-incremental search for
|
||||
a string supplied by the user.'''
|
||||
self._history.non_incremental_reverse_search_history(self.l_buffer)
|
||||
|
||||
def non_incremental_forward_search_history(self, e): # (M-n)
|
||||
'''Search forward starting at the current line and moving down
|
||||
u'''Search forward starting at the current line and moving down
|
||||
through the the history as necessary using a non-incremental search
|
||||
for a string supplied by the user.'''
|
||||
self._history.non_incremental_reverse_search_history(self.l_buffer)
|
||||
|
||||
def history_search_forward(self, e): # ()
|
||||
'''Search forward through the history for the string of characters
|
||||
u'''Search forward through the history for the string of characters
|
||||
between the start of the current line and the point. This is a
|
||||
non-incremental search. By default, this command is unbound.'''
|
||||
self.l_buffer=self._history.history_search_forward(self.l_buffer)
|
||||
|
||||
def history_search_backward(self, e): # ()
|
||||
'''Search backward through the history for the string of characters
|
||||
u'''Search backward through the history for the string of characters
|
||||
between the start of the current line and the point. This is a
|
||||
non-incremental search. By default, this command is unbound.'''
|
||||
self.l_buffer=self._history.history_search_backward(self.l_buffer)
|
||||
|
||||
def yank_nth_arg(self, e): # (M-C-y)
|
||||
'''Insert the first argument to the previous command (usually the
|
||||
u'''Insert the first argument to the previous command (usually the
|
||||
second word on the previous line) at point. With an argument n,
|
||||
insert the nth word from the previous command (the words in the
|
||||
previous command begin with word 0). A negative argument inserts the
|
||||
@@ -241,76 +241,76 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
pass
|
||||
|
||||
def yank_last_arg(self, e): # (M-. or M-_)
|
||||
'''Insert last argument to the previous command (the last word of
|
||||
u'''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
|
||||
|
||||
def delete_char(self, e): # (C-d)
|
||||
'''Delete the character at point. If point is at the beginning of
|
||||
u'''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()
|
||||
|
||||
def backward_delete_char(self, e): # (Rubout)
|
||||
'''Delete the character behind the cursor. A numeric argument means
|
||||
u'''Delete the character behind the cursor. A numeric argument means
|
||||
to kill the characters instead of deleting them.'''
|
||||
self.l_buffer.backward_delete_char()
|
||||
|
||||
def forward_backward_delete_char(self, e): # ()
|
||||
'''Delete the character under the cursor, unless the cursor is at
|
||||
u'''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
|
||||
|
||||
def quoted_insert(self, e): # (C-q or C-v)
|
||||
'''Add the next character typed to the line verbatim. This is how to
|
||||
u'''Add the next character typed to the line verbatim. This is how to
|
||||
insert key sequences like C-q, for example.'''
|
||||
e = self.console.getkeypress()
|
||||
self.insert_text(e.char)
|
||||
|
||||
def tab_insert(self, e): # (M-TAB)
|
||||
'''Insert a tab character. '''
|
||||
u'''Insert a tab character. '''
|
||||
cursor = min(self.l_buffer.point, len(self.l_buffer.line_buffer))
|
||||
ws = ' ' * (self.tabstop - (cursor % self.tabstop))
|
||||
self.insert_text(ws)
|
||||
|
||||
def self_insert(self, e): # (a, b, A, 1, !, ...)
|
||||
'''Insert yourself. '''
|
||||
u'''Insert yourself. '''
|
||||
if ord(e.char)!=0: #don't insert null character in buffer, can happen with dead keys.
|
||||
self.insert_text(e.char)
|
||||
|
||||
def transpose_chars(self, e): # (C-t)
|
||||
'''Drag the character before the cursor forward over the character
|
||||
u'''Drag the character before the cursor forward over the character
|
||||
at the cursor, moving the cursor forward as well. If the insertion
|
||||
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()
|
||||
|
||||
def transpose_words(self, e): # (M-t)
|
||||
'''Drag the word before point past the word after point, moving
|
||||
u'''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()
|
||||
|
||||
def upcase_word(self, e): # (M-u)
|
||||
'''Uppercase the current (or following) word. With a negative
|
||||
u'''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()
|
||||
|
||||
def downcase_word(self, e): # (M-l)
|
||||
'''Lowercase the current (or following) word. With a negative
|
||||
u'''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()
|
||||
|
||||
def capitalize_word(self, e): # (M-c)
|
||||
'''Capitalize the current (or following) word. With a negative
|
||||
u'''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()
|
||||
|
||||
def overwrite_mode(self, e): # ()
|
||||
'''Toggle overwrite mode. With an explicit positive numeric
|
||||
u'''Toggle overwrite mode. With an explicit positive numeric
|
||||
argument, switches to overwrite mode. With an explicit non-positive
|
||||
numeric argument, switches to insert mode. This command affects only
|
||||
emacs mode; vi mode does overwrite differently. Each call to
|
||||
@@ -321,54 +321,54 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
pass
|
||||
|
||||
def kill_line(self, e): # (C-k)
|
||||
'''Kill the text from point to the end of the line. '''
|
||||
u'''Kill the text from point to the end of the line. '''
|
||||
self.l_buffer.kill_line()
|
||||
|
||||
def backward_kill_line(self, e): # (C-x Rubout)
|
||||
'''Kill backward to the beginning of the line. '''
|
||||
u'''Kill backward to the beginning of the line. '''
|
||||
self.l_buffer.backward_kill_line()
|
||||
|
||||
def unix_line_discard(self, e): # (C-u)
|
||||
'''Kill backward from the cursor to the beginning of the current line. '''
|
||||
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()
|
||||
|
||||
def kill_whole_line(self, e): # ()
|
||||
'''Kill all characters on the current line, no matter where point
|
||||
u'''Kill all characters on the current line, no matter where point
|
||||
is. By default, this is unbound.'''
|
||||
self.l_buffer.kill_whole_line()
|
||||
|
||||
def kill_word(self, e): # (M-d)
|
||||
'''Kill from point to the end of the current word, or if between
|
||||
u'''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()
|
||||
|
||||
def backward_kill_word(self, e): # (M-DEL)
|
||||
'''Kill the word behind point. Word boundaries are the same as
|
||||
u'''Kill the word behind point. Word boundaries are the same as
|
||||
backward-word. '''
|
||||
self.l_buffer.backward_kill_word()
|
||||
|
||||
def unix_word_rubout(self, e): # (C-w)
|
||||
'''Kill the word behind point, using white space as a word
|
||||
u'''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()
|
||||
|
||||
def delete_horizontal_space(self, e): # ()
|
||||
'''Delete all spaces and tabs around point. By default, this is unbound. '''
|
||||
u'''Delete all spaces and tabs around point. By default, this is unbound. '''
|
||||
pass
|
||||
|
||||
def kill_region(self, e): # ()
|
||||
'''Kill the text in the current region. By default, this command is unbound. '''
|
||||
u'''Kill the text in the current region. By default, this command is unbound. '''
|
||||
pass
|
||||
|
||||
def copy_region_as_kill(self, e): # ()
|
||||
'''Copy the text in the region to the kill buffer, so it can be
|
||||
u'''Copy the text in the region to the kill buffer, so it can be
|
||||
yanked right away. By default, this command is unbound.'''
|
||||
pass
|
||||
|
||||
def copy_region_to_clipboard(self, e): # ()
|
||||
'''Copy the text in the region to the windows clipboard.'''
|
||||
u'''Copy the text in the region to the windows clipboard.'''
|
||||
if self.enable_win32_clipboard:
|
||||
mark=min(self.l_buffer.mark,len(self.l_buffer.line_buffer))
|
||||
cursor=min(self.l_buffer.point,len(self.l_buffer.line_buffer))
|
||||
@@ -376,72 +376,72 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
return
|
||||
begin=min(cursor,mark)
|
||||
end=max(cursor,mark)
|
||||
toclipboard="".join(self.l_buffer.line_buffer[begin:end])
|
||||
toclipboard=u"".join(self.l_buffer.line_buffer[begin:end])
|
||||
clipboard.SetClipboardText(str(toclipboard))
|
||||
|
||||
def copy_backward_word(self, e): # ()
|
||||
'''Copy the word before point to the kill buffer. The word
|
||||
u'''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
|
||||
|
||||
def copy_forward_word(self, e): # ()
|
||||
'''Copy the word following point to the kill buffer. The word
|
||||
u'''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
|
||||
|
||||
def paste(self,e):
|
||||
'''Paste windows clipboard'''
|
||||
u'''Paste windows clipboard'''
|
||||
if self.enable_win32_clipboard:
|
||||
txt=clipboard.get_clipboard_text_and_convert(False)
|
||||
self.insert_text(txt)
|
||||
|
||||
def paste_mulitline_code(self,e):
|
||||
'''Paste windows clipboard'''
|
||||
reg=re.compile("\r?\n")
|
||||
u'''Paste windows clipboard'''
|
||||
reg=re.compile(u"\r?\n")
|
||||
if self.enable_win32_clipboard:
|
||||
txt=clipboard.get_clipboard_text_and_convert(False)
|
||||
t=reg.split(txt)
|
||||
t=[row for row in t if row.strip()!=""] #remove empty lines
|
||||
if t!=[""]:
|
||||
t=[row for row in t if row.strip()!=u""] #remove empty lines
|
||||
if t!=[u""]:
|
||||
self.insert_text(t[0])
|
||||
self.add_history(self.l_buffer.copy())
|
||||
self.paste_line_buffer=t[1:]
|
||||
log("multi: %s"%self.paste_line_buffer)
|
||||
log(u"multi: %s"%self.paste_line_buffer)
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def ipython_paste(self,e):
|
||||
'''Paste windows clipboard. If enable_ipython_paste_list_of_lists is
|
||||
u'''Paste windows clipboard. If enable_ipython_paste_list_of_lists is
|
||||
True then try to convert tabseparated data to repr of list of lists or
|
||||
repr of array'''
|
||||
if self.enable_win32_clipboard:
|
||||
txt=clipboard.get_clipboard_text_and_convert(
|
||||
self.enable_ipython_paste_list_of_lists)
|
||||
if self.enable_ipython_paste_for_paths:
|
||||
if len(txt)<300 and ("\t" not in txt) and ("\n" not in txt):
|
||||
txt=txt.replace("\\","/").replace(" ",r"\ ")
|
||||
if len(txt)<300 and (u"\t" not in txt) and (u"\n" not in txt):
|
||||
txt=txt.replace(u"\\", u"/").replace(u" ", ur"\ ")
|
||||
self.insert_text(txt)
|
||||
|
||||
def yank(self, e): # (C-y)
|
||||
'''Yank the top of the kill ring into the buffer at point. '''
|
||||
u'''Yank the top of the kill ring into the buffer at point. '''
|
||||
pass
|
||||
|
||||
def yank_pop(self, e): # (M-y)
|
||||
'''Rotate the kill-ring, and yank the new top. You can only do this
|
||||
u'''Rotate the kill-ring, and yank the new top. You can only do this
|
||||
if the prior command is yank or yank-pop.'''
|
||||
pass
|
||||
|
||||
|
||||
def digit_argument(self, e): # (M-0, M-1, ... M--)
|
||||
'''Add this digit to the argument already accumulating, or start a
|
||||
u'''Add this digit to the argument already accumulating, or start a
|
||||
new argument. M-- starts a negative argument.'''
|
||||
pass
|
||||
|
||||
def universal_argument(self, e): # ()
|
||||
'''This is another way to specify an argument. If this command is
|
||||
u'''This is another way to specify an argument. If this command is
|
||||
followed by one or more digits, optionally with a leading minus
|
||||
sign, those digits define the argument. If the command is followed
|
||||
by digits, executing universal-argument again ends the numeric
|
||||
@@ -455,83 +455,83 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
pass
|
||||
|
||||
def delete_char_or_list(self, e): # ()
|
||||
'''Deletes the character under the cursor if not at the beginning or
|
||||
u'''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. '''
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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.'''
|
||||
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
|
||||
u'''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.'''
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
u'''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
|
||||
@@ -541,21 +541,21 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
pass
|
||||
|
||||
def dump_functions(self, e): # ()
|
||||
'''Print all of the functions and their key bindings to the Readline
|
||||
u'''Print all of the functions and their key bindings 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_variables(self, e): # ()
|
||||
'''Print all of the settable variables and their values to the
|
||||
u'''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
|
||||
u'''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.'''
|
||||
@@ -565,38 +565,38 @@ class NotEmacsMode(basemode.BaseMode):
|
||||
#Create key bindings:
|
||||
|
||||
def init_editing_mode(self, e): # (C-e)
|
||||
'''When in vi command mode, this causes a switch to emacs editing
|
||||
u'''When in vi command mode, this causes a switch to emacs editing
|
||||
mode.'''
|
||||
|
||||
self._bind_exit_key('Control-d')
|
||||
self._bind_exit_key('Control-z')
|
||||
self._bind_exit_key(u'Control-d')
|
||||
self._bind_exit_key(u'Control-z')
|
||||
|
||||
# I often accidentally hold the shift or control while typing space
|
||||
self._bind_key('Shift-space', self.self_insert)
|
||||
self._bind_key('Control-space', self.self_insert)
|
||||
self._bind_key('Return', self.accept_line)
|
||||
self._bind_key('Left', self.backward_char)
|
||||
self._bind_key('Control-b', self.backward_char)
|
||||
self._bind_key('Right', self.forward_char)
|
||||
self._bind_key('Control-f', self.forward_char)
|
||||
self._bind_key('BackSpace', self.backward_delete_char)
|
||||
self._bind_key('Home', self.beginning_of_line)
|
||||
self._bind_key('End', self.end_of_line)
|
||||
self._bind_key('Delete', self.delete_char)
|
||||
self._bind_key('Control-d', self.delete_char)
|
||||
self._bind_key('Clear', self.clear_screen)
|
||||
self._bind_key(u'Shift-space', self.self_insert)
|
||||
self._bind_key(u'Control-space', self.self_insert)
|
||||
self._bind_key(u'Return', self.accept_line)
|
||||
self._bind_key(u'Left', self.backward_char)
|
||||
self._bind_key(u'Control-b', self.backward_char)
|
||||
self._bind_key(u'Right', self.forward_char)
|
||||
self._bind_key(u'Control-f', self.forward_char)
|
||||
self._bind_key(u'BackSpace', self.backward_delete_char)
|
||||
self._bind_key(u'Home', self.beginning_of_line)
|
||||
self._bind_key(u'End', self.end_of_line)
|
||||
self._bind_key(u'Delete', self.delete_char)
|
||||
self._bind_key(u'Control-d', self.delete_char)
|
||||
self._bind_key(u'Clear', self.clear_screen)
|
||||
|
||||
|
||||
# make it case insensitive
|
||||
def commonprefix(m):
|
||||
"Given a list of pathnames, returns the longest common leading component"
|
||||
if not m: return ''
|
||||
u"Given a list of pathnames, returns the longest common leading component"
|
||||
if not m: return u''
|
||||
prefix = m[0]
|
||||
for item in m:
|
||||
for i in range(len(prefix)):
|
||||
if prefix[:i+1].lower() != item[:i+1].lower():
|
||||
prefix = prefix[:i]
|
||||
if i == 0: return ''
|
||||
if i == 0: return u''
|
||||
break
|
||||
return prefix
|
||||
|
||||
|
||||
Reference in New Issue
Block a user