hdima / python-syntax

Python syntax highlighting script for Vim
http://www.vim.org/scripts/script.php?script_id=790
MIT License
363 stars 109 forks source link

Don't highlight "builtins" that appear as attribute names #31

Closed anntzer closed 8 years ago

anntzer commented 9 years ago

congma/vim-syntax-python@21886ee963f4df89b198404ee4cc4165cc476de3 prevents "builtins" from being highlighted when they appear as attributes of another object. It would be nice to port this fix to this repo too.

Note that the fix is incomplete as it assumes there are no spaces around the dot, whereas python actually allows arbitrary whitespace there (subject to normal line continuation rules).

jevogel commented 8 years ago

I added this fix into this file to test for myself, and it seems to mess up the formatting of float literals, (e.g., with 100.5, the "100" part will be Normal and the ".5" part will be Number). Any thoughts on how to fix this? I'm not that great with regex.

jevogel commented 8 years ago

Actually managed to fix it by changing it to syn match pythonBtInIsolator "\(\.\)\@<!\<\k\+\D\>" contains=pythonBuiltinFunc,pythonStatement (added \D to the keyword search)

hdima commented 8 years ago

@jevogel Can you create a pull request?

However it seems containedin=pythonBtInIsolator is redundant and can be removed. And the regexp probably also can be simplified.

hdima commented 8 years ago

So I've tried a simplified version of the patch. It works but it breaks highlighting for numbers even with the fix from @jevogel. For example complex numbers, hexadecimal numbers and error checking for numbers don't work. Also I don't really like to use \@<! which can be really slow. So I think it's a bad idea to apply the patch.

anntzer commented 8 years ago

Can you detail in which aspects complex, hexadecimals and number error checking are broken? They seem to work fine for me with @jevogel's patch. Performance can be improved by only doing 1-character lookbehind, "\(\.\)\@1<!\<\K\+\>". (\K = \k but excluding digits)

purpleP commented 8 years ago

@anntzer try my fork https://github.com/purpleP/python-syntax.git