2

An expansion of this question: How can I highlight all function names in Python files?

i have a sample:

src_file = replacement_file.replace(header_dir, source_dir)

here i need to match variable/arguments inside method/function, i need to match "header_dir", "source_dir"

Any suggestion is highly appreciated.

I'm working on the problem so will feedback to you via edit. thanks.

Edit 1: i try to match the function name, with help of @carpetsmoker i can match function name but can't match inside (), here:

syn match pFun "\v[[:alpha:]_.]+\ze(\s?\()" contained nextgroup=pFunVars
syn region pFunVars start="(" end=")" contained contains=pFunPara transparent keepend
syn match  pFunPara "[^,]*" contained contains=pythonString,pythonBrackets skipwhite

it doesn't match both function name and variables. highlight completely failed.

the fact is if i keep only:

syn match pFun "\v[[:alpha:]_.]+\ze(\s?\()"

function name match works. any clues?

EDIT 2: i guess match with end is ( and a region that start with "(" make it confused by regex engine. question is how can i separate the match pattern from ending with (, pattern contains ( and start of region is (, is that double "(" ?

EDIT 3: thanks @muru for suggestion, but it works partially,

syn region pFun matchgroup=Function \start="\v[[:alpha:]_.]+\ze(\s?\()" end=")" contains=pFun nextgroup=pFunPara
syn match pFunPara /\i*\ze\s*=[^,]/ contained contains=pythonString,pythonBrackets skipwhite

here, "pFunPara /\i*\ze\s*=[^,]/" i can't highlight the contains: pythonString, pythonBrackets inside pFunPara, @muru, do you have pattern to improve this? maybe loop via pFun make it impossible to highlight?

2

1 Answer 1

2

Adapting the syntax commands I used in this answer and the default pythonFunction syntax match from Vim:

syn region pFun matchgroup=Function start='\h\i*\(\.\h\i*\)*\s*(' end=')' contains=pFun,pythonString,pythonNumber,pfunPara
syn match pFunPara /\v(\=\s*)?\zs\h\i*\ze\s*[,)]/ contained
hi pFunPara ctermfg=yellow
hi Function ctermfg=green

Gives me:

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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