jupyterlab_code_formatter icon indicating copy to clipboard operation
jupyterlab_code_formatter copied to clipboard

auto format when save

Open SolarisYan opened this issue 5 years ago • 7 comments

Hi there, can we set it to auto format code when auto save the notebook?

SolarisYan avatar Mar 08 '19 06:03 SolarisYan

Hello! There is no setting to support this at the moment, I agree this is something useful and will work on this when I get more free time! (PR always welcomed though :stuck_out_tongue: )

ryantam626 avatar Mar 09 '19 13:03 ryantam626

Thank you for response

SolarisYan avatar Mar 18 '19 13:03 SolarisYan

@SolarisYan Any ideas on how this could be implemented?

(I don't know if it's possible to use a @jupyterlab extension to hook into whatever code is called when a user leaves a cell.)

sebinsua avatar May 02 '19 20:05 sebinsua

@sebinsua In fact, i have no idea about that, and i think it's possible to use a hook to solve it.

SolarisYan avatar May 05 '19 02:05 SolarisYan

I created a trailing space remover extension, which works on notebook save event.

You can check how I implemented it: https://github.com/wallneradam/jupyterlab-trailing-space-remover

It was very hard to find how to listen on save event. My 1st version used a closure on toJSON method. But the final solution is much better.

Also you can use the following to get an event, when active cell is changed: http://jupyterlab.github.io/jupyterlab/notebook/interfaces/inotebooktracker.html#activecellchanged

The developer documentation is very poor. The same as PhosphorJS. Both were written very well, to make easy to create plugins, but without documentation it is very hard to do it. The only way I found is to read the packages folder under JupyterLab source, where there are a lot of examples.

wallneradam avatar Oct 08 '19 10:10 wallneradam

I created a trailing space remover extension, which works on notebook save event.

You can check how I implemented it: https://github.com/wallneradam/jupyterlab-trailing-space-remover

It was very hard to find how to listen on save event. My 1st version used a closure on toJSON method. But the final solution is much better.

Also you can use the following to get an event, when active cell is changed: http://jupyterlab.github.io/jupyterlab/notebook/interfaces/inotebooktracker.html#activecellchanged

The developer documentation is very poor. The same as PhosphorJS. Both were written very well, to make easy to create plugins, but without documentation it is very hard to do it. The only way I found is to read the packages folder under JupyterLab source, where there are a lot of examples.

Ooo thanks for the tip! This should help

ryantam626 avatar Oct 16 '19 22:10 ryantam626

FYI: https://jupyter-notebook.readthedocs.io/en/stable/extending/savehooks.html

mlucool avatar Oct 25 '19 14:10 mlucool

Closed by #195?

black-puppydog avatar Oct 15 '22 12:10 black-puppydog

Closed by #195?

Bingo, I haven't been doing house cleaning at all, closing now.

ryantam626 avatar May 05 '23 08:05 ryantam626