spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.38k stars 1.62k forks source link

Feature request: Kivy syntax highlighting #2311

Open sirpercival opened 9 years ago

sirpercival commented 9 years ago

Kivy has a pygments-based lexer: https://github.com/kivy/kivy/blob/master/kivy/extras/highlight.py

Can this be included in syntaxhighlighters.py?

goanpeca commented 9 years ago

Sure it can, want to give it a try ?

You can take a look at: https://github.com/spyder-ide/spyder/blob/master/spyderlib/widgets/sourcecode/syntaxhighlighters.py


@ccordoba12 Was not this supposed to guess automatically with the work of PR #97 in bitbucket?

Nodd commented 9 years ago

I guess that the pygment definitions are not in pygments itself but provided by kivy, so spyder doesn't know abut them.

cooknl commented 9 years ago

The link to the spyder syntaxhighlighters.py is broken

They moved it from sourcecode to utils

https://github.com/spyder-ide/spyder/blob/master/spyderlib/utils/syntaxhighlighters.py

cooknl commented 9 years ago

I posted a question to StackOverflow: http://stackoverflow.com/questions/33462949/how-is-syntaxhighlighters-py-called-by-spyder-ide

goanpeca commented 9 years ago

Hi @cooknl, as @Nodd pointed out, pygments does not natively support kivy highlighting (Look a t the available lexers here)

You could very easily add this ability by modifying the Generic Pygments Highlighter located here

Now you would need to add the kivy somewhere in spyder codebase, for now it could be in syntaxhighlighters.py, unless @nodd or @ccordoba12 have a better place for it, some file that stores pygments specific lexers?

And then you could update this so that the if has an extra condition where it fins if it is a .kv file and based on that assigns the correct custom lexer.

Cheers

Nodd commented 9 years ago

Instead of including the file in spyder, could we simply try to import it and use it if it is found ?

goanpeca commented 9 years ago

Sure, thats an option as well, not sure if kivy isinstalled the usual way (as a python package though...)

goanpeca commented 9 years ago

Or we could just submit it to pygments in bitbucket as a request?

Nodd commented 9 years ago

kivy is used as import kivy, so import kivy.extras.highlight in a try/except block should do the trick.