1

I have a syntax file with the following definitions:

syn keyword pythonBuiltinFunc           __import__ abs all any
                                        \ bin bool bytearray
                                        \ callable chr classmethod compile complex
                                        \ delattr dict dir divmod
                                        \ enumerate eval
                                        \ filter float format frozenset
                                        \ getattr globals hasattr hash hex
                                        \ id input int isinstance issubclass iter
                                        \ len list locals
                                        \ map max min next
                                        \ object oct open ord pow property
                                        \ range repr reversed round
                                        \ set setattr slice sorted
                                        \ staticmethod str sum super
                                        \ tuple type vars zip
                                        \ nextgroup=pythonArgs skipwhite

The problem is that this matches occurrences of next (e.g.) even when that name is referenced as an object's attribute, as in obj.next, and this messes up the highlighting.

While I might buy that it's useful to not shadow built-in names, I'm not sure that I buy this for bound names.

Does any one have thoughts on how to apply the above definitions, but exclude the pathological case I mentioned below? I guess I'd be allowing whitespace in the word pattern, but ignoring it in the match?

1

You should use syn match instead of syn keyword for this kind of things:

syn match pythonBuiltinFunc "\<next\>"

For syn keyword, from syntax.txt:

It can only contain keyword characters, according to the 'iskeyword' option. It cannot contain other syntax items. It will only match with a complete word (there are no keyword characters before or after the match). The keyword "if" would match in "if(a=b)", but not in "ifdef x", because "(" is not a keyword character and "d" is.

  • This is indeed what I ended up doing. Thanks! – yangmillstheory Jul 5 '18 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.