문제

(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

도움이 되었습니까?

해결책

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)))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top