[英]Indent preprocessor directives as C code in emacs
Emacs, by default, does not indent pre-processor code. 默认情况下,Emacs不会缩进预处理器代码。 I know it has historical roots that are obsolete by now.
我知道它的历史根源已经过时了。
However, having a code with a lot of #ifdef unindented is hard to read. 但是,拥有大量#ifdef unindented的代码很难阅读。
So I would like to make emacs automatic indentation give me something like that: 所以我想让emacs自动缩进给我这样的东西:
void myfunc() {
int foo;
#ifdef BAR
printf(foo);
#endif
return foo;
}
Instead of what I get now : 而不是我现在得到的:
void myfunc() {
int foo;
#ifdef BAR
printf(foo);
#endif
return foo;
}
Any leads on that issue you emacs hackers :) ? 这个问题的任何线索你emacs黑客:)?
You can simply tell Emacs to add an offset to the pre-processor lines. 您可以简单地告诉Emacs向预处理器线添加偏移量。
point
) in a pre-processor line point
)放在预处理器行中 Syntactic symbol to change:
, Syntactic symbol to change:
cpp-macro
, press Enter cpp-macro
,按Enter键 0
) 0
) Then a TAB on each pre-processor line should indent it correctly. 然后每个预处理器行上的TAB应正确缩进。 (or Mx
indent-region
...). (或Mx
indent-region
......)。
To have the change set permanently, you can for instance add the required lines in your .emacs
file. 要永久更改设置,您可以在
.emacs
文件中添加所需的行。
An easy way to copy a previously entered command is cx ESC ESC and use the arrow keys to find the (c-set-offset ...)
Elisp command. 复制先前输入的命令的简单方法是cx ESC ESC并使用箭头键找到
(c-set-offset ...)
Elisp命令。
That should be 那应该是
(c-set-offset (quote cpp-macro) 0 nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.