##// END OF EJS Templates
Update terminal-only magics to new API.
Fernando Perez -
Show More
@@ -14,22 +14,18 b''
14 14 # Imports
15 15 #-----------------------------------------------------------------------------
16 16
17 import __builtin__
18 17 import bdb
19 18 import os
20 19 import re
21 20 import sys
22 21 import textwrap
23 22
24 try:
25 23 from contextlib import nested
26 except:
27 from IPython.utils.nested_context import nested
28 24
29 25 from IPython.core.error import TryNext, UsageError
30 26 from IPython.core.usage import interactive_usage, default_banner
31 27 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
32 from IPython.core.pylabtools import pylab_activate
28 from IPython.core.magic import Magics, register_magics, line_magic
33 29 from IPython.testing.skipdoctest import skip_doctest
34 30 from IPython.utils.encoding import get_stream_enc
35 31 from IPython.utils import py3compat
@@ -124,14 +120,19 b" def rerun_pasted(shell, name='pasted_block'):"
124 120 # Terminal-specific magics
125 121 #------------------------------------------------------------------------
126 122
127 def magic_autoindent(self, parameter_s = ''):
123 @register_magics
124 class TerminalMagics(Magics):
125
126 @line_magic
127 def autoindent(self, parameter_s = ''):
128 128 """Toggle autoindent on/off (if available)."""
129 129
130 130 self.shell.set_autoindent()
131 131 print "Automatic indentation is:",['OFF','ON'][self.shell.autoindent]
132 132
133 133 @skip_doctest
134 def magic_cpaste(self, parameter_s=''):
134 @line_magic
135 def cpaste(self, parameter_s=''):
135 136 """Paste & execute a pre-formatted code block from clipboard.
136 137
137 138 You must terminate the block with '--' (two minus-signs) or Ctrl-D
@@ -182,8 +183,8 b" def magic_cpaste(self, parameter_s=''):"
182 183 block = strip_email_quotes(get_pasted_lines(sentinel))
183 184 store_or_execute(self.shell, block, name)
184 185
185
186 def magic_paste(self, parameter_s=''):
186 @line_magic
187 def paste(self, parameter_s=''):
187 188 """Paste & execute a pre-formatted code block from clipboard.
188 189
189 190 The text is pulled directly from the clipboard without user
@@ -239,10 +240,10 b" def magic_paste(self, parameter_s=''):"
239 240
240 241 store_or_execute(self.shell, block, name)
241 242
242
243 243 # Class-level: add a '%cls' magic only on Windows
244 244 if sys.platform == 'win32':
245 def magic_cls(self, s):
245 @line_magic
246 def cls(self, s):
246 247 """Clear screen.
247 248 """
248 249 os.system("cls")
@@ -664,15 +665,7 b' class TerminalInteractiveShell(InteractiveShell):'
664 665
665 666 def init_magics(self):
666 667 super(TerminalInteractiveShell, self).init_magics()
667 self.define_magic('autoindent', magic_autoindent)
668 self.define_magic('cpaste', magic_cpaste)
669 self.define_magic('paste', magic_paste)
670 try:
671 magic_cls
672 except NameError:
673 pass
674 else:
675 self.define_magic('cls', magic_cls)
668 self.register_magics(TerminalMagics)
676 669
677 670 def showindentationerror(self):
678 671 super(TerminalInteractiveShell, self).showindentationerror()
General Comments 0
You need to be logged in to leave comments. Login now