1

(EMACS 24.2 ) I need to highliight function call. I found this on internet

(add-hook 'c-mode-hook (lambda ()
   (font-lock-add-keywords nil '(
      ("\\<\\(\\sw+\\) ?(" . 'font-lock-function-name-face))t)))

It works but it highlight also the following open parenthesis. I am non confident with regular expression, please, How can I modify match string to avoid parenthesis highlighting?

enter image description here

Drew
  • 29,895
  • 7
  • 74
  • 104
Mario Giovinazzo
  • 431
  • 2
  • 12

1 Answers1

10

The regular expression is fine, you just need to highlight the first group in the match, not the whole of it. Replace . 'font-lock-function-name-face with 1 'font-lock-function-name-face.

Another thing to change, just a recommendation, is that font-lock-add-keywords accepts the mode name as the first argument. So you don't need to use the hook.

Result:

(font-lock-add-keywords
 'c-mode
 '(("\\<\\(\\sw+\\) ?(" 1 'font-lock-function-name-face)))
Dmitry
  • 3,625
  • 2
  • 30
  • 28