[IPython-user] [FWD] Ctrl-Z as EOF

Fernando Perez Fernando.Perez at colorado.edu
Sat Oct 28 13:17:01 CDT 2006


Another one forwarded to the list, please note that you need to be subscribed 
to post (we get way too much spam otherwise).

I'll reply on-list, sorry for the delay, this slipped in a pile of other email.

Cheers,

f


# ORIGINAL MESSAGE:

Subject:
Ctrl-Z as EOF
From:
Tim Roberts <timr at probo.com>
Date:
Wed, 18 Oct 2006 15:40:24 -0700
To:
IPython <ipython-user at scipy.org>

I thought I had sent this in many months ago, but I do not see it.
After installing IPython on Win32, one has the benefit of the included
readline module at all times.  However, the readline module causes one
change in behavior that Win32 Pythoners may find uncomfortable: when
using the interactive interpreter, Ctrl-Z no longer exits.  Instead, it
is silently eaten up, as an undo with nothing to undo.

The following patch restores the EOF meaning when the buffer is empty,
which is the behavior I expect.

Index: rlmain.py
===================================================================
--- rlmain.py    (revision 1833)
+++ rlmain.py    (working copy)
@@ -673,6 +673,12 @@
          else:
              self._bell()

+    def maybe_eof(self, e): # (C-z)
+        '''At start of line, return end of file.  Otherwise, undo.'''
+        if len(self.line_buffer) == 0:
+            raise EOFError
+        self.undo(e)
+
      def backward_delete_char(self, e): # (Rubout)
          '''Delete the character behind the cursor. A numeric argument means
          to kill the characters instead of deleting them.'''
@@ -1178,7 +1184,7 @@
          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-z',         self.maybe_eof)
          self._bind_key('Control-_',         self.undo)
          self._bind_key('Escape',            self.prefix_meta)
          self._bind_key('Meta-d',            self.kill_word)

-- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc.


More information about the IPython-user mailing list