如何让 emacs 像'{'和 '}' 一样对待 #ifdef 和 #endif?
How do I make emacs treat #ifdef and #endif like '{' and '}'?
我希望emacs对待"#ifdef"就像对待缩进的"{"answers"#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宏"并不能起到什么作用。我该怎么做?谢谢
您可以将此el文件用于emacs:http://www.emacswiki.org/emacs/ppindent.el
你可以在这里找到许多关于emacs缩进的信息:http://www.emacswiki.org/emacs/IndentingC
预处理器注释应该从第一列开始,所以emacs在那里是正确的,但现在编译器通常允许它们缩进。(参见缩进#定义)
也就是说,有关这方面的讨论,请参阅emacs中的C代码缩进预处理器指令。事实上,我可能会尝试将这个问题作为重复问题来结束。
我同意关于这个问题的一些评论,因为认为预处理器是块或词法范围的是错误的,所以以与处理常规C代码相同的方式缩进它实际上是有害的。
相关文章:
- 如何将不同的可执行文件合并到一个窗口框架中进行编码?像浏览器一样
- 为什么在C++中对链表这样做?(像堆叠一样处理它们)
- 堆栈和队列是否像C++中的数组一样传递?
- 是否有技术原因阻止 Java 中的 final C++ 像 const 一样严格?
- #if 如何工作?我误解了 #if~#endif 的形式吗?
- 访问数据成员(本身是对象)的数据成员,就好像它们是类成员一样
- 我们可以将集合的值存储在变量中吗?就像我们可以将数组的值存储在变量中一样
- 我如何在C++像在 Python 中一样实现 f 字符串?
- 自制的上衣:看起来一样,但不完全相同
- 如何使用 redis-plus-plus 存储二进制数据,就像我想存储结构一样?@for_stack?
- 如何像在 C++ 中处理数组一样对 .txt 文件中的字符进行寻址?
- 如何将两个字符串加在一起,就好像它们是变量一样?
- 像 CPP 中的控制台一样的应用程序
- 为什么C++中没有常量引用,就像常量指针一样?
- 为什么将两个对象分配给另一个对象后,两个对象不一样?
- 有没有像给定的一样的 std::optional_function
- Java 是否像C++模板一样具有泛型推论?
- 记忆栅栏和记忆屏障是一样的吗
- 对象作为参数传递,就好像我们正在传递构造函数值一样
- 如何让 emacs 像'{'和 '}' 一样对待 #ifdef 和 #endif?