spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.3k stars 1.61k forks source link

Enhacements to code folding #8090

Open Skottfelt opened 6 years ago

Skottfelt commented 6 years ago

I am using spyder4.0.0b1, so sorry if the following is already implemented in future releases.

First of all, thank you for implementing code-folding functionality! What I could use is a 'Fold-all' button, or that the editor remembers the folding status, when a file is opened, such that I don't have to fold all the code again everytime I open a file.

bcolsen commented 6 years ago

Thanks @Skottfelt. This is a good point.

Code folding might need an epic issue.

Issues off the top of my head:

ccordoba12 commented 6 years ago

@bcolsen, very good suggestions, thanks! Unfortunately, I think we'll implement them after Spyder 4 is released, unless someone else helps us with them.

gerazov commented 5 years ago

I love the new code folding!

I want to add a suggestion too: make code folding stop at first unindented line. Currently it stops at the first unindented code (I guess).

Here's what I mean: image

After folding becomes: image

And it would be better not to touch the comment.

bcolsen commented 5 years ago

@gerazov Great suggestion! That's really unfortunate that it folds the comment like that.

RichardPflaum commented 5 years ago

First of all I'm super excited about finally being able to fold the code. Thank you for the great work with Spyder! I also have two suggestions for further enhancements:

Saravji commented 5 years ago

Tagging a bug in code folding onto this thread as it is closely related (presumably): In case code blocks are folded, the hint re Code analysis does not appear. When clicking on the yellow icon, the editor window jumps close to the top of the code. Using v 4.0.0.b1, python 3.7.1, ubuntu 18.04

aryoung2010 commented 5 years ago

I updated to 4b2 and I can't figure out how to use the folding. Would someone explain it to me? Thanks!

pbower commented 5 years ago

Hi all, I’ve been using version 4 for a few days. Let me know if I’ve missed something as it’s been hard to access documentation. Is there a way to add code folds anywhere you like? Currently it looks like it’s just under comments with “”” , and functions, classes etc. However if you are working on a simple script, one can’t fold lots of code because python won’t let you indent without a reason under your comments (so you can’t use comments to break up your code and fold it into sections.) Additionally, one wouldn’t want to create fake functions just to get code folded. Thanks

ccordoba12 commented 5 years ago

Is there a way to add code folds anywhere you like?

No and it won't be possible in the final version, sorry.

pbower commented 5 years ago

Will you guys consider adding it in future? It would be really useful

Get Outlook for iOShttps://aka.ms/o0ukef


From: Carlos Cordoba notifications@github.com Sent: Thursday, October 17, 2019 1:28:54 PM To: spyder-ide/spyder spyder@noreply.github.com Cc: Peter doctor_bower@hotmail.com; Comment comment@noreply.github.com Subject: Re: [spyder-ide/spyder] Enhacements to code folding (#8090)

Is there a way to add code folds anywhere you like?

No and it won't be possible in the final version, sorry.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/spyder-ide/spyder/issues/8090?email_source=notifications&email_token=AI27BYT7OSKR6ANQ7E3LZP3QO7EWNA5CNFSM4F4PCTM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBOQXNA#issuecomment-542968756, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AI27BYWHQZPN76Y3OJYQIXDQO7EWNANCNFSM4F4PCTMQ.

bcolsen commented 5 years ago

@pbower There are plans for code folding for code cell blocks with support for code cell groups which should cover most of your request.

Currently spyder4's outline explorer will place code cells as the top level for easy navigation of long files so you might not need the folding as much. https://docs.spyder-ide.org/editor.html#defining-code-cells

ElieGouzien commented 4 years ago

Hey, I have another suggestion. Also you did a fantastic job with code folding, I think there should be an option to deactivate it and remove the associated vertical bar (just as for line numbers).

jnsebgosselin commented 4 years ago

Hey, I have another suggestion. Also you did a fantastic job with code folding, I think there should be an option to deactivate it and remove the associated vertical bar (just as for line numbers).

I agree with this. See https://github.com/spyder-ide/spyder/issues/6628.

wangbowenll commented 4 years ago

I have update spyder to 4.0.1 but i can not find the function of code folding. please help me

wangbowenll commented 4 years ago

我喜欢新的代码折叠!

我也想添加一个建议:使代码折叠在第一行不缩进处停止。目前,它在第一个未缩进的代码处停止(我想)。

这就是我的意思: 图片

折叠后变为: ![图片](https://user-images.githubusercontent.com/15214418/48624757-8a144b80-e9ad-11e8-91a3-6b12d6c51e6e.png

I love the new code folding!

I want to add a suggestion too: make code folding stop at first unindented line. Currently it stops at the first unindented code (I guess).

Here's what I mean: image

After folding becomes: image

And it would be better not to touch the comment.

hello , I have updated the spyder to 4.0.1,but in setting i can not find the function of code fold. why? please help me.

wangbowenll commented 4 years ago

I updated to 4b2 and I can't figure out how to use the folding. Would someone explain it to me? Thanks!

I updated to 4.0.1and I also can't figure out how to use the folding. what should i do? please help me

shyok0 commented 4 years ago
  1. Improvement to code folding (ref: Pycharm kind of folding)
  2. Seperate code folding provision for block of comments
  3. window minimizing (console, help, plots windows) something like in Pycharm

Hopefully, these things in next release.

VikneshSK commented 4 years ago

@wangbowenll yes, even i am expecting similar documentation. I need to do code folding myself.

pbower commented 4 years ago

It is good but RStudio code folding is still a lot better. With a bunch of asterisk’s once can each separate / hide parts of their code so they don’t need to spend ages scrolling through things or hit the page up/down buttons. In spyder, it’s not possible to manually add a code fold it only happens in certain situations, which is really annoying.

Get Outlook for iOShttps://aka.ms/o0ukef


From: VikneshSK notifications@github.com Sent: Friday, January 31, 2020 8:30:21 PM To: spyder-ide/spyder spyder@noreply.github.com Cc: Peter doctor_bower@hotmail.com; Mention mention@noreply.github.com Subject: Re: [spyder-ide/spyder] Enhacements to code folding (#8090)

@wangbowenllhttps://github.com/wangbowenll yes, even i am expecting similar documentation. I need to do code folding myself.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/spyder-ide/spyder/issues/8090?email_source=notifications&email_token=AI27BYRAKH27JIXMHMRER7DRAPVS3A5CNFSM4F4PCTM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKOB3YA#issuecomment-580656608, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AI27BYWXW5SO4OULGKIOJR3RAPVS3ANCNFSM4F4PCTMQ.

goanpeca commented 4 years ago

@pbower

In spyder, it’s not possible to manually add a code fold it only happens in certain situations, which is really annoying.

Have you tried using cells??

# %% This is a cell with a name and is foldable
bcolsen commented 4 years ago

Have you tried using cells??

Code cell folding isn't implemented in Spyder yet. It's one of the suggestions and should mostly cover @pbower 's suggestions.

To navigate quickly through long code currently I'm using the outline panel with named code cells and code cell groups

OverLordGoldDragon commented 4 years ago

A workaround I figured: if 1: at top of cell. Drawback: indentation.

pbower commented 4 years ago

Code cell folding would definitely do it. Yes the folding need is especially for long code, doing ‘page up’ ‘page down’ is very difficult when everything you want to be folded can’t be. Even split screen on different parts of the code - still hard to navigate. Thanks for responses. Cheers

Get Outlook for iOShttps://aka.ms/o0ukef


From: OverLordGoldDragon notifications@github.com Sent: Saturday, February 8, 2020 10:57:55 AM To: spyder-ide/spyder spyder@noreply.github.com Cc: Peter doctor_bower@hotmail.com; Mention mention@noreply.github.com Subject: Re: [spyder-ide/spyder] Enhacements to code folding (#8090)

A workaround I figured: if True: at top of cell. Drawback: indentation.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/spyder-ide/spyder/issues/8090?email_source=notifications&email_token=AI27BYXRLX24EKJZHMK4IWLRBXYQHA5CNFSM4F4PCTM2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELFAQDI#issuecomment-583665677, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AI27BYQVWNRML7VTZXRQNVDRBXYQHANCNFSM4F4PCTMQ.

EduardoNigro commented 3 years ago

Hi folks,

I have been programming in MATLAB forever and they have excellent code folding capabilities. After reading all the comments above, I just want to reiterate the importance of saving the last folded "state" of a given file. I would also make the new suggestion where you can choose which parts of the code are folded (see image) once you hit the shortcuts for fold/unfold all.

Code Folding Options

I use this all the time and it really helps to have (in my case) methods and properties (attributes) folded inside my classes, as shown in the image below. Please keep in mind the syntax differences between MATLAB and Python.

Code Folding Example

Easier sad than done. I hope this helps. Thanks, Eduardo

mcnoat commented 2 years ago

I second the request by @ bcolsen for a "fold all" feature. This would make it that much easier for me to navigate my code.

01tot10 commented 2 years ago

+1 For a couple of variants of "fold-all" feature, as mentioned by @bcolsen, @mcnoat. My projects have been growing lately, and have found myself scrolling up and down my source code for unnecessarily long. Having shortcuts for "Fold all", "Fold all functions", "Fold all docstrings", and the like, would be a lifesaver for me. Also, remembering the source file folding state would be useful in the long run.