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

QSyntaxHighlighter and Pygments do not properly interoperate, leading to occasional mis-highlighting #2122

Closed
spyder-bot opened this issue Feb 17, 2015 · 5 comments
Assignees
Milestone

Comments

@spyder-bot
Copy link
Collaborator

From [email protected] on 2015-01-18T11:36:30Z

As noted in my recent pull request [1], certain filetypes will not highlight well when using Pygments. This is because the base class, QSyntaxHighlighter [2] breaks text into blocks (individual lines) and tries to highlight them one at a time [3], whereas Pygments is set up to highlight whole files at once; when Pygments is asked to highlight individual lines, it can't always give the right results (see, for example, multi-line comments in a css file like this one [4]).

This disconnect will be tough to work around. IPython has a sophisticated attempt [5], but I don't know how well it can be adapted to Spyder. I'll investigate and hopefully have some sort of fix I can offer, but I'm not sure I can solve it.

[1] bitbucket.org/spyder-ide/spyderlib/pull-request/97/
[2] http://qt-project.org/doc/qt-4.8/qsyntaxhighlighter.html [3] https://bitbucket.org/spyder-ide/spyderlib/src/b5a5ef2bb4d59a437a111fff7cb03faf09e86d3f/spyderlib/widgets/sourcecode/syntaxhighlighters.py?at=default#cl-856 [4] https://raw.githubusercontent.com/daneden/animate.css/master/animate.css [5] https://github.com/ipython/ipython/blob/master/IPython/qt/console/pygments_highlighter.py

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

@spyder-bot
Copy link
Collaborator Author

From contrebasse on 2015-01-18T16:02:07Z

I don't understands the details, but it seems to me that QSyntaxHighlighter has a way to manage blocks bigger than one line since it highlights multiline strings just fine ?

@spyder-bot
Copy link
Collaborator Author

From [email protected] on 2015-01-18T18:30:21Z

Sorry, I forgot to mention that. QSyntaxHighlighter has a method for setting state from one block to the next. So if a block starts a multi-line comment, the next block knows that it is currently inside a multi-line comment and can be highlighted accordingly. But there's no (easy) way to connect that state mechanism with Pygments' highlighting. If Pygments sees a /* but no corresponding */, it will just think it's an error; it won't indicate that a comment has started, and has no way to tell later blocks that they are still inside a comment.

@spyder-bot
Copy link
Collaborator Author

From contrebasse on 2015-01-19T02:29:40Z

I understand now, thanks.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2015-01-30T13:56:48Z

Status: Accepted
Labels: Cat-Editor MS-v2.4

@randyheydon
Copy link
Contributor

Also see my unfinished pull request in relation to this issue.

@ccordoba12 ccordoba12 modified the milestones: v3.0, v3.0beta4 Jan 27, 2016
@ccordoba12 ccordoba12 modified the milestones: v3.0beta4, v3.0rc1 Apr 25, 2016
@ccordoba12 ccordoba12 modified the milestones: v3.1, v3.0beta4 Jun 11, 2016
@ccordoba12 ccordoba12 modified the milestones: v3.1, v3.1.1 Jan 6, 2017
@goanpeca goanpeca removed the 1 star label Jan 14, 2017
@ccordoba12 ccordoba12 modified the milestones: v3.1.1, v3.1.2 Jan 18, 2017
@ccordoba12 ccordoba12 modified the milestones: v3.1.2, v3.1.1, v3.1.3 Jan 18, 2017
@ccordoba12 ccordoba12 modified the milestones: v3.1.3, v3.2 Jan 27, 2017
@ccordoba12 ccordoba12 modified the milestones: v3.2, v3.3 Feb 14, 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

4 participants