Frage

(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

War es hilfreich?

Lösung

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)))
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top