Skip to content

Commit

Permalink
Enabled use of multiple uses of %%opts magic in the same cell
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Jun 25, 2015
1 parent 8edf247 commit 2a77fd0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions holoviews/ipython/magics.py
Expand Up @@ -589,6 +589,21 @@ def register_custom_spec(cls, spec):

cls.opts_spec = spec

@classmethod
def _partition_lines(cls, line, cell):
"""
Check the code for additional use of %%opts. Enables
multi-line use of %%opts in a single call to the magic.
"""
specs, code = [line], []
for line in cell.splitlines():
line = line.strip()
if line.startswith('%%opts'):
specs.append(line.strip()[7:])
else:
code.append(line)
return ' '.join(specs), '\n'.join(code)


@line_cell_magic
def opts(self, line='', cell=None):
Expand Down Expand Up @@ -617,6 +632,7 @@ def opts(self, line='', cell=None):
More information may be found in the class docstring of
ipython.parser.OptsSpec.
"""
line, cell = self._partition_lines(line, cell)
try:
spec = OptsSpec.parse(line, ns=self.shell.user_ns)
except SyntaxError:
Expand Down

0 comments on commit 2a77fd0

Please sign in to comment.