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

Outline Explorer: disable if/else/try/for statements #5821

Closed
mherrmann3 opened this issue Nov 23, 2017 · 10 comments
Closed

Outline Explorer: disable if/else/try/for statements #5821

mherrmann3 opened this issue Nov 23, 2017 · 10 comments

Comments

@mherrmann3
Copy link

The Outline Explorer is really useful to jump to certain parts of the code quickly -- especially to functions, classes, code cells, and even comments starting with # ---. Especially the latter two help to structure a longer script better. However, the Outline Explorer also shows every if/else/try/for which makes the outline basically useless: for a rather long file, the actual main structures (functions, cells, etc.) are somewhere in between several if/else/try/for code statements that are rather meaningless for an actual "outline" (especially the single else: lines).

For this reason I ask whether you can implement an additional option in the right-click menu like "Show if/else/try/for... statements" ... just as there exists "Show special comments" to toggle code cell and # --- comments. Thanks for considering!

@mherrmann3 mherrmann3 changed the title Outline Explorer: optionally show if/else/try/for statements Outline Explorer: optionally disable if/else/try/for statements Nov 23, 2017
@CAM-Gerlach
Copy link
Member

I can second that; this would indeed be very useful. In general, I'm not sure I understand what general reason there would be to give if/else/try/catch substantially more importance than any other line of code, at least on the level of functions, classes, cells, etc, particularly without any option to disable it. I wouldn't think this would be too difficult to do...

@jnsebgosselin
Copy link
Member

If @ccordoba12 accept it, I can take a look at it since it is something that has been bothering me for some time now.

@ccordoba12
Copy link
Member

Jean, I think we should remove the code that shows if/else/try/for in the Outline Explorer. It's something that bothers me too, but I haven't had the time to fix it.

@jnsebgosselin
Copy link
Member

Perfect @ccordoba12 , consider it done :)

@ccordoba12 ccordoba12 changed the title Outline Explorer: optionally disable if/else/try/for statements Outline Explorer: disable if/else/try/for statements Nov 27, 2017
@ccordoba12 ccordoba12 modified the milestones: v4.0beta2, v4.0beta1 Dec 26, 2017
@robach
Copy link

robach commented Jan 12, 2021

Hello,

Many thanks for the nice editor, the outline Pane helps a lot.

I just switched to spyder 4.
Unfortunately many of my runtime scripts use blocks starting by "if"
for easy navigation and "menu-like" running of smaller code blocks.

Now I need to modify 10 years of scripts to add "####" lines before each "if".

Would it be possible to add an option to include again the if/else/try/for statements in the outline ?

Just in case this would be a really-easy task on your side.

Thanks
Best regards

@robach
Copy link

robach commented Jan 12, 2021

a fix using sed

sed -i 's/^if ./#### &\n&/' test.py
sed -i 's/^ if .
/####---- &\n&/' test.py
sed -i 's/^ if .*/####-------- &\n&/' test.py

(but the "expandable" outline of spyder 3 was nicer)

@CAM-Gerlach
Copy link
Member

Hey, sorry about that. If there's enough interest from other users, @ccordoba12 might consider a PR, which you could base on the code that was removed by PR #5842; I'm just not sure how widely something like this would be used. As an alternative, you could consider replacing them with code cell comments instead of plain ones (# %% Optional descriptive text), which do allow the code within them to be expanded/collapsed just like your if statements, while also allowing you to give them a name/description, run just the code inside, and a few other features.

@ccordoba12
Copy link
Member

I think @jnsebgosselin decided to remove that functionality because it introduced too much noise in the Outline (and I agree with that). So I don't think we'd like it back.

@CAM-Gerlach
Copy link
Member

To be clear, I was referring to considering it as an option, off by default, if broader support among users was plausible, rather than always on as before. However, given this is the first time someone has requested it back, as far as I'm aware, and an alternative (code cells) exists that would provide the same benefits and more, and can be added with simple sed commands (or Spyder's own find/replace, etc), I'm not sure I see a compelling case for it.

@robach
Copy link

robach commented Jan 17, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants