emacs、#ifdef 宏颜色更改和缩进

问题描述 投票:0回答:2

如果宏未定义,我希望我的 emacs 将代码颜色更改为灰色,而且,在 #ifdef #else 的情况下,也需要适当的缩进。

#define MY_MACRO
#ifdef MY_MACRO
int foo = 0;//proper indent, normal color
#else
int bar = 0;//proper indent, and gray color
emacs syntax-highlighting font-lock
2个回答
2
投票

Emacs 有一个

hide-ifdef-mode

在 hide-ifdef 模式下,#ifdef 中的代码构造 C 预处理器将消除可能隐藏在视图中的情况。

可以通过

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
投票

如果您想要更改颜色而不是隐藏现在有阴影的 hide-ifdef-mode,请使用 hide-ifdef-toggle-shadowing 激活。

© www.soinside.com 2019 - 2024. All rights reserved.