python builtin function like print, len, sum... i can match and highlight other function and its argument. but with builtin function i can't change color.

my setup:

syn keyword pythonStatement def nextgroup=pythonFunction skipwhite
syn match pythonFunction "\%(\%(def\s\|@\)\s*\)\@<=\h\%(\w\|\.\)*" contained nextgroup=pythonVars
syn region pythonVars start="(" skip=+\(".*"\|'.*'\)+ end=")" contained contains=pythonParameters transparent keepend
syn match pythonParameters "[^,]*" contained contains=pythonParam skipwhite
syn match pythonParam "[^,]*" contained contains=pythonExtraOperator,pythonLambdaExpr,pythonBuiltinObj,pythonBuiltinType,pythonConstant,pythonString,pythonNumber,pythonBrackets,pythonSelf,pythonComment skipwhite
syn match pythonBrackets "{[(|)]}" contained skipwhite

and links all to Function but the result: enter image description here

EDIT 1: @Rich: for more clear, below is the expectation: enter image description here

  • I'm afraid I can't figure out what you're trying to do.
    – Rich
    Oct 6 '17 at 14:08
  • @Rich: thanks for your reply, please refer to my EDIT 1.
    – Tuyen Pham
    Oct 6 '17 at 14:11
  • 1
    Got it. What's the output of the command: for id in synstack(line("."), col(".")) | echo synIDattr(id, "name") | endfor when run with the cursor on shouldBeGreen and when the cursor is on itsGreen?
    – Rich
    Oct 6 '17 at 14:25
  • @Rich: super, i got result, with shouldBeGreen has no output. With itsGreen output is: pythonFunctionCallVars pythonFunctionCallParameters pythonFunctionCallParam that's actually same as pythonVars, pythonParameters and pythonParam.
    – Tuyen Pham
    Oct 6 '17 at 14:40
  • then why those match don't apply on print function?
    – Tuyen Pham
    Oct 6 '17 at 14:41

I've found the issue, basically keywords can't be contained in other matches, pythonBuiltin is keyword.
:help syn-containedin, it has quote:
Don't forget that keywords never contain another item, thus adding them to "containedin" won't work.
here for more discussion.

  • This is incorrect. The documentation you've quoted states that keywords cannot contain another item, not that they cannot be contained in other items. containedin is not used anywhere in your code: you do have some uses of contains but these are all in match and region items, which is perfectly legal.
    – Rich
    Dec 1 '17 at 11:55
  • Yes, it should be priority, people should refer to the link.
    – Tuyen Pham
    Dec 1 '17 at 11:59

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.