Coder Social home page Coder Social logo

magicstack / magicpython Goto Github PK

View Code? Open in Web Editor NEW
1.4K 39.0 91.0 1.94 MB

Cutting edge Python syntax highlighter for Sublime Text, Atom and Visual Studio Code. Used by GitHub to highlight your Python code!

License: MIT License

Makefile 0.10% Python 32.92% C++ 0.34% JavaScript 66.08% Reason 0.56%
syntax-highlighter python atom visual-studio-code sublime-text-3 python-3

magicpython's Introduction

Magic Python Build Status apm Package Control VSM

This is a package with preferences and syntax highlighter for cutting edge Python 3, although Python 2 is well supported, too. The syntax is compatible with Sublime Text, Atom and Visual Studio Code. It is meant to be a drop-in replacement for the default Python package.

Attention VSCode users: MagicPython is used as the default Python highlighter in Visual Studio Code. Don't install it unless you want or need the cutting edge version of it. You will likely see no difference because you're already using MagicPython.

MagicPython correctly highlights all Python 3 syntax features, including type annotations, f-strings and regular expressions. It is built from scratch for robustness with an extensive test suite.

Type hints in comments require support by the color scheme. The one used in the screenshot is Chromodynamics.

Installation Instructions

This is meant to be a drop-in replacement for the default Python package.

In Atom, install the MagicPython package and disable the built-in language-python package.

In Sublime Text, install MagicPython package via "Package Control" and disable the built-in Python package (using Package Control -> Disable Package, or directly by adding "Python" to "ignored_packages" in the settings file).

In VSCode, starting with version 0.10.1, install MagicPython with Install Extension command.

Alternatively, the package can be installed manually in all editors:

  • copy the MagicPython package into the Sublime/Atom/VSCode user packages directory;
  • disable Python package;
  • enjoy.

Changes and Improvements

The main motivation behind this package was the difficulty of using modern Python with other common syntax highlighters. They do a good job of the 90% of the language, but then fail on the nuances of some very useful, but often overlooked features. Function annotations tend to freak out the highlighters in various ways. Newly introduced keywords and magic methods are slow to be integrated. Another issue is string highlighting, where all raw strings are often assumed to be regular expressions or special markup used by .format is completely ignored. Bumping into all of these issues on daily basis eventually led to the creation of this package.

Overall, the central idea is that it should be easy to notice something odd or special about the code. Odd or special doesn't necessarily mean incorrect, but certainly worth the explicit attention.

Annotations

Annotations should not break the highlighting. They should be no more difficult to read at a glance than other code or comments.

A typical case is having a string annotation that spans several lines by using implicit string concatenation. Multi-line strings are suboptimal for use in annotations as it may be highly undesirable to have odd indentation and extra whitespace in the annotation string. Of course, there is no problem using line continuation or even having comments mixed in with implicit string concatenation. All of these will be highlighted as you'd expect in any other place in the code.

def some_func(a,                        # nothing fancy here, yet

              b: 'Annotation: '         # implicitly
                 '"foo" for Foo, '      # concatenated
                 '"bar" for Bar, '      # annotation
                 '"other" otherwise'='otherwise'):

A more advanced use case for annotations is to actually have complex expressions in them, such as lambda functions, tuples, lists, dicts, sets, comprehensions. Admittedly, all of these might be less frequently used, but when they are, you can rely on them being highlighted normally in all their glorious details.

# no reason why this should cause the highlighter to break
#
def some_func(a:
                 # annotation starts here
                 lambda x=None:
                    {key: val
                        for key, val in
                            (x if x is not None else [])
                    }
                    # annotation ends here and below is the default for 'a'
                    =42):

Result annotations are handled as any other expression would be. No reason to worry that the body of the function would look messed up.

# no reason why this should cause the highlighter to break
#
def some_func() -> {
                     'Some',        # comments
                     'valid',       # are
                     'expression'   # good
                   }:

Strings

Strings are used in many different ways for processing and presenting data. Making the highlighter more friendly towards these uses can help you concentrate your efforts on what matters rather than visual parsing.

Raw strings are often interpreted as regular expressions. This is a bit of a problem, because depending on the application this may actually not be the most common case. Raw strings can simply be the input to some other processor, in which case regexp-specific highlighting is really hindering the overall readability. MagicPython follows a convention that a lower-case r prefix means a regexp string, but an upper-case R prefix means just a raw string with no special regexp semantics. This convention holds true for all of the legal combinations of prefixes. As always the syntax is biased towards Python 3, thus it will mark Python-2-only prefixes (i.e. variations of ur) as deprecated.

String formatting is often only supported for '%-style formatting', however, the recommended and more readable syntax used by .format is ignored. The benefits of using simple and readable {key} replacement fields are hindered by the fact that in a complex or long string expression it may not be easily apparent what parameters will actually be needed by .format. This is why MagicPython highlights both kinds of string formatting syntax within the appropriate string types (bytes don't have a .format method in Python 3, so they don't get the special highlighting for it, raw and unicode strings do). Additionally, the highlighter also validates that the formatting is following the correct syntax. It can help noticing an error in complex formatting expressions early.

Python 3.6 f-strings are supported in both the raw and regular flavors. The support for them is somewhat more powerful than what can be done in regular strings with .format, because the f-string spec allows to highlight them with less ambiguity.

Numeric literals

Most numbers are just regular decimal constants, but any time that octal, binary, hexadecimal or complex numbers are used it's worth noting that they are of a special type. Highlighting of Python 2 'L' integers is also supported.

Underscores in numeric literals are also supported (PEP 515, introduced in Python 3.6):

100_000_000_000         0b_1110_0101        0x_FF_12_A0_99

Python 3.5 features

New keywords async and await are properly highlighted. Currently, these keywords are new and are not yet reserved, so the Python interpreter will allow using them as variable names. However, async and await are not recommended to be used as variable, class, function or module names. Introduced by PEP 492 in Python 3.5, they will become proper keywords in Python 3.7. It is very important that the highlighter shows their proper status when they are used as function parameter names, as that could otherwise be unnoticed and lead to very messy debugging down the road.

Built-ins and Magic Methods

Various built-in types, classes, functions, as well as magic methods are all highlighted. Specifically, they are highlighted when they appear as names in user definitions. Although it is not an error to have classes and functions that mask the built-ins, it is certainly worth drawing attention to, so that masking becomes a deliberate rather than accidental act.

Highlighting built-ins in class inheritance list makes it slightly more obvious where standard classes are extended. It is also easier to notice some typos (have you ever typed Excepiton?) a little earlier.

Parameters and Arguments

MagicPython highlights keywords when they are used as parameter/argument names. This was mentioned for the case of async and await, but it holds true for all other keywords. Although the Python interpreter will produce an appropriate error message when reserved keywords are used as identifier names, it's still worth showing them early, to spare even this small debugging effort.

Development

You need npm and node.js to work on MagicPython.

  • clone the repository
  • run make to build the local development environment
  • run make release to build the syntax packages for Sublime Text and Atom (running make test also generates the "release" packages)

Please note that we have some unit tests for the syntax scoping. We will be expanding and updating our test corpus. This allows us to trust that tiny inconsistencies will not easily creep in as we update the syntax and fix bugs. Use make test to run the tests regularly while updating the syntax spec. Currently the test files have two parts to them, separated by 3 empty newlines: the code to be scoped and the spec that the result must match.

If you intend to submit a pull request, please follow the following guidelines:

  • keep code lines under 80 characters in length, it improves readability

  • please do use multi-line regular expressions for any non-trivial cases like:

    • the regexp contains a mix of escaped and unescaped braces/parentheses
    • the regexp has several | in it
    • the regexp has several pairs of parentheses, especially nested ones
    • or the regexp is simply longer than 35 characters
  • always run make test to ensure that your changes didn't have unexpected side effects

  • update unit tests and add new ones if needed, keeping the test cases short whenever possible

Multiple scopes

It is sometimes necessary to assign multiple scopes to the same matched group. It is very important to keep in mind that the order of these scopes is apparently treated as significant by the engines processing the grammar specs. However, it is equally important to know that different specification formats seem to have different order of importance (most important first vs. last). Since we try to create grammar that can be compiled into several different formats, we must chose one convention and then translate it when necessary during compilation step. Our convention is therefore that most important scope goes first.

Color Scheme

If you want to write your own color scheme for MagicPython you can find a list of all the scopes that we use in misc/scopes. The file is automatically generated based on the syntax grammar, so it is always up-to-date and exhaustive.

magicpython's People

Contributors

1st1 avatar abusalimov avatar asottile avatar brettcannon avatar chbk avatar donjayamanne avatar elprans avatar goi42 avatar nicktimko avatar nullie avatar pchaigno avatar tennyson-mccalla avatar therumbler avatar vpetrovykh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magicpython's Issues

Unsaved file cannot set syntax to python

After disable built-in python package, the View>Syntax>Python option is also gone.Thus I can't set python syntax for a new created file which is not saved.
Would you consider adding an syntax setting entry in that place?

"super()" formatting

The super() statement seems seems not be distinguished from other functions and has blue parens. This could be better.
See the screenshots (Sublime Text, tomorrow night eighties theme)

  1. MagicPython

bildschirmfoto 2015-10-20 um 16 23 20

  1. Default Python3 highlighter

bildschirmfoto 2015-10-20 um 16 24 49

Tab size mangling

I've set my tab_size to 3 in ~/Library/Application Support/Sublime Text 3/Packages/User/Preferences.sublime-settings, however MagicPython seems to ignore that setting. Why is that, and how can I get my tab_size back?

Equals operator (==) incorrectly tokenized to two consecutive assignments

I encountered an issue with tokenizing the equals operator, ==, which gets tokenized as two consecutive assignment operations due to the latter getting precedence. The effect can be seen when using a font containing programming ligatures (such as Fira Code) where the equals operator fails to render correctly.

dokai@d7cdae9 contains a test case which demonstrates the issue and fails accordingly.

  • Editor name and version: Atom 1.7.3
  • Platform: OSX 10.11.4
  • Color scheme: Monokai Phoenix
  • MagicPython version: 0.5.9
  • A sreenshot:
    2016-05-17 02 17 01 pm

VIM support

Hi,
My question is regarding vim support. Have you ever planned to do this?

MagicPython errs occasionally when opening ST3

Here's an image. The graphical bug is because the theme is being reloaded.
Here's a log.

DPI scale: 1
startup, version: 3083 linux x64 channel: stable
executable: /opt/sublime_text_3/sublime_text
working dir: /
packages path: /home/txtsd/.config/sublime-text-3/Packages
state path: /home/txtsd/.config/sublime-text-3/Local
zip path: /opt/sublime_text_3/Packages
zip path: /home/txtsd/.config/sublime-text-3/Installed Packages
ignored_packages: ["Arduino-like IDE", "Colorcoder", "Djaneiro", "Emmet", "GoSublime", "isort", "nginx", "Perv - Color Scheme", "Python", "SublimeLinter", "SublimeLinter-javac", "Theme - Nexus", "Trimmer", "Vintage"]
pre session restore time: 2.68182
startup time: 3.18831
first paint time: 3.45688
reloading plugin Default.block
reloading plugin Default.comment
reloading plugin Default.copy_path
reloading plugin Default.delete_word
reloading plugin Default.detect_indentation
reloading plugin Default.duplicate_line
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.indentation
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_file_settings
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.quick_panel
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.swap_line
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.trim_trailing_white_space
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin 0_package_control_loader.00-package_control
reloading plugin 0_package_control_loader.01-ssl-linux
Package Control: Linux SSL: successfully loaded _ssl module for libssl.so.1.0.0
reloading plugin 0_package_control_loader.02-bz2
reloading plugin ColorPicker.sublimecp
reloading plugin FileDiffs.file_diffs
reloading plugin Git.add
reloading plugin Git.annotate
reloading plugin Git.commit
reloading plugin Git.diff
reloading plugin Git.flow
reloading plugin Git.git
reloading plugin Git.history
reloading plugin Git.repo
reloading plugin Git.stash
reloading plugin Git.status
reloading plugin Git.statusbar
reloading plugin HTML5.encode_html_entities
reloading plugin HTML5.html_completions
reloading plugin PKGBUILD.pkgbuildCommands
reloading plugin Package Control.1_reloader
reloading plugin Package Control.2_bootstrap
reloading plugin Package Control.Package Control
reloading plugin SideBarEnhancements.SideBar
reloading plugin SideBarEnhancements.SideBarAPI
reloading plugin SideBarEnhancements.SideBarDefaultDisable
reloading plugin Anaconda.anaconda
reloading plugin Anaconda.version
plugins loaded
Package Control: Installing 2 upgrades
ignored packages updated to: ["Arduino-like IDE", "Colorcoder", "Djaneiro", "Emmet", "GoSublime", "isort", "MagicPython", "nginx", "Perv - Color Scheme", "Python", "Seti_UI", "SublimeLinter", "SublimeLinter-javac", "Theme - Nexus", "Trimmer", "Vintage"]
error: Error loading syntax file "Packages/XML/XML.tmLanguage": Unable to open Packages/MagicPython/grammars/MagicPython.tmLanguage
reloading Packages/MagicPython/settings/sublime/MagicPython.sublime-settings
generating syntax summary
generating meta info summary
reloading Packages/Seti_UI/+res/Ext/CSS.sublime-settings
reloading Packages/Seti_UI/+res/Ext/HTML (Rails).sublime-settings
reloading Packages/Seti_UI/+res/Ext/HTML.sublime-settings
reloading Packages/Seti_UI/+res/Ext/Plain text.sublime-settings
reloading Packages/Seti_UI/+res/Ext/Ruby Haml.sublime-settings
reloading Packages/Seti_UI/+res/Ext/Ruby.sublime-settings
reloading Packages/Seti_UI/+res/Ext/SCSS.sublime-settings
reloading Packages/Seti_UI/+res/Ext/Sass.sublime-settings
reloading Packages/Seti_UI/Main/Widget - Seti_orig.sublime-settings
generating syntax summary
generating meta info summary
reloading Packages/User/Package Control.sublime-settings
reloading Packages/User/Preferences.sublime-settings
Package Control: Upgraded MagicPython to 0.4.44
ignored packages updated to: ["Arduino-like IDE", "Colorcoder", "Djaneiro", "Emmet", "GoSublime", "isort", "nginx", "Perv - Color Scheme", "Python", "Seti_UI", "SublimeLinter", "SublimeLinter-javac", "Theme - Nexus", "Trimmer", "Vintage"]
reloading Packages/MagicPython/settings/sublime/MagicPython.sublime-settings
generating syntax summary
generating meta info summary
reloading Packages/User/Package Control.sublime-settings
reloading Packages/User/Preferences.sublime-settings
reloading Packages/User/Preferences.sublime-settings
Package Control: Upgraded Seti_UI to 2015.11.06.16.14.56
ignored packages updated to: ["Arduino-like IDE", "Colorcoder", "Djaneiro", "Emmet", "GoSublime", "isort", "nginx", "Perv - Color Scheme", "Python", "SublimeLinter", "SublimeLinter-javac", "Theme - Nexus", "Trimmer", "Vintage"]
generating syntax summary
reloading Packages/Seti_UI/Main/Widget - Seti_orig.sublime-settings
generating meta info summary
reloading Packages/Seti_UI/+res/Ext/CSS.sublime-settings
reloading Packages/Seti_UI/+res/Ext/HTML (Rails).sublime-settings
reloading Packages/Seti_UI/+res/Ext/HTML.sublime-settings
reloading Packages/Seti_UI/+res/Ext/Plain text.sublime-settings
reloading Packages/Seti_UI/+res/Ext/Ruby Haml.sublime-settings
reloading Packages/Seti_UI/+res/Ext/Ruby.sublime-settings
reloading Packages/Seti_UI/+res/Ext/SCSS.sublime-settings
reloading Packages/Seti_UI/+res/Ext/Sass.sublime-settings
reloading Packages/User/Package Control.sublime-settings
reloading Packages/User/Preferences.sublime-settings
reloading Packages/User/Preferences.sublime-settings
ERROR:root:[Errno 111] Connection refused
ERROR:root:Traceback (most recent call last):
  File "/home/txtsd/.config/sublime-text-3/Packages/Anaconda/anaconda_lib/worker.py", line 191, in start
    self.client = AsynClient(self.available_port)
  File "/home/txtsd/.config/sublime-text-3/Packages/Anaconda/anaconda_lib/jsonclient.py", line 36, in __init__
    EventHandler.__init__(self, (host, port))
  File "/home/txtsd/.config/sublime-text-3/Packages/Anaconda/anaconda_lib/ioloop.py", line 107, in __init__
    self.sock.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused

This is what it looks like when it doesn't break.

DPI scale: 1
startup, version: 3083 linux x64 channel: stable
executable: /opt/sublime_text_3/sublime_text
working dir: /
packages path: /home/txtsd/.config/sublime-text-3/Packages
state path: /home/txtsd/.config/sublime-text-3/Local
zip path: /opt/sublime_text_3/Packages
zip path: /home/txtsd/.config/sublime-text-3/Installed Packages
ignored_packages: ["Arduino-like IDE", "Colorcoder", "Djaneiro", "Emmet", "GoSublime", "isort", "nginx", "Perv - Color Scheme", "Python", "SublimeLinter", "SublimeLinter-javac", "Theme - Nexus", "Trimmer", "Vintage"]
pre session restore time: 0.42951
startup time: 0.734251
first paint time: 0.792481
reloading plugin Default.block
reloading plugin Default.comment
reloading plugin Default.copy_path
reloading plugin Default.delete_word
reloading plugin Default.detect_indentation
reloading plugin Default.duplicate_line
reloading plugin Default.echo
reloading plugin Default.exec
reloading plugin Default.fold
reloading plugin Default.font
reloading plugin Default.goto_line
reloading plugin Default.history_list
reloading plugin Default.indentation
reloading plugin Default.kill_ring
reloading plugin Default.mark
reloading plugin Default.new_templates
reloading plugin Default.open_context_url
reloading plugin Default.open_file_settings
reloading plugin Default.open_in_browser
reloading plugin Default.pane
reloading plugin Default.paragraph
reloading plugin Default.paste_from_history
reloading plugin Default.quick_panel
reloading plugin Default.save_on_focus_lost
reloading plugin Default.scroll
reloading plugin Default.set_unsaved_view_name
reloading plugin Default.side_bar
reloading plugin Default.sort
reloading plugin Default.swap_line
reloading plugin Default.switch_file
reloading plugin Default.symbol
reloading plugin Default.transform
reloading plugin Default.transpose
reloading plugin Default.trim_trailing_white_space
reloading plugin CSS.css_completions
reloading plugin Diff.diff
reloading plugin HTML.encode_html_entities
reloading plugin HTML.html_completions
reloading plugin 0_package_control_loader.00-package_control
reloading plugin 0_package_control_loader.01-ssl-linux
Package Control: Linux SSL: successfully loaded _ssl module for libssl.so.1.0.0
reloading plugin 0_package_control_loader.02-bz2
reloading plugin ColorPicker.sublimecp
reloading plugin FileDiffs.file_diffs
reloading plugin Git.add
reloading plugin Git.annotate
reloading plugin Git.commit
reloading plugin Git.diff
reloading plugin Git.flow
reloading plugin Git.git
reloading plugin Git.history
reloading plugin Git.repo
reloading plugin Git.stash
reloading plugin Git.status
reloading plugin Git.statusbar
reloading plugin HTML5.encode_html_entities
reloading plugin HTML5.html_completions
reloading plugin PKGBUILD.pkgbuildCommands
reloading plugin Package Control.1_reloader
reloading plugin Package Control.2_bootstrap
reloading plugin Package Control.Package Control
reloading plugin SideBarEnhancements.SideBar
reloading plugin SideBarEnhancements.SideBarAPI
reloading plugin SideBarEnhancements.SideBarDefaultDisable
reloading plugin Anaconda.anaconda
reloading plugin Anaconda.version
plugins loaded
Package Control: Skipping automatic upgrade, last run at 2015-11-07 13:36:27, next run at 2015-11-07 14:36:27 or after

Incorrect highlight of decorator's opening parenthesis

I discovered that opening parenthesis in decorator highlighted with wrong color, in my case (I'm using Tomorrow Night color scheme) it highlighted with blue color, when closing parenthesis highlighted with white color

Screenshot for MagicPython decorator highlight

screen shot 2015-10-20 at 10 27 08 pm

Screenshot for regular Python decorator highlight

screen shot 2015-10-20 at 10 29 11 pm

No support for newline between function parameters and return type

  • Editor name and version: Atom 1.9.3
  • MagicPython version: MagicPython 0.5.13
  • A sreenshot:
    screen shot 2016-08-09 at 2 22 16 pm
  • 5-10 lines of surrounding code:
@util.timer
def get_streaks(s: sqlalchemy.orm.session.Session,
                active: Optional[bool]=None,
                sort_by_length: Optional[bool] = False,
                limit: Optional[int]=None,
                ) \
        -> Sequence[Streak]:

Python runs this code just fine, it seems MagicPython doesn't handle newline continuations in this space properly. Removing the \ has no effect on syntax highlighting.

Inconsistent variable highlighting?

OS X 10.11.2, Sublime Text 3113, Gravity theme, latest MagicPython.

Trying out MagicPython from PythonImproved. In the first Python file I opened, I see:

screen shot 2016-05-13 at 17 54 30

X_train and X_test are highlighted purple, but y_train and y_test are white. Capitalizing the Y vars turns them purple.

I'm assuming that any word starting with a capital is treated as a "constant" and colored accordingly. Is this intentional? Wouldn't checking for ALL_CAPS be better?

MagicPython doesn't work with VS Code under Windows 10

  • Editor name and version: Visual Studio Code 1.2.1
  • Platform: Windows 10
  • Color scheme: Default
  • MagicPython version: 0.5.11
  • A sreenshot:
    no magic
  • 5-10 lines of surrounding code:

I've had this issue for a while now, and it's slightly different in Windows 10 vs Linux Mint 17.3. In LM17.3 there's some coloring. For example def func(arg1, arg2): would have def as blue, func as yellow-ish, and the rest as white.

In any case, with Windows 10 the extension flat-out doesn't work as you can see in the screenshot.

Highlighting of SQL inside strings

The stock Python package performs syntax highlighting inside strings containing SQL commands. That's rather useful, even though the implementation might need some more work. In this example:

create = 'CREATE TABLE test (id INT, name TEXT);'
insert = 'INSERT INTO test VALUES (1, "Bob")'

in the second line, words recognized as SQL are highlighted, but not in the first one, where "CREATE TABLE" has the same color as the non-reserved names.

(Actually, as you can see, even Github's Markdown does it, with exactly the same behavior, so perhaps something is wrong with the first line, although it does execute properly)

Do you consider this a useful addition?

Build system is not working

Hi I used to be able to use ctrl+B to run python scripts in sublime. After switching to MagicPython, it is not working.

Scope triple single and triple double slightly different

According to PEP257 triple double quotes should be used as docstrings. Now I realize that not everyone may buy into this, but I generally use the triple double for my docstrings and triple single for regex etc. Then I usually style my docstrings as comments in my color scheme. It would be nice if MagicPython at least scoped triple single and triple double slightly different. Simply adding in a "single" or "double" specifier would be more than sufficient.

Extension-less Python files not picked up

Bit of a papercut, but...

If I have example, not no .py extension, as:

#!/usr/bin/env python

if __name__ == '__main__':
    print('python')

Then in Sublime Text 3, MagicPython isn't automatically selected. Without MagicPython enabled and Python disabled, the stock Python package is selected.

No kernal for language python found

Hello,

I have the same issue:

nteract/hydrogen#201

I disabled the default language-python and add MagicPython add {"MagicPython": "python"}
or {"MagicPython":"python3"}
to Language Mappings in the Hydrogen settings. However the kernel cant be found. With language-python enabled and MagicPython disabled it works.

magic

  • ATOM 1.7.3:
  • MAC OS X El Capitan 10.11.4:
  • MagicPython version 0.5.9:
  • *Hydrogen version 0.9.0 *:

Support PyCharm

Not a bug, but a feature request.

I use this on Sublime and it truly is magical, but I was wondering if this can somehow be integrated into PyCharm?

differences from PythonImproved [not a bug]

Since how MagicPython compares to PythonImproved is a frequently asked question, here we'll document some differences in highlighting.

PythonImproved is on the left, MagicPython is on the right.

screen shot 2015-10-19 at 7 38 28 pm

screen shot 2015-10-19 at 7 38 45 pm

screen shot 2015-10-19 at 8 20 17 pm

screen shot 2015-10-19 at 7 40 24 pm

screen shot 2015-10-19 at 7 56 49 pm

screen shot 2015-10-19 at 7 54 52 pm

screen shot 2015-10-19 at 7 55 49 pm

screen shot 2015-10-19 at 7 54 21 pm

screen shot 2015-10-19 at 7 53 25 pm

screen shot 2015-10-19 at 7 47 59 pm

screen shot 2015-10-19 at 7 46 43 pm

screen shot 2015-10-19 at 7 44 07 pm

screen shot 2015-10-19 at 7 43 31 pm

screen shot 2015-10-19 at 7 42 55 pm

screen shot 2015-10-19 at 7 41 54 pm

screen shot 2015-10-19 at 7 41 02 pm

Treat single-character capital names as class instead of constant

Currently, single-character words are highlighted like ALL_CAPS_NAMES, but in practice they are usually class names instead, such as Q and F objects in Django.

It might be better to change the highlighting rule of constants to require at least two characters instead. (Or even two uppercase characters because names like _N also look like a class. This might just be me though.)

Support for rST files and PEP257

Hi,
I wonder if anyone has considered support for rST files (I'm thinking particularly of the directives and labels often used when writing for Sphinx?
If I wanted to implement that, do you have any suggestions of the approach I should take?

Thanks!
-Blaise

Highlighting of pseudo-keyword "self"

The convention of having methods refer to their calling instances by the parameter name "self" is so commonly accepted that "self" should probably highlighted.

Suggestion: Improved PEP8 syntax

One thing an improved VIM syntax does is proper alignment of variables and parameters in functions. For example, entering the following sequence in VIM:

def f(a, b, c, <enter>d):<enter>pass

I get

def f(a, b, c,
      d):
    pass

On the other hand, if I do the same thing in Atom, I get

def f(a, b, c,
d):
pass

Also, the VIM syntax does this while typing, no need to call some "reparagraph" command.

It would be nice if such feature was available to Atom (and maybe Sublime, but since I'm using VIM and Atom... ;) )

Curly braces inside string constants, shown in wrong colour

Curly braces inside string constants, are shown in the colour of the constant scope.

  • Editor name and version: Sublime Text 3114
  • Platform: Linux Mint 17
  • Color scheme: My own based on Boxy Tomorrow.tmTheme but many colours altered, see this Gist.
  • MagicPython version: 0.5.15

Screen capture with syntax set to MagicPython:

st_magicpython_01

Screen capture with syntax set to PythonImproved (what I was using before MP):

st_magicpython_02

Hope this helps.

For your convenience the dictionary for the constant scope:

<dict>
    <key>name</key>
    <string>Constant</string>
    <key>scope</key>
    <string>constant, constant.language, support.constant, constant.character, constant.character.escape, constant.other, constant.other.color, constant.other.symbol, constant.other.key</string>
    <key>settings</key>
    <dict>
        <key>foreground</key>
        <string>#EE1B2D</string>
        <!-- <string>#b5bd68</string> -->
    </dict>
</dict>

MagicPython overrides color scheme

ST3, 3114
win 10
customized Monokai
MP: 0.5.15

I'm trying to customize the display of classnames. Here is the piece from my .tmTheme file:

        <dict>
            <key>name</key>
            <string>Class name</string>
            <key>scope</key>
            <string>entity.name.class,  entity.name.type.class.python</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string>underline  bold</string>
                <key>foreground</key>
                <string>#7D8BFA</string>
            </dict>

When I open the file, the class name is briefly styled like I want - then it's overridden, and changes to the default text color.

Class names work in Matlab and C++ files I work in. I think this is a magicPython issue, but I'm not sure.

Any ideas?

Include Magic Pythons tmLanguage directly into VS Code

  • Editor name and version: VS Code
  • Platform: All
  • MagicPython version: Latest

I'm looking at improving the (out of the box) syntax highlighting for python in Visual Studio Code. Currently VS Code is using the tmLanguage file from TextMate's Python bundle. However the tmLanguage file provided by Magic Python seems to be far better.

Do you have any concerns with me trying to include the tmLanguage file from Magic python directly into VS Code?

how to enable sublimeLinter with magicPython?

  • Editor name and version: SublimeText 2
  • Platform: Linux
  • Color scheme: Dawn
  • MagicPython version: latest stable
  • A sreenshot: none
  • 5-10 lines of surrounding code: any

In sublimeText2 python files use 'MagicPython' (ofcourse if magicPython installed) as syntax scheme. But sublimeLinter wait for 'Python' syntax scheme. How to solve this?

Unicode character "ı" causes hangs

I'm using 0.5.7 on dv 3099 build of sublime text. With this build, a string ending with mı, rı, ğı etc causes mp and eventually sublime text to become unresponsive. It does happen all the time with the given and a couple more similar strings but interestingly, not for all the strings that end in ı.

For example: strings ending with gı, nı, hı, şı etc do not cause any problems. With MP disabled, sublime text does not hang or freeze.

MagicPython is incompatible with SublimeLinter

I tried this today and I noticed that SublimeLinter won't work if I use MagicPython. I'm guessing it has something to do with "Python" being a disabled package and it might well be a SublimeLinter bug.

I still thought I report it here. Maybe this is a known issue with a known workaround? :)

Incorrect highlighting when using new-style string formatting and a % sign.

Hi, I have just installed MagicPython in Sublime Text 3 and already love it. I have noticed a small inconsistency in the highlighting of strings like these

print('This happens {:.02f}% of the times'.format(percent))

See the result below:
screen shot 2015-10-20 at 12 20 25

In this case, of course, the % sign is not part of the formatting, just like the space and the following o.

Built-in names in class scope should not be highlighted

Currently built-in names are highlighted in definitions, even when they are inside a class scope:

class SomeClass:

    id = models.AutoField(...)   # Common in Django.

    def open(self):    # Also quite common. pathlib.Path.open is an example.
        pass

    class Exception:   # Less common, but possible.
        pass

I read the Built-ins and Magic Methods section in README, but am still not sure whether this is intentional. I can’t think of a case in which they can shadow built-in global names.

Not all arguments highlighted inside of parentheses

I also discovered that not all arguments highlighted inside of parentheses if comparing with standard Python highlighter

MagicPython

screen shot 2015-10-20 at 11 19 49 pm

Standard Python

screen shot 2015-10-20 at 11 19 07 pm

Or this is not a bug, but feature? As constants like settings.SETTING_NAME also not highlighted by MagicPython

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.