##// END OF EJS Templates
Made %paste sentinel configurable
vivainio -
Show More
@@ -1,7 +1,7 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 1070 2006-01-23 21:12:36Z vivainio $"""
4 $Id: Magic.py 1071 2006-01-23 21:30:41Z vivainio $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -2765,11 +2765,12 b' Defaulting color scheme to \'NoColor\'"""'
2765 2765 clipboard.
2766 2766
2767 2767 You must terminate the block with '--' (two minus-signs) alone on the
2768 line.
2768 line. You can also provide your own sentinel with '%paste -s %%' ('%%'
2769 is the new sentinel for this operation)
2769 2770
2770 2771 The block is dedented prior to execution to enable execution of
2771 2772 method definitions. The executed block is also assigned to variable
2772 named 'pasted_block' for later editing with %edit.
2773 named 'pasted_block' for later editing with '%edit pasted_block'.
2773 2774
2774 2775 You can also pass a variable name as an argument, e.g. '%paste foo'.
2775 2776 This assigns the pasted block to variable 'foo' as string, without
@@ -2781,13 +2782,16 b' Defaulting color scheme to \'NoColor\'"""'
2781 2782
2782 2783 IPython statements (magics, shell escapes) are not supported (yet).
2783 2784 """
2784 par = parameter_s.strip()
2785 opts,args = self.parse_options(parameter_s,'s:',mode='string')
2786 par = args.strip()
2787 sentinel = opts.get('s','--')
2788
2785 2789 from IPython import iplib
2786 2790 lines = []
2787 print "Pasting code; enter '--' alone on the line to stop."
2791 print "Pasting code; enter '%s' alone on the line to stop." % sentinel
2788 2792 while 1:
2789 2793 l = iplib.raw_input_original(':')
2790 if l =='--':
2794 if l ==sentinel:
2791 2795 break
2792 2796 lines.append(l)
2793 2797 block = "\n".join(lines)
General Comments 0
You need to be logged in to leave comments. Login now