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