From 1a604cf973c47e04a6ddef1f111f51aa7ce02e66 Mon Sep 17 00:00:00 2001 From: jstenar <> Date: Tue, 6 Mar 2007 19:27:29 +0000 Subject: [PATCH] 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 --- doc/ChangeLog | 6 + pyreadline/clipboard/__init__.py | 10 +- .../{clipboard.py => win32_clipboard.py} | 1 - pyreadline/configuration/pyreadlineconfig.ini | 111 +++++++++--------- pyreadline/console/__init__.py | 2 +- pyreadline/keysyms/__init__.py | 4 +- pyreadline/modes/basemode.py | 3 +- pyreadline/modes/emacs.py | 16 ++- pyreadline/rlmain.py | 9 +- 9 files changed, 90 insertions(+), 72 deletions(-) rename pyreadline/clipboard/{clipboard.py => win32_clipboard.py} (97%) diff --git a/doc/ChangeLog b/doc/ChangeLog index 58e56e9..17e9fc4 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2007-03-06 Jörgen Stenarson + * 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 * moved ironpython specifics from emacs.py->readline to a hook_wrapper just as in the hookwrapper for the normal console. diff --git a/pyreadline/clipboard/__init__.py b/pyreadline/clipboard/__init__.py index 6c76046..2852618 100644 --- a/pyreadline/clipboard/__init__.py +++ b/pyreadline/clipboard/__init__.py @@ -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)) diff --git a/pyreadline/clipboard/clipboard.py b/pyreadline/clipboard/win32_clipboard.py similarity index 97% rename from pyreadline/clipboard/clipboard.py rename to pyreadline/clipboard/win32_clipboard.py index 594bfa1..a626edc 100644 --- a/pyreadline/clipboard/clipboard.py +++ b/pyreadline/clipboard/win32_clipboard.py @@ -14,7 +14,6 @@ # # - ################################################################################### # # The Python win32clipboard lib functions work well enough ... except that they diff --git a/pyreadline/configuration/pyreadlineconfig.ini b/pyreadline/configuration/pyreadlineconfig.ini index ba1c4a3..7cf6692 100644 --- a/pyreadline/configuration/pyreadlineconfig.ini +++ b/pyreadline/configuration/pyreadlineconfig.ini @@ -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 diff --git a/pyreadline/console/__init__.py b/pyreadline/console/__init__.py index f9a14cc..039e4a9 100644 --- a/pyreadline/console/__init__.py +++ b/pyreadline/console/__init__.py @@ -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: diff --git a/pyreadline/keysyms/__init__.py b/pyreadline/keysyms/__init__.py index b7b6ed9..6faa94f 100644 --- a/pyreadline/keysyms/__init__.py +++ b/pyreadline/keysyms/__init__.py @@ -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 * diff --git a/pyreadline/modes/basemode.py b/pyreadline/modes/basemode.py index 32edb0a..6ec17dd 100644 --- a/pyreadline/modes/basemode.py +++ b/pyreadline/modes/basemode.py @@ -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")) diff --git a/pyreadline/modes/emacs.py b/pyreadline/modes/emacs.py index ae1e1ce..3779a49 100644 --- a/pyreadline/modes/emacs.py +++ b/pyreadline/modes/emacs.py @@ -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 diff --git a/pyreadline/rlmain.py b/pyreadline/rlmain.py index 639ecfd..897c757 100644 --- a/pyreadline/rlmain.py +++ b/pyreadline/rlmain.py @@ -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: