-1

I want my emacs to change code color to gray if the macro undefined, and also, in the case of #ifdef #else, a proper indent is needed too.

#define MY_MACRO
#ifdef MY_MACRO
int foo = 0;//proper indent, normal color
#else
int bar = 0;//proper indent, and gray color
Drew
  • 29,895
  • 7
  • 74
  • 104
Francis
  • 737
  • 1
  • 7
  • 21

1 Answers1

2

Emacs has a hide-ifdef-mode.

In hide-ifdef-mode, code within #ifdef constructs that the C preprocessor would eliminate may be hidden from view.

It can be activated via M-x hide-ifdef-mode. For a basic usage, use the function hide-ifdefs (default shortcut C-c @ h). `

#define MY_MACRO
#ifdef MY_MACRO
int foo = 0;//proper indent, normal color
#else...
#endif

To revert the effects, use the function show-ifdefs (default shortcut C-c @ s):

#define MY_MACRO
#ifdef MY_MACRO
int foo = 0;//proper indent, normal color
#else
int bar = 0;//proper indent, and gray color
#endif
  • thanks@Lud, this is a solution to tell whether the MACRO is defined, but not what i want. i think color change would be a better choice, because i can see what is under UNDEFINED conveniently without 'show-ifdefs' cmd(although it is convenient too).so i'll let the thread open, and wait for my COLOR CHANGE SOLUTION. – Francis Dec 09 '16 at 04:13