diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 6966ad5..1be626d 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -61,7 +61,7 @@ from IPython.core.logger import Logger from IPython.core.macro import Macro from IPython.core.payload import PayloadManager from IPython.core.plugin import PluginManager -from IPython.core.prefilter import PrefilterManager, ESC_MAGIC +from IPython.core.prefilter import PrefilterManager, ESC_MAGIC, ESC_CELL_MAGIC from IPython.core.profiledir import ProfileDir from IPython.core.pylabtools import pylab_activate from IPython.core.prompts import PromptManager @@ -1348,7 +1348,9 @@ class InteractiveShell(SingletonConfigurable): """ oname = oname.strip() #print '1- oname: <%r>' % oname # dbg - if not py3compat.isidentifier(oname.lstrip(ESC_MAGIC), dotted=True): + if not oname.startswith(ESC_MAGIC) and \ + not oname.startswith(ESC_CELL_MAGIC) and \ + not py3compat.isidentifier(oname, dotted=True): return dict(found=False) alias_ns = None @@ -1406,11 +1408,18 @@ class InteractiveShell(SingletonConfigurable): # Try to see if it's magic if not found: - if oname.startswith(ESC_MAGIC): - oname = oname.lstrip(ESC_MAGIC) - obj = self.find_line_magic(oname) - if obj is None: + obj = None + if oname.startswith(ESC_CELL_MAGIC): + oname = oname.lstrip(ESC_CELL_MAGIC) obj = self.find_cell_magic(oname) + elif oname.startswith(ESC_MAGIC): + oname = oname.lstrip(ESC_MAGIC) + obj = self.find_line_magic(oname) + else: + # search without prefix, so run? will find %run? + obj = self.find_line_magic(oname) + if obj is None: + obj = self.find_cell_magic(oname) if obj is not None: found = True ospace = 'IPython internal' diff --git a/IPython/core/prefilter.py b/IPython/core/prefilter.py index 36c319d..059fb2a 100644 --- a/IPython/core/prefilter.py +++ b/IPython/core/prefilter.py @@ -50,6 +50,7 @@ ESC_SHELL = '!' ESC_SH_CAP = '!!' ESC_HELP = '?' ESC_MAGIC = '%' +ESC_CELL_MAGIC = ESC_MAGIC * 2 ESC_QUOTE = ',' ESC_QUOTE2 = ';' ESC_PAREN = '/'