Sublime Forum

Python's print() not considered a function by sublime scopes?

#1

I would expect both cases to have the same scopes…

1 Like

#2

The Python syntax definition that ships with ST3 is… not the best… I guess it has to be compatible with Python 2, where print is not a function. https://github.com/sublimehq/Packages/issues/51

0 Likes

#3

There are ways to be smarter about distinguishing print as a keyword and print as a function.

I have a rather high success rate in this branch of my PythonImproved fork. I intend to contribute that back to the original definition that gets shipped by ST on installation – at some point.

2 Likes

#4

Cool!

What’s the status of integrating this into ST? How “stable” is it for use as a plugin? What would I lose by not using the Neon theme, if I prefer the Monokai theme colors?

0 Likes

#5

I’ve been using it successfully for over a year now with little to no problems, although I can just fix those myself when I spot them.

Personally, I use the Tubnil color scheme (from the Nil theme), so it will work perfectly fine with any other color scheme than Neon.

To install, you can download the file from here and just save it in your User package or create a new arbitrarily named package for it.

1 Like

#6

Nice. Started using with the Monokai theme.

Now I have a bunch of open Python files with the “old” language (I set “PythonImproved” as the default for new ones I’ll open). Is there a quick way to switch all of them to “PythonImproved”?

0 Likes

#7

If it’s really that much, you can patch it with some Python code from the console, depending on your ST

[v.set_syntax_file("Packages/<whereever-you-put-it>/PythonImproved.tmLanguage") for w in sublime.windows() for v in w.views() if v.settings().get("syntax").startswith("Packages/Python/Python.")]
2 Likes

#8

Awesome! :smile:

42 Python files across 6 open windows at the moment, so this was quite handy.

In ST3, this worked perfectly:

[v.set_syntax_file("Packages/User/PythonImproved.tmLanguage") for w in sublime.windows() for v in w.views() if v.settings().get("syntax").startswith("Packages/Python/Python.")]
0 Likes