From 86a18923be78f3541ec4c83ac840f6254cac6f68 2009-08-12 17:50:32 From: Fernando Perez Date: 2009-08-12 17:50:32 Subject: [PATCH] Make %paste echo by default, introduce -q for quiet mode. --- diff --git a/IPython/Magic.py b/IPython/Magic.py index 8e8e758..e8b660a 100644 --- a/IPython/Magic.py +++ b/IPython/Magic.py @@ -3369,7 +3369,8 @@ Defaulting color scheme to 'NoColor'""" """Allows you to paste & execute a pre-formatted code block from clipboard. The text is pulled directly from the clipboard without user - intervention. + intervention and printed back on the screen before execution (unless + the -q flag is given to force quiet mode). The block is dedented prior to execution to enable execution of method definitions. '>' and '+' characters at the beginning of a line are @@ -3387,7 +3388,7 @@ Defaulting color scheme to 'NoColor'""" -r: re-executes the block previously entered by cpaste. - -e: echo the pasted text back to the terminal. + -q: quiet mode: do not echo the pasted text back to the terminal. IPython statements (magics, shell escapes) are not supported (yet). @@ -3395,7 +3396,7 @@ Defaulting color scheme to 'NoColor'""" -------- cpaste: manually paste code into terminal until you mark its end. """ - opts,args = self.parse_options(parameter_s,'re',mode='string') + opts,args = self.parse_options(parameter_s,'rq',mode='string') par = args.strip() if opts.has_key('r'): self._rerun_pasted() @@ -3404,8 +3405,8 @@ Defaulting color scheme to 'NoColor'""" text = self.shell.hooks.clipboard_get() block = self._strip_pasted_lines_for_code(text.splitlines()) - if opts.has_key('e'): - # Echo back to terminal. + # By default, echo back to terminal unless quiet mode is requested + if not opts.has_key('q'): write = self.shell.write write(block) if not block.endswith('\n'): diff --git a/IPython/tests/test_magic.py b/IPython/tests/test_magic.py index 32265ff..393d749 100644 --- a/IPython/tests/test_magic.py +++ b/IPython/tests/test_magic.py @@ -262,7 +262,8 @@ class TestMagicRun(object): # Multiple tests for clipboard pasting def test_paste(): - def paste(txt, flags=''): + def paste(txt, flags='-q'): + """Paste input text, by default in quiet mode""" hooks.clipboard_get = lambda : txt _ip.magic('paste '+flags) @@ -302,7 +303,7 @@ def test_paste(): _ip.magic('paste -r') yield (nt.assert_equal, user_ns['x'], [1,2,3]) - # Also test paste -e, by temporarily faking the writer + # Also test paste echoing, by temporarily faking the writer w = StringIO() writer = _ip.IP.write _ip.IP.write = w.write @@ -310,7 +311,7 @@ def test_paste(): a = 100 b = 200""" try: - paste(code,'-e') + paste(code,'') out = w.getvalue() finally: _ip.IP.write = writer