我如何在linux中使用“缩进”实用程序纠正命名空间块中的缩进

How can I correct indentation in namespace block using `indent` utility in linux

本文关键字:缩进 实用程序 命名空间 linux      更新时间:2023-10-16

(我已经在https://codereview.stackexchange.com/上发布了这个问题,并标记为离题。主持人建议在SO发布问题

我使用indent来纠正缩进。一切正常,除了名称空间块缩进。

我有示例代码:

$ cat test2.cc
#include <iostream>
namespace API
{
void f ()
{
    std::cout << "f() called" << std::endl;
}
}

但运行indent后,我得到:

$ indent -st -bl -bli0  -i 4 -c 4 -kr -nce -bls test2.cc
#include <iostream>
namespace API
{
    void f()
^^^^<=== I don't want these indentation
    {
        std::cout << "f() called" << std::endl;
    }
}

我不希望第一次缩进命名空间块,很难找到任何相关的缩进选项(这是非常复杂的)。我怎样才能算出来呢?

indent是用来格式化C代码的。它并不真正了解c++语法,例如namespace

我建议使用clang-format,这是一个c++格式化程序。