寻找比 GNU 缩进更灵活的工具

发布于 2024-07-06 05:23:02 字数 553 浏览 6 评论 0原文

当我使用我想要的源代码中的各种选项运行 indent 时,它会执行我想要的操作,但也会混淆指针类型中 *s 的放置:

  -int send_pkt(tpkt_t* pkt, void* opt_data);
  -void dump(tpkt_t* bp);
  +int send_pkt(tpkt_t * pkt, void *opt_data);
  +void dump(tpkt * bp);

我知道我在类型旁边放置 *s 而不是变量是非常规的,但如何才能做到这一点?我打算让他们一个人呆着吗? 或者有其他工具可以实现我想要的功能吗? 我查看了手册页、信息页,并访问了 Google 建议的六个页面,但我找不到执行此操作的选项。

我尝试了艺术风格(又名 AStyle),但似乎无法弄清楚如何使其缩进为 4 的倍数,但使每 8 个制表符。 那是:

if ( ... ) {
<4spaces>if ( ... ) {
<tab>...some code here...
<4spaces>}
}

When I run indent with various options I want against my source, it does what I want but also messes with the placement of *s in pointer types:

  -int send_pkt(tpkt_t* pkt, void* opt_data);
  -void dump(tpkt_t* bp);
  +int send_pkt(tpkt_t * pkt, void *opt_data);
  +void dump(tpkt * bp);

I know my placement of *s next to the type not the variable is unconventional but how can I get indent to just leave them alone? Or is there another tool that will do what I want? I've looked in the man page, the info page, and visited a half a dozen pages that Google suggested and I can't find an option to do this.

I tried Artistic Style (a.k.a. AStyle) but can't seem to figure out how to make it indent in multiples of 4 but make every 8 a tab. That is:

if ( ... ) {
<4spaces>if ( ... ) {
<tab>...some code here...
<4spaces>}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我闹别瞎闹 2024-07-13 05:23:02

Uncrustify

Uncrustify 有多个关于如何缩进文件的选项。

从配置文件:

indent_with_tabs                           
  How to use tabs when indenting code  
  0=spaces only  
  1=indent with tabs, align with spaces  
  2=indent and align with tabs

您可以在此处找到它。

BCPP
来自网站:“bcpp 缩进 C/C++ 源程序,用空格替换制表符或相反。与缩进不同,它(根据设计)不会尝试换行长语句。”
此处找到它。

通用IndentGUI
它是一个支持多种美化器/格式化程序的工具。 它可以引导您找到更多选择。
此处找到它。

艺术风格
您可以尝试 艺术风格又名 AStyle (尽管它不能满足您的需要,但我将把它留在这里以防其他人发现它有用)。

Uncrustify

Uncrustify has several options on how to indent your files.

From the config file:

indent_with_tabs                           
  How to use tabs when indenting code  
  0=spaces only  
  1=indent with tabs, align with spaces  
  2=indent and align with tabs

You can find it here.

BCPP
From the website: "bcpp indents C/C++ source programs, replacing tabs with spaces or the reverse. Unlike indent, it does (by design) not attempt to wrap long statements."
Find it here.

UniversalIndentGUI
It's a tool which supports several beautifiers / formatters. It could lead you to even more alternatives.
Find it here.

Artistic Style
You could try Artistic Style aka AStyle instead (even though it doesn't do what you need it to do, I'll leave it here in case someone else finds it useful).

若水微香 2024-07-13 05:23:02

修改代码并改变其行为。 毕竟它是 GNU。 ;-)

因为这可能不是您想要的答案,所以这是另一个链接: http://www.fnal.gov/docs/working-groups/c++wg/indenting.html

Hack around and change its behavior editing the code. It's GNU after all. ;-)

As it's probably not the answer you wanted, here's another link: http://www.fnal.gov/docs/working-groups/c++wg/indenting.html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文