-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Editor - Show blank spaces suggestions #2175
Comments
From ccordoba12 on 2015-02-15T15:18:53Z Good suggestions. About them:
Status: HelpNeeded |
Well a direct way of doing it is not available on the Qt side, but there is a way but seems to convoluted just for this.... but it is something like this: An editor would be in reality two, the one that is displayed and the one that holds the information, the one that is displayed will have the characters replaced but whatever our needs and the one that is on the "background" will hold the original text, but they should remain in sync ... but seems like a lot for such a simple thing, unless there is something extra we could gain from this approach.... |
@goanpeca Yes, there is: Vim support :-) We need two Editors for Vim support: one in command mode and in edit mode. But it's true, it's too much work... |
Hmmm, just out of curiosity I will give it a quick go (just to see if it can work) but I will not go in depth in keeping the rest functional.... completio etc... just to see if it can work or not.. |
FYI, I think it's possible to enable vim shortcuts without having two editors, see https://github.com/Nodd/spyderplugins.vim |
A brighter color or different glyph for the spaces would indeed be nice. Apparently more Spyder users are interested: https://bugreports.qt.io/browse/QTBUG-46072 There are several different syntax coloring groups already. Would it be possible to add a 'space' syntax group and assign a specific color to that? With respect to the last suggestion, I like to see all my spaces, especially the trailing ones. |
The problem is we don't have access to the dots that represent blank spaces to give them a different color. They are not real dots, they are just added by Qt and have the same color than regular text. |
But we should be able to change the color of the regular text for the spaces (or tabs), right ? (Even if we can't change the dots themselves). |
I've taken some syntax highlighter example code and modified it such that it shows and highlights spaces by adding a rule for a single space. In opts = self.editor.document().defaultTextOption()
opts.setFlags(opts.flags() | QtGui.QTextOption.ShowTabsAndSpaces)
self.editor.document().setDefaultTextOption(opts) In spaceFormat = QtGui.QTextCharFormat()
spaceFormat.setForeground(QtCore.Qt.red)
self.highlightingRules.append((QtCore.QRegExp(" "), spaceFormat)) Perhaps I'll make fork of Spyder and make a pull request. This should be enough information for someone else to pick it up in case I won't get around to it. |
A first attempt that works well enough for me: https://github.com/hugobuddel/spyder/commit/8704814eb4055c7c7fa268ac52e2235642ffb3e1 It simply assigns the It might be too much work for me to generalize this, given my very limited experience with Spyder (and Qt). Therefore I didn't create a pull request just now. Does this warrant a user-defined color? Does this solution work with other schemes? Are there problematic edge-cases? Etc. Perhaps a more beautiful solution would be to just make every space a bit brighter than the surrounding text, or a bit darker for dark schemes. |
@hugobuddel, it's really great that you've found a way to do this!! Kudos to you! :-) But please, please make a pull request so we can better discuss not only your code but the colors assigned to spaces. |
Done @ccordoba12 ! |
Fixed in #2501 |
From goanp...@gmail.com on 2015-02-14T12:29:43Z
Spyder Version: 2.4.0dev (4931: r1ff46f376d07 )
Python Version: 2.7.9
Qt Version : 4.8.5, PySide 1.2.1 on Linux
pyflakes >=0.5.0: 0.5.0 (OK)
pep8 >=0.6 : 1.4.6 (OK)
IPython >=1.0 : 2.3.1 (OK)
zmq >=2.1.11 : 14.4.1 (OK)
pygments >=1.6 : 2.0.1 (OK)
pandas >=0.13.1 : 0.15.2 (OK)
sphinx >=0.6.6 : 1.2.3 (OK)
psutil >=0.3 : 2.1.1 (OK)
jedi >=0.8.1 : None (NOK)
rope >=0.9.2 : 0.10.2 (OK)
matplotlib >=1.0: 1.4.2 (OK)
sympy >=0.7.0 : 0.7.6 (OK)
pylint >=0.25 : None (NOK)
What steps will reproduce the problem?
What is the expected output? What do you see instead?
The function works but I have some suggestions/comments...
Please provide any additional information below
.
I would suggest:
1.) The dots are the same color as main text, they should be lighter, to provide guidance without being too intrusive
2.) It would be nice to sync the indentation characters selected in the Editor Advanced preferences to display the same, so if 4 spaces is selected, every 4 spaces, the dot should become a bar
|
or should be a bit different to show this clearly3.) I think having dots for the indentation before any content in the line is more than enough. The idea of having this is to guide with indentation, but right now every single space is "highlighted", which can be distracting in the middle of definition of variables and statements of code
Original issue: http://code.google.com/p/spyderlib/issues/detail?id=2175
The text was updated successfully, but these errors were encountered: