Reputation: 19563
I'm using vim 7.3, scripting in python 2.7. I have some syntax highlighting, but mostly just for number, strings, comments, and a few core functions and keywords. I have tried the core vim python.vim syntax file, and the one from vim.org
Is there any way to get (separate colour) highlighting for variables and function names?
Upvotes: 2
Views: 2902
Reputation: 318688
There is not really a difference between variables and functions in python (both are first-class objects in python). So that's pretty much impossible without actually running the code and testing if callable(var)
is true.
And there are always cases where such a behaviour would be confusing:
class Dummy(object):
pass
foo = Dummy()
if False:
foo()
foo.__call__ = lambda self: 'meow'
foo.x = 'y'
foo()
When would you highlight foo
as a function now? It cannot be called until after the __call__
assignment but having different syntax highlighting for the same object would be pretty confusing. Of course the example is rather stupid. But it shows easily why it's not really possible to do what you want in python. You could make it even more complicated by using inheritance and metaclasses.
Upvotes: 6