Home Download Buy Blog Forum Support

Python Improved - a better Python language definition

Python Improved - a better Python language definition

Postby MattDMo on Wed Oct 23, 2013 12:11 am

OK, so technically this is a language definition and not a plugin, but I figured I'd post it here anyways. Python Improved has (finally) been released on Package Control for all the world to use. Basically, I started out with the default Python.tmLanguage files from ST2 and TextMate, and ironed out a few minor (if I recall) differences between them, and started making some improvements, like having any *Exception or *Error highlighted, instead of just the predefined ones, and clarifying the difference between a "builtin function" (like open() or isinstance()) and a "builtin type" (like "ascii" or "bytearray"), even though many of them are also functions. I'm also a huge fan of @wuub's SublimeREPL and its IPython integration, so I added scopes to highlight the "In [#]/Out [#]" line markers.

At some point I discovered @facelessuser's Better Python and adapted many ideas from there. I then started playing with Django and installed Djaneiro, but wasn't completely happy with it, so I cannabalized the parts I liked most and added them to what I was now calling "PythonImproved". The project kind of languished for a while, but the success I've had with my Neon Color Scheme, which contains syntax highlighting for all of the new scopes in PythonImproved, I decided to clean it up, put together a README, and submit it to Package Control, and here we are.

Issues:
None that I'm really aware of, having been using it and tweaking it for most of the past year, but there is one thing I'd like to ask for help on: I haven't put an extensive amount of work into it, but I'd love to support Python 3's function annotations, even just the straightforward ":" and "->" operators, perhaps with a specialized scope for the word that comes after:
Code: Select all
def greet(name: str, age: int) -> str:
    print('Hello {0}, you are {1} years old'.format(name, age))
# instead of the standard
def greet(name, age):
    print(...)


So, if you're an expert regexer and want to contribute, head over to GitHub and open a pull request. Otherwise, if you have any other questions, concerns, implementation problems, whatever, feel free to open an issue and I'll get back to you as soon as I can.

This will go into the README soon, but if you love Python Improved so much you want to make it your default Python language definition, do the following (in ST2):
1. Copy "Packages/Python Improved/PythonImproved.tmLanguage" to some other location in your filesystem, not under the Sublime Text hierarchy.
2. Open PythonImproved.tmLanguage in ST2.
3. Change the contents of the <string> key on line 44 to "Python"
4. Save the file as "Python.tmLanguage"
5. Quit ST2.
6. From your OS/command line, rename "Packages/Python/Python.tmLanguage" to "Python.tmLanguage.backup" or something similar, just in case.
7. Delete "Packages/Python/Python.tmLanguage.cache"
8. Copy the newly edited and renamed Python.tmLanguage from its other location to "Packages/Python"
9. Restart ST2.
10. ???
11. Profit!
(sorry, couldn't help myself)

So, I hope you enjoy it, and if you have any questions just let me know!

MattDMo
MattDMo
 
Posts: 36
Joined: Thu Jan 17, 2013 3:15 am
Location: near Boston

Re: Python Improved - a better Python language definition

Postby chid on Sun Oct 27, 2013 10:01 am

Will this support ST3?
chid
 
Posts: 4
Joined: Wed Jul 04, 2012 2:51 am

Re: Python Improved - a better Python language definition

Postby iamntz on Sun Oct 27, 2013 10:49 am

@chid: considering that is only language file, it should work just fine.
iamntz
 
Posts: 896
Joined: Fri Apr 29, 2011 8:52 am
Location: Romania

Re: Python Improved - a better Python language definition

Postby facelessuser on Sun Oct 27, 2013 4:54 pm

I will have to check this out :).
facelessuser
 
Posts: 1541
Joined: Tue Apr 05, 2011 7:38 pm

Re: Python Improved - a better Python language definition

Postby skuroda on Sun Oct 27, 2013 8:05 pm

Don't know if you have an ongoing list of added scopes, but if you do, it might be worth including those in the README. That way people can customize their own color scheme rather than relying only on your Neon theme.
skuroda
 
Posts: 676
Joined: Fri Oct 05, 2012 8:11 am

Re: Python Improved - a better Python language definition

Postby MattDMo on Mon Oct 28, 2013 4:33 pm

skuroda wrote:Don't know if you have an ongoing list of added scopes, but if you do, it might be worth including those in the README.

It's definitely on my list of things to do, I've just been very busy with work and family life the past several days.

That way people can customize their own color scheme rather than relying only on your Neon theme.

What, one theme doesn't work for every single person? I'm shocked! :o
MattDMo
 
Posts: 36
Joined: Thu Jan 17, 2013 3:15 am
Location: near Boston

Re: Python Improved - a better Python language definition

Postby FichteFoll on Tue Oct 29, 2013 5:48 pm

In the year(s) of using ST with Python I also experienced some things that the syntax file did not cover. Maybe some of it hasn't been fixed yet by you (didn't check myself):

- `next` keyword (Py3)
- `__bool__` function (Py3)
- `0b100101` numeric literal notation
- When splitting a `def` function definition into multiple lines, comments are not recognized

You might want to consider monitoring https://github.com/SublimeText/Issues/i ... state=open ;)
FichteFoll
 
Posts: 376
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: Python Improved - a better Python language definition

Postby MattDMo on Fri Nov 01, 2013 10:05 pm

@FichteFoll:
  • `next` is included in "support.function.builtin.python" - it's possible your current color scheme doesn't highlight that scope properly.
  • I just added `__bool__`, so next time you update it should be there.
  • PythonImproved does include support for binary literals, both regular ('0b01100101') and long ('0b01100101L')
  • I also just added support for comments within function definitions:
    Code: Select all
    def myfunc(self,            # gotta have self
               param1="value",  # values are cool
               param2=True,     # or False, whatever
               **kwargs):       # you never know
@skuroda:
I've put a list of new/modified scopes in the README. I think I got most of the major ones, but I did leave out some minor housekeeping, regex tuning, and whatnot.

As always, if something doesn't look quite right, or you have any feedback at all, please let me know!
MattDMo
 
Posts: 36
Joined: Thu Jan 17, 2013 3:15 am
Location: near Boston

Re: Python Improved - a better Python language definition

Postby facelessuser on Fri Nov 01, 2013 11:06 pm

Edit:

@MattDMo I decided to go ahead and give your language a try. I think I can probably help you with the Python 3's function annotations. I like what you are doing with this.
facelessuser
 
Posts: 1541
Joined: Tue Apr 05, 2011 7:38 pm

Re: Python Improved - a better Python language definition

Postby facelessuser on Fri Nov 01, 2013 11:31 pm

I see why you were struggling with those annotations. They are flexible enough to make things a pain. I'll take a crack at it. It may be one of those things that will require multiple iterations over it before everything is 100% covered (or near 100% covered), but if a couple initial passes can bring it up cleanly greater than the current 0%, it will be an improvement.
facelessuser
 
Posts: 1541
Joined: Tue Apr 05, 2011 7:38 pm

Next

Return to Plugin Announcements

Who is online

Users browsing this forum: Yahoo [Bot] and 11 guests