1

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?

2

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.

  • I thought for sure it was the comment-start in the syntax table. I'll try this asap, thanks – Sean Allred Oct 17 '14 at 19:37
  • Thanks again. I did try to find a reference for the syntax of the regular expression here; since \\< isn't standard, there must be some documentation on it. I couldn't find it anywhere in the manual, however -- do you know where I should look? – Sean Allred Oct 17 '14 at 20:57
  • @SeanAllred: Yes, see the Elisp manual, node Regexp Backslash, and look for \<. And see node Syntax for Strings for info about doubling the backslash. – Drew Oct 17 '14 at 21:01
  • In the manual. This is the \< special operator (where the `` needs to be doubled in strings because it's a special escaping character in strings). – Stefan Oct 17 '14 at 21:01
  • Related, before I ask another Q (in case it's another silly mistake like this...) - is there any reason it should work for this face? gist.github.com/vermiculus/6b2e6aad3c2ec14dc20d @Drew Ah, I suppose there's no (easy) way then to mark comment-only syntax. – Sean Allred Oct 17 '14 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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