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

Visual help for indentation: draw spaces and tabs #670

Closed
spyder-bot opened this issue Feb 17, 2015 · 43 comments
Closed

Visual help for indentation: draw spaces and tabs #670

spyder-bot opened this issue Feb 17, 2015 · 43 comments

Comments

@spyder-bot
Copy link
Collaborator

From jorisvan...@gmail.com on 2011-05-29T03:29:41Z

This is actually a feature request.

In gedit there is a plugin that allows you to 'draw spaces and tabs' ('Draw spaces' in the gedit-plugins package). I find it very handy to see visually of my indentation is correct. Certainly for example, if you have a blank line in an indentated group like a class of function definition or for loop, that blank line has also to be indentated with the same level. But you can't visually see if this is done correctly or not. When you have the 'draw spaces' enabled it is much easier (see example in attachment how it looks like).

So I wonder if something like this would be possible in Spyder (as an option in the preferences)?

Attachment: gedit-printscreen.png

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=670

@spyder-bot
Copy link
Collaborator Author

From jorisvan...@gmail.com on 2011-05-29T01:32:14Z

And you don't have to look at the code in the example, just to show what I mean. Because defining a function in a for loop each time again is rather stupid :-)

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2011-10-08T06:57:54Z

There is no option to do this right now, but it would be really really helpful. I'll see what I can do about it.

Labels: -Type-Defect Type-Enhancement Cat-Editor

@spyder-bot
Copy link
Collaborator Author

From contrebasse on 2012-03-14T16:28:04Z

I'd rather have indentation lines, like geany (and others) has. It's especially useful in python to see blocks.

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2012-03-18T14:09:58Z

Labels: -Type-Enhancement Type-Enh

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-02-13T09:41:25Z

Labels: MS-v2.3

@spyder-bot
Copy link
Collaborator Author

From omegat...@gmail.com on 2013-02-13T10:03:34Z

Notepad++ does this, too. I have the space dots turned really light so they aren't distracting, but the tab arrows then end up a little too dark.

Attachment: Notepad++ space and tabs.png

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2013-03-12T05:43:06Z

Summary: Visual help for indentation: draw spaces and tabs (was: Visual help for indentation: draw spaces)

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2013-03-12T05:43:30Z

issue #1308 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2013-03-13T04:37:23Z

issue #1311 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2013-05-11T05:32:15Z

Labels: -MS-v2.3 MS-v2.4

@spyder-bot
Copy link
Collaborator Author

From dr.bag...@gmail.com on 2013-08-07T12:26:10Z

Given how useful it is for python, I'd vote for implementing something similar to sublime. lines for tabs, dots for spaces. See pic.

Attachment: XDUxE.png

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-08-09T19:57:14Z

You are right: we should provide this functionality because of its importance to learn and use Python.

I know how to do it and even had a patch to make it work a long time ago, so it shouldn't be that hard to make it work again.

Status: Accepted
Labels: -MS-v2.4 MS-v2.3

@spyder-bot
Copy link
Collaborator Author

From contrebasse on 2013-08-12T04:14:28Z

I would prefer vertical lines over the sublime way, because I find it clearer to see the indentation. The important information is not the number of tabs but rather the alignment with previous blocks of code.

Visually differentiating between tabs and space can help check indentation coherency, but this can be automatically corrected anyway.

Of course, any solution is better than nothing !

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2013-08-12T05:02:01Z

I fully agree with contrebasse.

@spyder-bot
Copy link
Collaborator Author

From dr.bag...@gmail.com on 2013-08-12T06:35:41Z

I still prefer the sublime way. Unless I'm misunderstanding you guys, it has best of both worlds as you do also get alignment information, the vertical lines may be subtle, but that's just the theme. Perhaps, if it's not that much added effort, a few options to accommodate both methods?

@spyder-bot
Copy link
Collaborator Author

From omegat...@gmail.com on 2013-08-12T08:05:05Z

it seems notepad++ has both? horizontal lines (with arrows) for tabs, dots for spaces, and vertical lines for "indent guide"?

@spyder-bot
Copy link
Collaborator Author

From contrebasse on 2013-08-13T07:35:23Z

Oh yeah, the vertical lines are present in sublime, they are visible when looking at the full scale image. Sorry.

@spyder-bot
Copy link
Collaborator Author

From ajande...@gmail.com on 2013-08-13T17:44:09Z

This would be a beautiful thing. It would definitely make nested loops easier to look at. I've been setting the "show vertical line" at multiples of 4 to make sure things are lined up :(

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-09-04T11:50:58Z

issue #1478 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-12-11T12:17:37Z

Labels: -MS-v2.3 MS-v2.3.1

@spyder-bot
Copy link
Collaborator Author

From Norl...@gmail.com on 2013-12-19T22:51:20Z

So once again I have to open up my file in notepad++ to fix indentation by visual inspection because my file is FUBAR from some cut and paste operation... what is the status on this feature request? I really don't care how its displayed just so long as I am able to discern the different breads of white space.

[coming from a c background it still has me stumped why people think its a good idea to be able to break code via invisible differences in the file!]

@spyder-bot
Copy link
Collaborator Author

From trueflyi...@gmail.com on 2013-12-20T01:29:11Z

coming from a c background it still has me stumped why people think its a good idea to be able to break code via invisible differences in the file!

step 1: use python 3 instead of python 2
step 2: see python loudly complain if you made an error with indentation
step 3: acknowledge that this is better than a language where visual indentation might mismatch with logical blocks.

but i agree that step 2 can be replaced with, “don’t make indentation mistakes since you see indentation in the editor”

@spyder-bot
Copy link
Collaborator Author

From contrebasse on 2014-01-07T06:34:29Z

You can use autopep8 to automatically correct the indentation (where possible). There's a plugin for spyder (disclaimer: I'm the author of the plugin): https://github.com/Nodd/spyder_autopep8

@spyder-bot
Copy link
Collaborator Author

From rbrato on 2014-04-25T03:37:41Z

Vertical lines, that would show the indentation would be very helpful. I have just started using Spyder and am missing them so much from Notepad++. Writing long/many lines codes in Spyder will become so much easier to follow with at least the vertical indentation guides.
Now, I have to look at column number to re-indent specific lines, but this is very troublesome with code blocks.
Please find a solution for indentation guides on Spyder.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-05-17T17:41:58Z

I think points are easier on the eye than lines. I'll try to implement it for 2.3.1 (I had a prototype a long time ago).

@spyder-bot
Copy link
Collaborator Author

From phyo.arkarlwin on 2014-06-24T16:40:32Z

I like the way kate does it , can chose points or vertical lines or both.
Can i check your prototype and see if i can help?

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-06-27T10:50:14Z

My prototype is not publicly available but you could take a look at IEP source code to see how they do it: https://bitbucket.org/iep-project/iep

@spyder-bot
Copy link
Collaborator Author

From nicola.m...@tut.by on 2014-07-21T00:18:09Z

Hello all,

Some time ago I've implemented a small dirty hack to show spaces and tabs. This is still working in Spyder ver. 2.3.0rc (as with Anaconda 2.0 under Windows). Perhaps, after some polishing and adding configuration controls, this can be a basis of 'real' implementation:

In the file <PYTHON_DIR>\Lib\site-packages\spyderlib\widgets\sourcecode\codeeditor.py I've added the following lines at the end of set_language() of CodeEditor class

    option = self.document().defaultTextOption()
    option.setFlags(option.flags() | QTextOption.ShowTabsAndSpaces)
    option.setFlags(option.flags() | QTextOption.AddSpaceForLineAndParagraphSeparators)
    self.document().setDefaultTextOption(option)

For this to work, it is necessary to import the class QTextOption from spyderlib.qt.QtGui

The idea was taken from discussion at http://www.qtcentre.org/threads/27245-Printing-white-spaces-in-QPlainTextEdit-the-QtCreator-way Perhaps, there is a better way to implement the whitespace visibility, but I does not know the Spyder internals well enough.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-08-17T18:29:23Z

Labels: -MS-v2.3.1 MS-v2.3.2

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-09-21T10:36:01Z

To solve this we need to

  1. Create a new entry in the "Source" menu to activate/deactivate this option

  2. Create an option under

    Preferences > Editor > Advanced Settings > Source code

    To let users apply this option to all their files.

Labels: Easy

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-10-31T15:10:19Z

Labels: -MS-v2.3.2 MS-v2.4

@spyder-bot
Copy link
Collaborator Author

From TheSa...@gmail.com on 2014-11-20T13:45:41Z

@-ccordoba: is there any chance to have this new feature in the next release?
@#28: I tried this in spyder 2.3.1 without success

@spyder-bot
Copy link
Collaborator Author

From nicola.m...@tut.by on 2014-11-25T00:50:07Z

@#32: I'm using Spyder v. 2.3.1 (Anaconda 64-bit distribution on MS Windows) and have patched it without issues.

Have you tried to run Spyder from console to see any errors?

As I've written before in comment #28, I regard this as dirty hack, but it suits me and my teammates.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-11-25T08:48:46Z

Ok, given its high demand, I'll work on this issue for 2.3.3. Unfortunately 2.3.2 is almost ready ;-)

Labels: -MS-v2.4 MS-v2.3.3

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2015-02-03T12:49:11Z

This issue was updated by revision 3a925f7ed02a .

Status: Started

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2015-02-03T12:49:12Z

This issue was updated by revision 43df2897db69 .

Status: Fixed

@spyder-bot
Copy link
Collaborator Author

From contrebasse on 2015-02-05T01:59:13Z

I think only part of the proposal is fixed. Sure, spaces are shown but
1- they are shown everywhere, not for indentation only
2- they don't highlight blocks at all, like vertical lines would do. For me this is the only use of showing indentation.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2015-02-05T07:44:36Z

About your points:

  1. This is a limitation of Qt. I did a bit of research and it seems there's nothing to prevent it showing all blanks.
  2. We can also add vertical lines to identify blocks, but this issue was about blank spaces, so that's what I fixed :-) Please open a new issue about vertical lines. I'll see if I can fix it for 2.3.4.

@spyder-bot
Copy link
Collaborator Author

From nicola.m...@tut.by on 2015-02-09T00:45:15Z

Very good to see the issue fixed! Thank you!

For me (as everyday Spyder user) it is quite helpful to see spaces and (eventually) tabs everywhere - indentation, trailing spaces, etc. to have my code cleaner.

@hugobuddel
Copy link
Contributor

Could the dots to highlight the spaces perhaps have a lighter color?

Currently it seems to have the 'Normal text' color, which is a bit to dark and makes the code hard to read. The attached gedit screenshot and the eclipse one from duplicate #1478 are easier to read.

@Nodd
Copy link
Contributor

Nodd commented Jun 23, 2015

This has been reported in #2175. It should be doable with the syntax highlighter.

@ccordoba12
Copy link
Member

@hugobuddel, that doesn't depend on us, sorry :-(

@dougthor42
Copy link
Contributor

@hugobuddel, that doesn't depend on us, sorry :-(

For a little more info, see the details of #2437. Basically, the dot characters are set by Qt. You can help out by commenting on or voting for https://bugreports.qt.io/browse/QTBUG-46072

EDIT:
I just saw that you already found out all this info in #2501 and #2175.

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