pyreadline-branch: added possibility to bind ctrl-c to copy. Changed test for ironpython due to changes in ironpython. Some refactoring/renaming of clipboard files

This commit is contained in:
jstenar
2007-03-06 19:27:29 +00:00
parent 4d8af3936a
commit 1a604cf973
9 changed files with 90 additions and 72 deletions
+6
View File
@@ -1,3 +1,9 @@
2007-03-06 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
* Changed tests for ironpython
* Added possibility to bind ctrl-c to a function
* Refactor clipboard handling
* Restructured example config file
2006-11-15 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
* moved ironpython specifics from emacs.py->readline to a hook_wrapper
just as in the hookwrapper for the normal console.
+3 -7
View File
@@ -1,7 +1,6 @@
import sys
success=False
in_ironpython=sys.version.startswith("IronPython")
in_ironpython="IronPython" in sys.version
if in_ironpython:
try:
from ironpython_clipboard import GetClipboardText,SetClipboardText
@@ -10,14 +9,11 @@ if in_ironpython:
pass
else:
try:
from clipboard import GetClipboardText,SetClipboardText
from win32_clipboard import GetClipboardText,SetClipboardText
success=True
except ImportError:
pass
raise
def send_data(lists):
SetClipboardText(make_tab(lists))
@@ -14,7 +14,6 @@
#
#
###################################################################################
#
# The Python win32clipboard lib functions work well enough ... except that they
+56 -55
View File
@@ -3,79 +3,80 @@
bind_exit_key("Control-d")
bind_exit_key("Control-z")
#Commands for moving
bind_key("Home", "beginning_of_line")
bind_key("End", "end_of_line")
bind_key("Left", "backward_char")
bind_key("Control-b", "backward_char")
bind_key("Right", "forward_char")
bind_key("Control-f", "forward_char")
bind_key("Alt-f", "forward_word")
bind_key("Alt-b", "backward_word")
bind_key("Clear", "clear_screen")
bind_key("Control-l", "clear_screen")
bind_key("Control-a", "beginning_of_line")
bind_key("Control-e", "end_of_line")
#bind_key("Control-l", "redraw_current_line")
#Commands for moving
bind_key("Home", "beginning_of_line")
bind_key("End", "end_of_line")
bind_key("Left", "backward_char")
bind_key("Control-b", "backward_char")
bind_key("Right", "forward_char")
bind_key("Control-f", "forward_char")
bind_key("Alt-f", "forward_word")
bind_key("Alt-b", "backward_word")
bind_key("Clear", "clear_screen")
bind_key("Control-l", "clear_screen")
bind_key("Control-a", "beginning_of_line")
bind_key("Control-e", "end_of_line")
#bind_key("Control-l", "redraw_current_line")
#Commands for Manipulating the History
bind_key("Return", "accept_line")
bind_key("Control-p", "previous_history")
bind_key("Control-n", "next_history")
bind_key("Up", "history_search_backward")
bind_key("Down", "history_search_forward")
bind_key("Alt-<", "beginning_of_history")
bind_key("Alt->", "end_of_history")
bind_key("Control-r", "reverse_search_history")
bind_key("Control-s", "forward_search_history")
bind_key("Alt-p", "non_incremental_reverse_search_history")
bind_key("Alt-n", "non_incremental_forward_search_history")
bind_key("Return", "accept_line")
bind_key("Control-p", "previous_history")
bind_key("Control-n", "next_history")
bind_key("Up", "history_search_backward")
bind_key("Down", "history_search_forward")
bind_key("Alt-<", "beginning_of_history")
bind_key("Alt->", "end_of_history")
bind_key("Control-r", "reverse_search_history")
bind_key("Control-s", "forward_search_history")
bind_key("Alt-p", "non_incremental_reverse_search_history")
bind_key("Alt-n", "non_incremental_forward_search_history")
bind_key("Control-z", "undo")
bind_key("Control-_", "undo")
#Commands for Changing Text
bind_key("Delete", "delete_char")
bind_key("Control-d", "delete_char")
bind_key("BackSpace", "backward_delete_char")
#bind_key("Control-Shift-v", "quoted_insert")
bind_key("Control-space", "self_insert")
bind_key("Delete", "delete_char")
bind_key("Control-d", "delete_char")
bind_key("BackSpace", "backward_delete_char")
#bind_key("Control-Shift-v", "quoted_insert")
bind_key("Control-space", "self_insert")
bind_key("Control-BackSpace", "backward_delete_word")
#Killing and Yanking
bind_key("Control-k", "kill_line")
bind_key("Control-shift-k", "kill_whole_line")
bind_key("Escape", "kill_whole_line")
bind_key("Meta-d", "kill_word")
bind_key("Control-w", "unix_word_rubout")
bind_key("Meta-Delete", "backward_kill_word")
bind_key("Control-k", "kill_line")
bind_key("Control-shift-k", "kill_whole_line")
bind_key("Escape", "kill_whole_line")
bind_key("Meta-d", "kill_word")
bind_key("Control-w", "unix_word_rubout")
bind_key("Meta-Delete", "backward_kill_word")
#Copy paste
bind_key("Control-m", "set_mark")
bind_key("Control-q", "copy_region_to_clipboard")
bind_key("Control-v", "paste")
bind_key("Alt-v", "ipython_paste")
bind_key("Control-y", "paste")
bind_key("Control-z", "undo")
bind_key("Control-_", "undo")
bind_key('Control-Shift-v', "paste_mulitline_code")
bind_key("Shift-Right", "forward_char_extend_selection")
bind_key("Shift-Left", "backward_char_extend_selection")
bind_key("Shift-Control-Right", "forward_word_extend_selection")
bind_key("Shift-Control-Left", "backward_word_extend_selection")
bind_key("Control-m", "set_mark")
bind_key("Control-Shift-x", "copy_selection_to_clipboard")
#bind_key("Control-c", "copy_selection_to_clipboard") #Needs allow_ctrl_c(True) below to be uncommented
bind_key("Control-q", "copy_region_to_clipboard")
bind_key('Control-Shift-v', "paste_mulitline_code")
bind_key("Control-x", "cut_selection_to_clipboard")
bind_key("Control-v", "paste")
bind_key("Control-y", "paste")
bind_key("Alt-v", "ipython_paste")
#Unbinding keys:
#un_bind_key("Home")
#new keybindings
bind_key("Shift-Right", "forward_char_extend_selection")
bind_key("Shift-Left", "backward_char_extend_selection")
bind_key("Shift-Control-Right", "forward_word_extend_selection")
bind_key("Shift-Control-Left", "backward_word_extend_selection")
bind_key("Control-BackSpace", "backward_delete_word")
bind_key("Control-x", "cut_selection_to_clipboard")
bind_key("Control-Shift-x", "copy_selection_to_clipboard")
#Other
bell_style("none") #modes: none, audible, visible(not implemented)
show_all_if_ambiguous("on")
mark_directories("on")
completer_delims(" \t\n\"\\'`@$><=;|&{(?")
debug_output("off")
#allow_ctrl_c(True) #(Allows use of ctrl-c as copy key, still propagate keyboardinterrupt when not waiting for input)
history_filename("~/.pythonhistory")
history_length(200) #value of -1 means no limit
+1 -1
View File
@@ -1,7 +1,7 @@
import glob,sys
success=False
in_ironpython=sys.version.startswith("IronPython")
in_ironpython="IronPython" in sys.version
if in_ironpython:
try:
+2 -2
View File
@@ -1,14 +1,14 @@
import sys
success=False
in_ironpython=sys.version.startswith("IronPython")
in_ironpython="IronPython" in sys.version
if in_ironpython:
try:
from ironpython_keysyms import *
success=True
except ImportError,x:
pass
raise
else:
try:
from keysyms import *
+2 -1
View File
@@ -14,7 +14,7 @@ import pyreadline.lineeditor.lineobj as lineobj
import pyreadline.lineeditor.history as history
import pyreadline.clipboard as clipboard
from pyreadline.error import ReadlineError,GetSetError
in_ironpython=sys.version.startswith("IronPython")
in_ironpython="IronPython" in sys.version
class BaseMode(object):
mode="base"
@@ -48,6 +48,7 @@ class BaseMode(object):
return val
argument_reset=property(_argreset)
allow_ctrl_c=property(*_gs("allow_ctrl_c"))
l_buffer=property(*_gs("l_buffer"))
next_meta=property(*_gs("next_meta"))
first_prompt=property(*_gs("first_prompt"))
+14 -2
View File
@@ -21,7 +21,7 @@ def format(keyinfo):
k=keyinfo+(ord(keyinfo[-1]),)
return "(%s,%s,%s,%s,%x)"%k
in_ironpython=sys.version.startswith("IronPython")
in_ironpython="IronPython" in sys.version
class EmacsMode(basemode.BaseMode):
@@ -44,7 +44,19 @@ class EmacsMode(basemode.BaseMode):
pass
while 1:
self._update_line()
event = c.getkeypress()
try:
event = c.getkeypress()
except KeyboardInterrupt:
from pyreadline.keysyms.common import KeyPress
from pyreadline.console.event import Event
event=Event(0,0)
event.char="c"
event.keyinfo=KeyPress("c",shift=False,control=True,meta=False,keyname=None)
log_sock("KBDIRQ")
if self.allow_ctrl_c:
pass
else:
raise
if self.next_meta:
self.next_meta = False
control, meta, shift, code = event.keyinfo
+6 -3
View File
@@ -21,7 +21,7 @@ import release
from modes import editingmodes
in_ironpython=sys.version.startswith("IronPython")
in_ironpython="IronPython" in sys.version
if in_ironpython:#ironpython does not provide a prompt string to readline
import System
default_prompt=">>> "
@@ -54,6 +54,7 @@ class Readline(object):
self.first_prompt = True
self.next_meta = False # True to force meta on next character
self.tabstop = 4
self.allow_ctrl_c=False
self.begidx = 0
self.endidx = 0
@@ -86,7 +87,6 @@ class Readline(object):
self.paste_line_buffer=[]
#Below is for refactoring, raise errors when using old style attributes
#that should be refactored out
def _g(x):
@@ -353,7 +353,9 @@ class Readline(object):
self.bell_style=mode
def sethistorylength(length):
self._history.history_length=int(length)
def allow_ctrl_c(mode):
log_sock("allow_ctrl_c:%s:%s"%(self.allow_ctrl_c,mode))
self.allow_ctrl_c=mode
def setbellstyle(mode):
self.bell_style=mode
def show_all_if_ambiguous(mode):
@@ -393,6 +395,7 @@ class Readline(object):
"history_length":sethistorylength,
"set_prompt_color":set_prompt_color,
"set_input_color":set_input_color,
"allow_ctrl_c":allow_ctrl_c,
}
if os.path.isfile(inputrcpath):
try: