1

I am trying to modify Vim's syntax highlighting rules for Python to suit specific needs : in particular, I need to capture all the line after some regexps (^Out [.*]: and ^\h\w*Error:).

After some digging in the vim syntax file python.vim (where I got inspiration from how strings are treated) and this SE subject, I finally came to this

  syntax match OutProc "^Out\s*\[.*\]:"
  syntax match ErrProc "^\h\w*Error:"
  syntax match plainOut ".*" contained
  syntax region PlainOutput matchgroup=plainInit
           \ start="^Out\s*\[.*\]:" end="$" contains=plainOut
  syntax region PlainOutput matchgroup=ErrProc
           \ start="^\h\w*Error:" end="$" contains=plainOut
  highlight default link plainInit OutProc

which almost works perfetcly. The only problem is that in the python.vim syntax file, one can find

syn keyword pythonExceptions  BaseException Exception

and so on for all bult-in exceptions. In consequence, in

FooError: int True
TypeError: int True

the first line behaves correctly (int True is captured in a PlainOutput region) while the second one does not (TypeError, int and True are recognized separately as keywords and hightlihgted as such) : I guess TypeError is matched as a keyword instead of the delimiter of the PlainOutput region. So finally my question boils down to : how to ensure that the pattern "^\h\w*Error:" is recognized as the delimiter instead of a distinct keyword when the keyword already exists ?

0

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.

Browse other questions tagged or ask your own question.