Thursday, 24 August 2017

regex - Adding syntax highlighting for a comment section in Emacs


I have the following


(defun add-c-syntax-highlighting ()
(font-lock-add-keywords nil '(
("\\<\\(\\-+\\)" 1 font-lock-warning-face prepend)
("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend))))

with


(add-hook 'c-mode-common-hook 'add-c-syntax-highlighting)

Testing on this simple buffer yields seemingly contradictory results:


//FIXME:
//-------------

with only FIXME fontified. What am I doing wrong?



Answer



My crystal ball tells me what you do wrong is copy&paste code you don't understand. Looks like it's feeling sarcastic today, sorry, I promise I'll get a new one soon.


As for your problem, it's the \\< in your regexp, which is a special constructor which matches the beginning of a word, so it can never match in front of a - since words can only start with proper letters or digits.


No comments:

Post a Comment

Where does Skype save my contact&#39;s avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...