Define a new macro Parameters ---------- name : str The name of the macro. themacro : str or Macro The action to do upon invoking the macro. If a string, a new Macro object is created by passing the string to it.
(self, name, themacro)
| 2625 | #------------------------------------------------------------------------- |
| 2626 | |
| 2627 | def define_macro(self, name, themacro): |
| 2628 | """Define a new macro |
| 2629 | |
| 2630 | Parameters |
| 2631 | ---------- |
| 2632 | name : str |
| 2633 | The name of the macro. |
| 2634 | themacro : str or Macro |
| 2635 | The action to do upon invoking the macro. If a string, a new |
| 2636 | Macro object is created by passing the string to it. |
| 2637 | """ |
| 2638 | |
| 2639 | from IPython.core import macro |
| 2640 | |
| 2641 | if isinstance(themacro, str): |
| 2642 | themacro = macro.Macro(themacro) |
| 2643 | if not isinstance(themacro, macro.Macro): |
| 2644 | raise ValueError('A macro must be a string or a Macro instance.') |
| 2645 | self.user_ns[name] = themacro |
| 2646 | |
| 2647 | #------------------------------------------------------------------------- |
| 2648 | # Things related to the running of system commands |
no outgoing calls