2016-11-28 26 views
-1

我希望我的emacs能夠在宏未定義的情況下將代碼顏色更改爲灰色,並且在#ifdef#else的情況下也需要適當的縮進。emacs,#ifdef宏的顏色變化和縮進

#define MY_MACRO 
#ifdef MY_MACRO 
int foo = 0;//proper indent, normal color 
#else 
int bar = 0;//proper indent, and gray color 

回答

2

Emacs有hide-ifdef-mode

在hide-ifdef-mode中,#ifdef構造中預處理器將消除的代碼可能會被隱藏起來。

它可以通過M-x hide-ifdef-mode激活。對於基本用法,請使用功能hide-ifdefs(默認快捷方式C-c @ h)。 `

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

要恢復的影響,使用功能show-ifdefs(默認快捷鍵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 
+0

感謝@路德,這是一個解決方案,告訴MACRO是否已定義,但不是我想。我認爲顏色變化會是一個更好的選擇,因爲我可以方便地看到UNDEFINED下沒有'show-ifdefs'cmd(儘管它也很方便),所以我會讓線程打開,然後等待我的COLOR CHANGE SOLUTION 。 – francis