Skip to content

The best Python language definition for Sublime Text - ever. Includes full support for Unicode, as well as both Python 2 and Python 3 syntax. Check out the Neon Color Scheme for highlighting.

License

Notifications You must be signed in to change notification settings

MattDMo/PythonImproved

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PythonImproved

A better Python .tmLanguage syntax highlighting definition for Sublime Text and TextMate. Inspired by:

as well as a number of my own changes to make things more consistent and understandable. For customized syntax highlighting taking advantage of all the new scopes, use PythonImproved with the Neon Color Scheme, or modify your own favorite theme with the scopes below.

Installation and Use

If you haven't already, install Package Control, then select Python Improved from the Package Control: Install Package option in the Command Palette. To use PythonImproved as your default Python syntax, open a .py file, then select View -> Syntax -> Open all with current extension as... -> PythonImproved.

While I haven't yet tried to install PythonImproved with TextMate, I can't think of a good reason as to why it wouldn't work. You could try putting it in the same directory as the standard Python.tmbundle package, in the Syntaxes subdirectory. Then, just pick PythonImproved from the syntax menu.

New/Changed Scopes

If you prefer to modify your own color scheme, here is a list of new/modified scopes, along with some examples. It's not perfectly complete, but it's a start.

  • support.ipython.in and support.ipython.out: IPython In [1]:/Out [1]: fields — designed for use with SublimeREPL
  • Django-specific:
    • support.type.django.model: (meta|models). DecimalField, EmailField, ForeignKey, ManyToManyField, etc.
    • support.other.django.module: django, django.contrib, etc.
    • variable.other.django.settings: settings.py options like ADMINS, DATABASES, INSTALLED_APPS, MIDDLEWARE_CLASSES, etc. Should be complete as of Django 1.6.
    • support.function.django.view: view functions get_list_or_404, get_object_or_404, load_and_render, loader, render_to_response, render
    • support.function.django.model: model functions get_object, get_list, get_count, etc.
  • constant.numeric.integer.(long).binary.python: binary literals 0b00101010, 0b00101010L
  • keyword.control.import.python now contains import, from, and as
  • keyword.other.python now only contains assertas, del, exec, and print have been relocated
  • support.type.exception.python now matches any identifier that ends with Exception or Error, not just the built-in ones like IndentationError or RuntimeException, allowing for the highlighting of custom exceptions such as those included in third-party modules
  • Miscellaneous changes to support.function.builtin.python and support.type.python — a lot of personal judgement went in to deciding which word went where (for example, list is a built-in function, but it's also a type, so I put it in type), so if you have a good reason for disagreeing please tell me.
  • Function annotation support for Python 3, thanks to @facelessuser. New scopes added: punctuation.separator.annotation.python, punctuation.separator.annotation.result.python, punctuation.definition.parameters-group.begin.python, and punctuation.definition.parameters-group.end.python.
  • You can now have comments in multi-line function definitions:
def myfunc(self,            # gotta have self
           param1="value",  # values are cool
           param2=True,     # or False, whatever
           **kwargs):       # you never know

Multi-line comments and function annotations

  • New scopes for bytes, unicode, and raw/regex strings, thanks to @simonzack: string.quoted.(single|double).(block|single-line).(bytes|bytes-raw|bytes-raw-regex).python
  • Also from @simonzack, highlighting of self|cls in parameter strings: variable.parameter.function.(keyword|language)
  • comment.line.note.python is a comment line that contains (BUG|FIXME|TODO|XXX) at the beginning. comment.line.note.notation.python matches the actual word itself, so you can differentially highlight the word and the whole line:

BUG FIXME TODO XXX line highlighting

Issues

If you have questions, concerns, or suggested improvements, I'd love to hear from you! Feel free to open an issue or send a pull request and I'll get back to you as soon as I can. You can also email me at mattdmo@pigimal.com.

License

© 2013-2014 Matt Morrison mattdmo@pigimal.com.

This is free software. It is licensed under the Creative Commons Attribution-ShareAlike 4.0 International Public License. Feel free to use this in your own work. However, if you modify and/or redistribute it, please attribute me in some way, and distribute your work under this or a similar license. A shout-out or a beer would be appreciated.

Creative Commons License

You can also [give on Gittip](https://www.gittip.com/on/github/MattDMo/).

About

The best Python language definition for Sublime Text - ever. Includes full support for Unicode, as well as both Python 2 and Python 3 syntax. Check out the Neon Color Scheme for highlighting.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 6

Languages