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

Editor - Show blank spaces suggestions #2175

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

Editor - Show blank spaces suggestions #2175

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

Comments

@spyder-bot
Copy link
Collaborator

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?

  1. Activating the 'Show blank spaces' in the Source menu

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 clearly
3.) 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

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2015-02-15T15:18:53Z

Good suggestions. About them:

  1. No idea how that could be done. I just activated a Qt option to show blank spaces in QPlainTextEdit widgets. So I don't know how dots color is selected.
  2. Vertical bars can be activated too, but that's not related to blank spaces, that's a different issue. So please open a new one for that.
  3. That's a Qt limitation. I know, a bit ugly, but I did a bit of research and it seems there is no way to change it. Could be wrong though :-)

Status: HelpNeeded
Labels: Cat-Editor

@goanpeca
Copy link
Member

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....

@ccordoba12
Copy link
Member

@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...

@goanpeca
Copy link
Member

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..

@Nodd
Copy link
Contributor

Nodd commented Jun 23, 2015

FYI, I think it's possible to enable vim shortcuts without having two editors, see https://github.com/Nodd/spyderplugins.vim

@hugobuddel
Copy link
Contributor

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.

@ccordoba12
Copy link
Member

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.

@Nodd
Copy link
Contributor

Nodd commented Jun 23, 2015

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).

@hugobuddel
Copy link
Contributor

Yes it is possible:
syntaxhighlighter

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 MainWindow.setupEditor():

        opts = self.editor.document().defaultTextOption()
        opts.setFlags(opts.flags() | QtGui.QTextOption.ShowTabsAndSpaces)
        self.editor.document().setDefaultTextOption(opts)

In Highlighter.__init__():

        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.

@hugobuddel
Copy link
Contributor

A first attempt that works well enough for me: https://github.com/hugobuddel/spyder/commit/8704814eb4055c7c7fa268ac52e2235642ffb3e1

It simply assigns the comment color to the new space pattern. The default comment color is a bit lighter than main text, which was my immediate goal. The spaces within colored texts, e.g. within a string, retain the surrounding color. The space pattern has to be at the start of the join at the end of make_python_patterns() because otherwise some keywords will match the space before them.

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.

spyderfullcrop

@ccordoba12
Copy link
Member

@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.

@hugobuddel
Copy link
Contributor

Done @ccordoba12 !
Pull request made, with different code. I'll add some screenshots to the pull request.
I'm fairly new to git pull requests. I think I did it right this time by rebasing to upstream/master.

@rlaverde
Copy link
Member

rlaverde commented Jun 9, 2017

Fixed in #2501

@rlaverde rlaverde closed this as completed Jun 9, 2017
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

6 participants