Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code folding #4083

Closed
horsto opened this issue Mar 1, 2018 · 26 comments
Closed

Code folding #4083

horsto opened this issue Mar 1, 2018 · 26 comments

Comments

@horsto
Copy link

@horsto horsto commented Mar 1, 2018

Currently when I click on the blue vertical bar next to a cell only 3 dots remain. That way all the info about that cell is lost. I don't see an option to enable code folding (e.g. if the first line contains a comment, leave that comment there and also let the cell be executable).
Are folding vs. collapsing things that should be handled completely separate? If so, is there a plan to implement code folding? Especially for long cells with only python import statements that would be extremely useful in my opinion.

@blink1073
Copy link
Member

@blink1073 blink1073 commented Mar 1, 2018

Hi @horsto, we have not yet considered cold folding as an option.

@horsto
Copy link
Author

@horsto horsto commented Mar 1, 2018

I understand. Hope it can be implemented in a future version! Thanks!

@ellisonbg
Copy link
Contributor

@ellisonbg ellisonbg commented Mar 2, 2018

@nikohansen
Copy link

@nikohansen nikohansen commented Apr 12, 2018

+1, code folding is the single feature which lets me hesitate to switch from notebook to lab.

@mmcguffi
Copy link

@mmcguffi mmcguffi commented Oct 12, 2018

+1 to above, codefolding and also collapsible headers are the only thing preventing me from making the switch -- those are just too important

@d8sconz
Copy link

@d8sconz d8sconz commented Oct 19, 2018

+1 to codefolding.

@vidartf
Copy link
Member

@vidartf vidartf commented Oct 19, 2018

For those interested to look at this, Codemirror has a code folding addon: https://codemirror.net/doc/manual.html#addons

From the top of my head you would need to:

  • Load the addon.
  • Expose an option/property on the editor interfaces to enable/disable folding.
  • Add a setting for the folding enabled state.
  • Add an action for changing the folding enabled state.

@d8sconz
Copy link

@d8sconz d8sconz commented Oct 20, 2018

@vidartf
Copy link
Member

@vidartf vidartf commented Oct 22, 2018

@d8sconz The codemirror addons are loaded here. An option can be added similarly to the scrollPastEnd flag. Initially, this should be sufficient to get it up an running (if the default of the folding flag is true it should always be enabled). Wiring it up to the settings/action can be done afterwards.

More general questions regarding working on the lab code are hopefully answered here: https://github.com/jupyterlab/jupyterlab/blob/master/CONTRIBUTING.md

Feel free to hop on the gitter channel if you have shorter, specific questions: https://gitter.im/jupyterlab/jupyterlab 😃

@Rabeez
Copy link

@Rabeez Rabeez commented Feb 22, 2019

image

I'm on jupyterlab 0.35.3
Has this not been added to the release package or something? Because the 'System Defaults' pane doesn't have any mention of code folding.
image

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented Feb 22, 2019

It's in the 1.0a1 prerelease.

@austinmw
Copy link

@austinmw austinmw commented Apr 9, 2019

@jasongrout how do you turn on this feature? (installed 1.0a1)

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented Apr 9, 2019

Go to the Settings > Advanced Settings menu item to pull up the settings editor. Then create a user config in the right side that sets the code folding item to true in the text editor or notebook settings (you can copy the defaults from left side, paste them into the right side, and change what you want).

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented Apr 9, 2019

For the text editor, this should work, for example:

{
    "editorConfig": {
         "codeFolding": true
    }
}

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented Apr 10, 2019

Saving the changes in the settings editor applies them immediately.

@jdcla
Copy link

@jdcla jdcla commented May 21, 2019

At this point, the status of folded code blocks are not saved by the server. This makes it rather unfriendly to use.

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented May 21, 2019

At this point, the status of folded code blocks are not saved by the server. This makes it rather unfriendly to use.

Right, all we save is the actual text file (for text files, of course) - there is no place for metadata about folded sections, etc. in a text file.

I'm curious - do you know any editor that saves the folded state? All the editors I'm familiar with don't save the folded state. I'm not saying that's the most friendly option, but I am curious about the status quo.

@mmcguffi
Copy link

@mmcguffi mmcguffi commented May 22, 2019

At this point, the status of folded code blocks are not saved by the server. This makes it rather unfriendly to use.

Right, all we save is the actual text file (for text files, of course) - there is no place for metadata about folded sections, etc. in a text file.

I'm curious - do you know any editor that saves the folded state? All the editors I'm familiar with don't save the folded state. I'm not saying that's the most friendly option, but I am curious about the status quo.

The extension for Jupyter Notebook saves the state of the folded code. +1 for this being an important feature to me

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented May 22, 2019

The extension for Jupyter Notebook

What Jupyter Notebook extension are you referring to?

@mmcguffi
Copy link

@mmcguffi mmcguffi commented May 22, 2019

What Jupyter Notebook extension are you referring to?

it's part of the nbextentions package:
https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/codefolding/readme.html

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented May 22, 2019

Thanks.

For reference, https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/codefolding/readme.html#internals says:

When saving a notebook, the folding information is saved in the metadata of each codecell. The number of the folding start line (beginning with 0) is stored in an array:

cell.metadata.code_folding = [ 3, 20, 33 ]

When reloading the notebook, the folding status is restored.

@bjpreisler
Copy link

@bjpreisler bjpreisler commented Jun 11, 2019

Saving the changes in the settings editor applies them immediately.

Forgive my ignorance, but when I attempt to save the appropriate text in the text editor, the save button is grayed out. I have made changes to the advanced settings text editor before when enabling extensions, but can't seem to figure out the issue here. Any thoughts?

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented Jun 11, 2019

You cannot save invalid json. Perhaps there is a missing or extra comma, etc.?

@atulkakrana
Copy link

@atulkakrana atulkakrana commented Jun 22, 2019

Code folding is the most basic thing to expect. It's unfortunate that VS code can't connect to JupyterHub notebooks.

@axil
Copy link

@axil axil commented Jul 19, 2019

+1 for porting codefolding extension to jupyterlab (with saving the folded state to json)

@triangulum
Copy link

@triangulum triangulum commented Aug 1, 2019

+1 for Collapsible Headings. It makes working with large notebooks so much more comfortable. I'll stick with Jupyter Notebook until that gets released.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.