diff --git a/CHANGELOG.md b/CHANGELOG.md index dfc2fd5..cd9a38d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added + +- Way to define your own magic function. ## [0.5.0] - 2021-05-22 diff --git a/noteql/__init__.py b/noteql/__init__.py index 36e89df..545e307 100755 --- a/noteql/__init__.py +++ b/noteql/__init__.py @@ -25,6 +25,8 @@ LOCAL_DB_MADE = False +REGISTERED_MAGICS = False + def get_engine(dburi): if not dburi: @@ -110,7 +112,8 @@ def __init__( df_viewer=None, df_viewer_kw=None, datasette_url=None, - cell_magic_output=False + cell_magic_name=None, + cell_magic_output=False, ): self.schema = schema self.dburi = dburi @@ -150,7 +153,17 @@ def __init__( connection.execute("create schema if not exists {};".format(self.schema)) self.ipython = get_ipython() - self.ipython.register_magics(Noteql) + + global REGISTERED_MAGICS + + if not REGISTERED_MAGICS: + if cell_magic_name: + Noteql.magics["line"][cell_magic_name] = Noteql.magics["line"].pop("nql") + Noteql.magics["cell"][cell_magic_name] = Noteql.magics["cell"].pop("nql") + + self.ipython.register_magics(Noteql) + REGISTERED_MAGICS = True + self.set() def tables(self):