Emacs C function call syntax highlighting

I use a special syntax highlighting theme for C in emacs, but I donโ€™t have the ability to highlight function calls. For example:

int func(int foo) { return foo; } void main() { int bar = func(3); } 

Is there any way to highlight the func function call in this example? It doesn't matter if macros are highlighted. Keywords like if, switch, or sizeof must not match.

Thanks!

+6
c emacs syntax-highlighting
source share
3 answers

The order of entries in the keyword list is significant. Therefore, if you place your entries after those that highlight keywords and function declarations, they will not be matched.

 (font-lock-add-keywords 'c-mode '(("\\(\\w+\\)\\s-*\(" (1 rumpsteak-font-lock-function-call-face))) t) 

Alternatively, you can use a function instead of a regular expression like MATCHER . Overkill for your question, if you have precisely indicated your requirements, but are useful in more complex cases. Unchecked (typed directly in the browser, in fact, so I donโ€™t even guarantee balanced parentheses).

 (defun rumpsteak-match-function-call (&optional limit) (while (and (search-forward-regexp "\\(\\w+\\)\\s-*\(" limit 'no-error) (not (save-match-data (string-match c-keywords-regexp (match-string 1)))) (not (save-excursion (backward-char) (forward-sexp) (c-skip-whitespace-forward) (or (eobp) (= ?\{ (char-after (point))))))))) (font-lock-add-keywords 'c-mode '((rumpsteak-match-function-call (1 rumpsteak-font-lock-function-call-face)))) 
+9
source share
 (font-lock-add-keywords 'c-mode '(("\\<\\([a-zA-Z_]*\\) *(" 1 font-lock-keyword-face))) 

in your .emacs. Replace font-lock-keyword-face with the one you want (MX list-faces-display to get a list of predefined ones).

+3
source share

You can try Ctrl-s to search or Ctrl-r to search back. Emacs will highlight your function for you.

0
source share

All Articles