n-riesco / ijavascript

IJavascript is a javascript kernel for the Jupyter notebook
Other
2.18k stars 187 forks source link

Proposal: Custom commands / magics #229

Closed apowers313 closed 3 years ago

apowers313 commented 3 years ago

Expanding on some of the comments in #43 :

Is there a way to add commands to the underlying shell and then people could define their own preferences or conventions?

For example, if you expose a function:

addCommand(cmdStr, cmdFn) {}

Then people can define their own library of magics and commands. For example, an npm package called ijavascript-standard-magics could include:

addCommand("!", shellExec);
addCommand("%print", doPrint);
...

The upside is that you don't have to be the arbiter of magics and people can decide for themselves what conventions are important and not important; the downside is a lack of convention in notebooks (unless the community coalesces around a single package).

If this sounds like a reasonable direction and you can give me some hints for where to implement, I'm happy to put together a PR.

apowers313 commented 3 years ago

Maybe the way to implement this is a custom transpiler in NEL?

n-riesco commented 3 years ago

jp-kernel provides an API for transpilation. See jp-babel and jp-coffeescript as examples.


I'm closing this issue, please, keep this discussion to issue #43 (otherwise it's hard for me to keep track where all the arguments about magic commands are).


And to be clear, I reject this proposal, because:

  1. The main objective of IJavascript is to behave as close as possible to the Node.js CLI (VM, pre-loaded packages, ...). IJavascript goes to great lengths to ensure this.
  2. I don't support magic commands (not only their syntax is incompatible with JS; they are a step back towards making the Jupyter protocol language-agnostic; they shouldn't be implemented as execute_request).
  3. I've published the technology behind IJavascript (jp-kernel, nel and jmp), so that others can create kernels fitting their own needs.

Note that I haven't named those packages IJavascript, because I don't want people to use the popularity of IJavascript to promote their own kernels.