GithubHelp home page GithubHelp logo

hdima / python-syntax Goto Github PK

View Code? Open in Web Editor NEW
365.0 365.0 110.0 442 KB

Python syntax highlighting script for Vim

Home Page: http://www.vim.org/scripts/script.php?script_id=790

License: MIT License

Vim Script 90.55% Python 9.45%

python-syntax's People

Contributors

achimnol avatar anntzer avatar graywh avatar hdima avatar iho avatar mcsalgado avatar yuriihabrusiev 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

python-syntax's Issues

""" or ''' as comments

how to mark starting and ending strings with """ or ''' as comment

currently as a workaround I added the following to the .vim/after/syntax/python.vim file

syn region Comment start=/"""/ end=/"""/
syn region Comment start=/'''/ end=/'''/

folding

How to use the folding file in folding-ideas folder?

"{{" not recognized as an escape

"{{" (and likewise with closing braces) are highlighted as if they were introducing formatting elements though they are actually escapes.

dictionary comprehensions

I don't believe this syntax is supported in your python.vim, is it?

{x:y for x,y in [(1,2), (3,4)]}

Highlight self

self is the standard keyword for self-reference in Python OO. I suggest that we link it to special.

I tried to find prior discussion about this since I felt that this kinda had to be discussed before, but I found nothing. Apologies if that was the case!

Python 3.6 f-string literal support

Python 3.6 has reached its last beta where its features are frozen now.
It introduces a new syntactic element: f-string literals.
https://docs.python.org/3.6/whatsnew/3.6.html#whatsnew36-pep498

In f-string literals, the content inside braces are treated as real Python expressions with optional format string after a colon character like in format() protocol. The expression expansion may be done inside the format string as well though. (See the examples in the above link.)

Let's add support for this.

async / await not highlighted

Highlighting for async and await definitions. I added the python.vim file to the syntax folder on .vim. Still can't get it to highlight this as Language keywords

g:python_version_2=1 overrides b:python_version_2=0

You should re-think how you select between the two Python syntax versions. The current method allows setting g:python_version_2=0 globally for python3 and lets buffers set b:python_version_2=1 for python2. But it doesn't allow setting g:python_version_2=1 to ensure python2 is the default and setting b:python_version_2=0 to get python3 for a single buffer.

vim's default pyrex.vim requires a pythonInclude group

Like it or not, the pyrex syntax file shipped with vim7.4 (extension .pyx) forcefully loads the python syntax file and clears the pythonInclude group, leading to an error with this python syntax file as it does not define pythonInclude anymore.
I would thus suggest providing an empty pythonInclude group to avoid this issue.

How to enable folding ?

Is there a preferred way to use proper folding with python-syntax ?

By "proper folding" I mean not a trivial folding solely indent based but a more decent one based on def, class and # {{{ }}} markers declarations.

I tried to use Python-Syntax-Folding and braceless.vim but none seems to be compatible with python-syntax.

The indent mode of Python-Syntax-Folding suits my needs but lacks python 3 syntax.

The identifier next to "async def" is not highlighted as function name

..and the fix is:

diff --git a/syntax/python.vim b/syntax/python.vim
index e461241..4ad66b3 100644
--- a/syntax/python.vim
+++ b/syntax/python.vim
@@ -176,7 +176,7 @@ else
   syn keyword pythonBoolean     True False
   syn match   pythonFunction    "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
   syn keyword pythonStatement   await
-  syn match   pythonStatement   "\<async\s\+def\>" display
+  syn match   pythonStatement   "\<async\s\+def\>" nextgroup=pythonFunction skipwhite
   syn match   pythonStatement   "\<async\s\+with\>" display
   syn match   pythonStatement   "\<async\s\+for\>" display
   syn match   pythonStatement   "\<async\s\+with\>" display```

Suggestion: Option to set pythonRun and pythonCoding as Comment

To me, the Special highlighting should be for things that stand out, so it shouldn't be used for large blocks like the shebang and coding header.

It would be nice if this could be an option that determines whether pythonRun and pythonCoding are linked to Special or Comment.

Is there an option can close the warning/error about coding style

Such as:
4 error| W0611 "sys" imported but unused [pyflakes
18 col 6 error| E225 missing whitespace around operator [pep8
34 col 6 error| E231 missing whitespace after "," [pep8
114 col 5 error| E303 too many blank lines (3) [pep8
141 col 1 warning| W391 blank line at end of file [pep8

Unclear license of python-syntax

Hello.

I am really enjoying your work to the point I would like to add a Gentoo ebuild for it into my overlay so other people can grab it and update with ease. Gentoo ebuild writing policy requires each package to have a license. I was unable to find any mention of this project's license. Can you please tell me what it is?

Thanks.

Unmatched/unbalanced parenthesis/brackets/etc

Would be nice if you could add highlight error for unmatched and unbalanced parenthesis/square brackets/curly braces/etc. For example, marking everything after (to the end of the file) an unclosed parenthesis in a function definition, to be highlighted with red background, or everything before (to the beginning of the file) an additional closing bracket without a corresponding starting bracket, or everything inside an opening parenthesis with closing bracket (unbalanced grouping stack).
That way, could be easier to identify balancing errors in big enclosed declarations, like that from big nested dicts declarations.
Thanks for the great work.

builtins and underscores in python vim syntax

@hdima

I have an issue I made at python-mode/python-mode#353 about syntax highlighting with vim.

Here is the post:

2013-12-16-223731_5206x1080_scrot

Taking a look at pocoo code / many python projects, here are some common variable names:

fix_tuple_repr - highlighting tuple and repr
implements_bool - highlight bool
range_type highlights range and type
file_something highlights file

Is this expected behavior? Is this considered a feature? An option or a bug to fix?

Highlighting trailing comma assignment

Hi there,

I find that bugs like

foo = 42,

are fairly common that it would be valuable to highlight the , in that scenario. While this syntax is technically correct in creating a tuple, I find that it's unintentional 80% of the time and drawing more attention to it would be valuable.

Closest solution I've hacked together is:

syn match PythonTrailingCommaWarning    "[=].*\(,\)\s*\(#.*\)*$" display

I'd love for something like this to be included in this syntax file, but there are some improvements that could be done if anyone is more familiar with how Vim syntax files work:

  • Only highlight the ,, not the entire substring starting from = ...
  • Include the scenario where it's return ...,
  • Exclude the scenario where it's foo = "bar, #"

Though I find that even without these improvements, this addition is already useful in catching these annoying bugs. :)

self isn't highlighted in classes

I've searched and found issues about that
#21
#10

And I find you arguments very weak.

So your first argument:

I actually tried it and I don't really like how it looks. It adds too many colors to the code to the point that it's getting harder to follow.

Really? You think that fist example is less readable then the second? I (and obviously a lot of people) don't. I think it's more readable.

screenshot 2016-01-06 22 35 17

screenshot 2016-01-06 22 35 38

If you can easily filter class fields from other variables and stuff it is beneficial. You can't doubt that, don't you? I strongly think if you somehow did it so that when self is highlighted it is harder to you to follow code, you just did something wrong with colors, that's it.

You second argument.

self is actually just a conventional name for the first argument of a method. And if somebody uses for example just s instead it won't be highlighted and just will be confusing.

Well then s is should be highlighted also, or any other name that is the pointer to class instance. And pycharm is actually doing just that. But that's probably involve actually parsing file or something and is harder (or impossible) to do with regexp. If that is so, than you should state so.

You last argument

As it just an argument of a method it also can raise a question "why the other arguments not highlighted?" and also can add to the confusion.

I will answer this 'confusing' question. Well, I've already answered it actually, so I'll just repeat myself. Because it's beneficial to filter class fields from other stuff in methods.

So to state my point again.
It is obviously beneficial to filter class field from other stuff. If it's impossible, say so. If it's hard and I you doubt my arguments, so you won't do it yourself, than if you could guide somehow to the solution many will thank you for that (including me). If it's easy, but you won't do it, then again, it would be nice if you could provide help on how to do that.

else: not highlighted

I noticed that the "else:" statement (with colon) is not correctly highlighted. Adding "else:" to line 156: syn keyword pythonConditional remedied the issue.

highliting isn't semantic aware.

screenshot 2016-01-07 17 55 50

screenshot 2016-01-07 17 55 58

screenshot 2016-01-07 17 56 26

As you can see from screenshots pycharm nows that len is bultin function and hightlights it, but if I define variable named len for some evil reason (and I sometimes do it with dict) it knows that it's the variable and not the function call, so it doesn't highlight it, unlike your highlighter.

Would it make sense to remove the @Spell (or at least make it a configurible option) for python strings ?

Hi,
Thanks for maintaining this. Really appreciate your work. Here's the issue I'm reporting:

Although I like having the @Spell option enabled for pythonComment, the same option for strings is a bit distracting because, typically my code doesn't usually have too many 'user consumable strings', however, it does have a lot of strings as keys to dicts etc:

  d= {'top_nav' : ..., 'err_msg' : ...} 

...which then get highlighted as spell errors. Is it possible to make this a configurable option, like python_spell_check_comments and python_spell_check_strings.

This isn't a big pain, just a suggestion. So feel free to close this issue with a WONTFIX . Thanks again for your work.

cheers,
steve

Tabbing behaviour is broken

When I enabled this package, it messed up the autotabbing behaviour of vim making it effectively unusable. Seems like #62 ("the project is dead: time to fork") might be right, as that's some pretty basic behaviour that is broken.

None is highlighted differently in Python 3 than in Python 2

This plugin's syntax file treats None as a pythonBuiltinObj for Python 2, but as a pythonStatement for Python 3. This causes different highlighting for None in Python 2 versus Python 3, since pythonBuiltinObj maps to the Structure group, but pythonStatement maps to the Statement group.

  1. Why did this plugin's maintainers decide the highlighting group for None should be different between Python 2 and Python 3? I'm not aware of anything different in the behavior of None from Python 2 to Python 3.
  2. Doesn't None โ€” a builtin constant โ€” most logically map to the Constant group, rather than Structure or (especially) Statement? (The same goes for other builtin constants like True, False, etc.)

yield from is incorrectly highlighted

Hello,

the yield from construct introduced in PEP 380 is not correctly highlighted. The from portion is highlighted as the standalone from statement, as opposed to the entire statement which should be highlighted as a keyword (that is, from preceeded by yield should be highlighted as as keyword).

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.