Permalink
Browse files

Merge pull request #861 from djv/master

Add support for terminating `%cpaste` blocks with `Ctrl-D`.

Closes gh-56.
  • Loading branch information...
2 parents a4cfe5c + 2b7a228 commit db84fc9dc46e2a57ad83563fbe3f47d142633d1e @fperez fperez committed Oct 14, 2011
Showing with 9 additions and 5 deletions.
  1. +8 −4 IPython/core/magic.py
  2. +1 −1 IPython/frontend/terminal/interactiveshell.py
View
12 IPython/core/magic.py
@@ -3207,11 +3207,15 @@ def _get_pasted_lines(self, sentinel):
from IPython.core import interactiveshell
print "Pasting code; enter '%s' alone on the line to stop." % sentinel
while True:
- l = self.shell.raw_input_original(':')
- if l == sentinel:
+ try:
+ l = self.shell.raw_input_original(':')
+ if l == sentinel:
+ return
+ else:
+ yield l
+ except EOFError:
+ print '<EOF>'
return
- else:
- yield l
def _strip_pasted_lines_for_code(self, raw_lines):
""" Strip non-code parts of a sequence of lines to return a block of
View
2 IPython/frontend/terminal/interactiveshell.py
@@ -487,7 +487,7 @@ def magic_autoindent(self, parameter_s = ''):
def magic_cpaste(self, parameter_s=''):
"""Paste & execute a pre-formatted code block from clipboard.
- You must terminate the block with '--' (two minus-signs) alone on the
+ You must terminate the block with '--' (two minus-signs) or Ctrl-D alone on the
line. You can also provide your own sentinel with '%paste -s %%' ('%%'
is the new sentinel for this operation)

0 comments on commit db84fc9

Please sign in to comment.