Thursday, September 12, 2013

Syntax Highlighting for Custom Keywords in IAR

Syntax highlighting makes code much easier to read by parsing the various elements (function names, parameters, constants, etc.) and displaying each differently. Unfortunately IAR doesn't recognize the C99 Fixed-Width Integer Types so it doesn't display them. For example see below. IAR doesn't display uint8_t any differently from the rest of the text.

To make IAR aware of these, you'll need to first create a custom keyword file, and then tell IAR to use it.

Creating a custom keyword file

To create a custom keyword file, open up your favorite text editor and insert the text below. Save it somewhere convenient. 



int8_t int16_t int32_t int64_t
int_fast8_t int_fast16_t int_fast32_t int_fast64_t
int_least8_t int_least16_t int_least32_t int_least64_t
uint8_t uint16_t uint32_t uint64_t
uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t
uint_least8_t uint_least16_t uint_least32_t uint_least64_t
intmax_t intptr_t uintmax_t uintptr_t 




Tell IAR to use the custom keyword file

Go to Tools : Options
Check the "Use Custom Keyword File" checkbox
Click on the Browse button labeled "..." and select the file you created above


Tell IAR to use the custom keyword file

Now, we'll change the color. 
Go to Editor : Colors and Fonts
In the Syntax Coloring box, click on "User keyword"
Change the color and font to whatever you want. I chose green to make them stand out a little from everything else that is blue.

Final Result

Same as before, but now with color.


No comments:

Post a Comment