magicstack / magicpython Goto Github PK
View Code? Open in Web Editor NEWCutting edge Python syntax highlighter for Sublime Text, Atom and Visual Studio Code. Used by GitHub to highlight your Python code!
License: MIT License
Cutting edge Python syntax highlighter for Sublime Text, Atom and Visual Studio Code. Used by GitHub to highlight your Python code!
License: MIT License
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:
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?
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?
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.
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?
In Sublime3 xrange
is not highlighted is that a bug or a feature?
I'm still using Python 2
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?
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.
PythonImproved allows for highlighting of the function name (the word just before the open parenthesis in a function call, not including .
). See lines 9 and 23 in the screenshot below.
The relevant tmLanguage syntax is here.
the print keyword isn't highlighted if it is followed by a list:
print [1, 2, 3]
Python 2.7 only ofc.
_Edit 20.10.15:_
same goes for the unicode
keyword in general.
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.
Hello,
I have the same issue:
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.
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.)
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.
Hi I used to be able to use ctrl+B to run python scripts in sublime. After switching to MagicPython, it is not working.
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?
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))
In this case, of course, the % sign is not part of the formatting, just like the space and the following o.
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.
The convention of having methods refer to their calling instances by the parameter name "self" is so commonly accepted that "self" should probably highlighted.
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... ;) )
R'\frac{m_{j \rightarrow i}(\mathrm{good})}'
This is illegal nesting of braces for a format string.
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
Screenshot for regular Python decorator highlight
I just stumbled upon this while wondering why the punctuation in typehint commets didn't work in my color scheme.
I have an import statement
import xml.etree.ElementTree as ET
ET
is highlighted as if it was defined as a constant like ET = 1
.
Is it possible to fix this with the current capabilities of ST and it's syntax language?
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?
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.
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
Hi,
My question is regarding vim support. Have you ever planned to do this?
In sublimeText2 python files use 'MagicPython' (ofcourse if magicPython installed) as syntax scheme. But sublimeLinter wait for 'Python' syntax scheme. How to solve this?
@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.
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
How can I point magicPython to a specific virtualenv in ST3?
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? :)
Curly braces inside string constants, are shown in the colour of the constant
scope.
Boxy Tomorrow.tmTheme
but many colours altered, see this Gist.Screen capture with syntax set to MagicPython:
Screen capture with syntax set to PythonImproved (what I was using before MP):
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>
Atom has a package, linter-flake8, that among other things will highlight unnecessary imports. With the standard Atom Python syntax highlighting, this works correctly. With the MagicPython syntax highlighting, the lint error always points at the end of the document.
Derived from #10.
For example the unicode
keyword.
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?
Eg matplotlib
's labels:
ax1.set(ylabel=R'$\frac{m_{j \rightarrow i}(\mathrm{good})}{\sum{m_{j \rightarrow i}}}$')
Maybe look for $-surrounded strings and apply TeX to them?
Noticed some inaccuracies in the Python raw strings in Atom. Not sure if they exist in Sublime. The links above the images will take you to the file for more context.
Looks like they're failing at the first apostrophe after a raw string.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.