Sublime Forum

Custom syntax word separators (include hyphen as a part of a word)

#1

I have just started to use your custom syntax feature and I need to allow the hyphen to be a part of a word for syntax highlighting.
My user preferences are :
“word_separators”: “./\()”’:,.;<>~!@#$%^&*|+=[]{}`~?"
I can click on a whole-word but the whole and word are different colours.

How can I tell the syntax customer to use these when I specify

  • match ‘(message)’ …
    and it highlights both of these, when I only need the first highlighted.
    message “Hi”
    set lf-message = “no”
0 Likes

#2

Are you creating a syntax definition and want to only match the first? Surround your pattern with \b anchors.

0 Likes

#3

I have a syntax match ‘\bmessage\b’ and I do not want this to match lf-message , but it does because it treats the hyphen as a word boundary. so where can I tell the syntax checker the hyphen is not a word boundary?

Thanks
Barry

0 Likes

#4

\b is an un-configurable regex feature (syntax parsing should be consistent across setups). You’ll want to either match words before scoping them using a lookahead: (?=[[:alpha:]_\-]+), match \blf-message\b before matching \bmessage\b or use a negative lookbehind: (?<![[:alpha:]_\-])message\b.

0 Likes