[英]C++ on Linux - How do I #define a #ifdef / #endif debug conditional
[英]How do I make emacs treat #ifdef and #endif like '{' and '}'?
我希望emacs将“#ifdef”与缩进相对应,就像“{”和“#endif”一样对待“}”。 像这样:
#ifdef __linux__
#include <sys/socket.h>
#endif
int func(void)
{
int foo = 0;
#ifdef DO_STUFF
foo = do_stuff();
#endif
return foo;
}
代替:
#ifdef __linux__
#include <sys/socket.h>
#endif
int func(void)
{
int foo = 0;
#ifdef DO_STUFF
foo = do_stuff();
#endif
return foo;
}
用“cpp-macro”搞乱是不行的。 我该怎么办? 谢谢!
您可以将此el文件用于emacs: http : //www.emacswiki.org/emacs/ppindent.el
您可以在此处找到有关emacs缩进的许多信息: http : //www.emacswiki.org/emacs/IndentingC
预处理
意见
被认为在第一列开始,所以Emacs是正确的存在,但这些天的编译器通常允许它们被缩进。 (参见缩进#defines )
也就是说,请参阅emacs中的Indent预处理程序指令作为C代码,以便对此进行讨论。 事实上,我可能会尝试将此问题作为副本重复。
我同意关于该问题的一些评论,因为将预处理器视为块或词法范围是错误的,因此以与使用常规C代码相同的方式缩进它实际上是有害的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.