Show More
@@ -1,7 +1,7 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """Magic functions for InteractiveShell. |
|
2 | """Magic functions for InteractiveShell. | |
3 |
|
3 | |||
4 |
$Id: Magic.py 10 |
|
4 | $Id: Magic.py 1068 2006-01-23 20:31:43Z vivainio $""" | |
5 |
|
5 | |||
6 | #***************************************************************************** |
|
6 | #***************************************************************************** | |
7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and |
|
7 | # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and | |
@@ -51,6 +51,7 b' from IPython.ipstruct import Struct' | |||||
51 | from IPython.macro import Macro |
|
51 | from IPython.macro import Macro | |
52 | from IPython.genutils import * |
|
52 | from IPython.genutils import * | |
53 | from IPython import platutils |
|
53 | from IPython import platutils | |
|
54 | ||||
54 | #*************************************************************************** |
|
55 | #*************************************************************************** | |
55 | # Utility functions |
|
56 | # Utility functions | |
56 | def on_off(tag): |
|
57 | def on_off(tag): | |
@@ -2759,4 +2760,45 b' Defaulting color scheme to \'NoColor\'"""' | |||||
2759 | page(self.shell.pycolorize(file_read(filename)), |
|
2760 | page(self.shell.pycolorize(file_read(filename)), | |
2760 | screen_lines=self.shell.rc.screen_length) |
|
2761 | screen_lines=self.shell.rc.screen_length) | |
2761 |
|
2762 | |||
|
2763 | def magic_paste(self, parameter_s=''): | |||
|
2764 | """Allows you to paste & execute a pre-formatted code block from | |||
|
2765 | clipboard. | |||
|
2766 | ||||
|
2767 | You must terminate the block with '--' (two minus-signs) alone on the | |||
|
2768 | line. | |||
|
2769 | ||||
|
2770 | The block is dedented prior to execution to enable execution of | |||
|
2771 | method definitions. The executed block is also assigned to variable | |||
|
2772 | named 'pasted_block' for later editing with %edit. | |||
|
2773 | ||||
|
2774 | You can also pass a variable name as an argument, e.g. '%paste foo'. | |||
|
2775 | This assigns the pasted block to variable 'foo' as string, without | |||
|
2776 | dedenting or executing it. | |||
|
2777 | ||||
|
2778 | Do not be alarmed by garbled output on Windows (it's a readline bug). | |||
|
2779 | Just press enter and type -- (and press enter again) and the block | |||
|
2780 | will be what was just pasted. | |||
|
2781 | ||||
|
2782 | IPython statements (magics, shell escapes) are not supported (yet). | |||
|
2783 | """ | |||
|
2784 | par = parameter_s.strip() | |||
|
2785 | from IPython import iplib | |||
|
2786 | lines = [] | |||
|
2787 | while 1: | |||
|
2788 | l = iplib.raw_input_original(':') | |||
|
2789 | if l =='--': | |||
|
2790 | break | |||
|
2791 | lines.append(l) | |||
|
2792 | block = "\n".join(lines) | |||
|
2793 | #print "block:\n",block | |||
|
2794 | if not par: | |||
|
2795 | b = textwrap.dedent(block) | |||
|
2796 | self.runsource(b) | |||
|
2797 | self.user_ns['pasted_block'] = b | |||
|
2798 | else: | |||
|
2799 | self.user_ns[par] = block | |||
|
2800 | print "Block assigned to '%s'" % par | |||
|
2801 | ||||
|
2802 | ||||
|
2803 | ||||
2762 | # end Magic |
|
2804 | # end Magic |
@@ -1,3 +1,7 b'' | |||||
|
1 | 2006-01-23 Ville Vainio <vivainio@gmail.com> | |||
|
2 | ||||
|
3 | * Added %paste magic for pasting python code | |||
|
4 | ||||
1 | 2006-01-22 Ville Vainio <vivainio@gmail.com> |
|
5 | 2006-01-22 Ville Vainio <vivainio@gmail.com> | |
2 |
|
6 | |||
3 | * Merge from branches/0.7.1 into trunk, revs 1052-1057 |
|
7 | * Merge from branches/0.7.1 into trunk, revs 1052-1057 |
General Comments 0
You need to be logged in to leave comments.
Login now