3

I'm trying to add additional colors to json-mode for when I edit json-schema. I can get it working fine without searching for double quotes, but I need to for some highlighting. I've tried quite a few things to highlight properties inside of "properties" including:

(font-lock-add-keywords 'json-mode '(("""\\(properties\\)""" 1 '(:foreground "chartreuse4") t))
(font-lock-add-keywords 'json-mode '(("\\""\\(properties\\)"\\"" 1 '(:foreground "chartreuse4") t))
(font-lock-add-keywords 'json-mode '(("\\s""\\(properties\\)\\s""" 1 '(:foreground "chartreuse4") t))

I expect once I understand the solution, I can easily highlight object in "type": "object" which was my original goal.

1 Answer 1

3

To put a " char inside a string in Lisp, just put one backslash in front of it.

If you want to highlight anything (not just properties) between double-quotes, try this as your regexp:

"\"\\(?:[^\"]\\|\\\\\\(?:.\\|[\n]\\)\\)*\""

That assumes that a backslash escapes any char - in particular the char ", so that \" is highlighted inside the string. Similarly for backslash preceding any other char. Dunno whether you want that, but you get the idea.

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.