我怎么能调整缩进我的c源代码在整个选定块所有一次



我想调整我的源代码缩进正确在一次后,我选择了它的一些块。有什么函数或键可以用括号括起来吗?

这里是原始选择的示例代码块,我想调整缩进。

while(1)
{
    func1();
    if( )
    {
        func2();
       } 
            }
if( x == 0 )
  {
      aa = 1;
  }

这将是正确缩进的代码,我只是想调整。

while(1)
{
    func1();
    if( )
    {
        func2();
    } 
}
if( x == 0 )
{
    aa = 1;
}

选择您的代码并按下C-M-,它应该绑定到indent-region:

C-M-

缩进该区域中的所有行,就像在每行的开头键入TAB (indent-region)一样。

如果提供了数字参数,则将区域中的每一行缩进到该列号。

我使用邪恶模式,因为我喜欢vim编辑keymap。在我的情况下,块自动缩进可以在选择代码块后通过equal(=)键完成。用c-default样式重新排列代码块非常方便。

(1) install evil package
(2) Insert this code into you emacs init file.
; indentation style for c, c++, java
(setq c-default-style "linux"
      c-basic-offset 4)
(3) select block using v and direction key
(4) press '='

最新更新