Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I highlight custom datatypes in emacs?

Tags:

emacs

Where I work we use a lot of our own custom data types. The c++ that emacs recognizes, notices many of the custom datatypes from the STL such as string, vector, etc. This means that in my editor if i declare a function like so:

string getString() const {
    return str;
}

The return value will be highlighted green and due to this the function name will in blue. Now if I decide to use a custom string this messes everything up. So now my cpp files are mostly in white because we don't use the normal stl classes here. How can I program my emacs editor to recognize that when I mean 'String', color it the same way you would as 'string'?

like image 364
Rob Avatar asked Nov 24 '25 01:11

Rob


1 Answers

You need font-lock-add-keywords. Here's an example:

(font-lock-add-keywords 'cc-mode
  '(("String" . font-lock-type-face)
    ("str" . font-lock-type-face)))

It adds a list of regular expression/font lock pairs.

There's much more to be read on the topic of adding-keywords. In particular, ctypes.el might be of interest to you.

like image 94
Bozhidar Batsov Avatar answered Nov 26 '25 19:11

Bozhidar Batsov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!