@option(
        '-d', '--delete', action='store_true', default=False,
        help='delete a named macro'
    )
    @option(
        '-l', '--list', action='store_true', default=False,
        help='list macros'
    )
    @option(
        '-s', '--show', action='store_true', default=False,
        help='show macro'
    )
    def line_macro(self, name, delete=False, list=False, show=False):
        """
        %macro NAME - execute a macro
        %macro -l [all|learned|system] - list macros
        %macro [-s] [-d] NAME - show or delete a macro

        This line macro will execute, show, list, or delete the 
        named macro.

        Examples:
            %macro renumber-cells

            %%macro test
            print "Ok!"

            %macro -l all

            %macro -d test
        """
        if list:
            self._list_macros(name)
        elif show:
            retval = "%%%%macro %s\n" % name
            if name in self.macros:
                retval += self.macros[name]
            elif name in self.learned:
                retval += self.learned[name]
            self.kernel.Print(retval)
        elif name in self.learned:
            if delete:
                del self.learned[name]
                self._save_macros()
            else:
                self.code = self.code.strip()
                if self.code: 
                    self.code += "\n"
                self.code += self.learned[name]
        elif name in self.macros:
            if delete:
                raise Exception("Can't delete system macro")
            else:
                self.code = self.code.strip()
                if self.code: 
                    self.code += "\n"
                self.code += self.macros[name]
        elif name == "":
            self._list_macros()
        else:
            self._list_macros(retval="No such macro: '%s'\n\n" % name,
                              error=True)
        self.evaluate = True
dataset/ETHPy150Open Calysto/metakernel/metakernel/magics/macro_magic.py/MacroMagic.line_macro/original