vim-python / python-syntax

Python syntax highlighting for Vim
MIT License
438 stars 84 forks source link

Make highlighting more customizable #1

Closed purpleP closed 7 years ago

purpleP commented 7 years ago

I've added some highlightings that I like, but not everyone might like them. So here's a screenshot that displays all the features I've added.

We can make syntax file more customizable on demand (as soon as anyone will ask for it I mean).

screenshot 2017-02-16 20 25 42
nfnty commented 7 years ago

I think they're great, but options are welcome.

nfnty commented 7 years ago

Is there anything specific now that hasn't got an option?

nfnty commented 7 years ago

Btw, I had to remove the kwargs highlighting as it was buggy. A better implementation is welcome though.

purpleP commented 7 years ago

@nfnty Buggy? Hmm, it works for me. Show me example where it wasn't working. By the way it wouldn't work in the case where the open parenthesis isn't visible in the screen and that's by design (performance)

nfnty commented 7 years ago

There are a lot of cases being mishighlighted. Anything matching \i\+= is highlighted, even though not being a kwarg: test((test=test)), test({test=}) etc. The implementation is very fragile and prone to breakage. To implement this properly would mean needing to parse exactly like the interpreter.

purpleP commented 7 years ago

@nfnty Well, both of you examples aren't valid python. I think it's reasonable compromise to expect invalid python to be highlighted improperly. By the same reasoning you can disable highlighting of python keywords, because in blabla def some def would be highlighted as a keyword.

However if you have examples of valid python code that would be highlighted improperly I would try to cover them.

nfnty commented 7 years ago

test(var=='test')

The kwarg mishighlighting is only the minor problem for now. The regions are being misapplied, which will introduce problems down the road.

purpleP commented 7 years ago

@nfnty Well, that code isn't pythonformat comliant, right? But anyway, this particular case is easy to fix. What about regions being misapplied?

purpleP commented 7 years ago

@nfnty

diff --git a/syntax/python.vim b/syntax/python.vim index 752ce01..b783f2d 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -217,7 +217,7 @@ syn region FunctionParameters start='(' end=')' display contains= \ pythonNone, \ pythonBuiltinFunc, \ pythonBoolean nextgroup=pythonRaiseFromStatement display contained -syn match OptionalParameters /\i\ze=/ display contained +syn match OptionalParameters /\i\ze=(=)\@!/ display contained " " Decorators (new in Python 2.4) " I just added negative lookahead.

nfnty commented 7 years ago

It's valid Python code, also highlighting should be as strict as possible.

Use commit c8300301fb9e2c18988eac4f15c0e15e4abd48bd (commit before removal) so that we're talking about the same thing.

test((test, test))
     ^^^^^^^^^^^^

The marked area is being matched as a pythonFunctionArgs region, when it's not. It's not simple to fix properly as that would entail parsing for functions inside the function args.

nfnty commented 7 years ago

BTW, you can use the plugin gerw/vim-HiLinkTrace to trace highlighting.

nfnty commented 7 years ago

Continue discussion in #14.