使用縮排格式化 while 語句(或 for,...)

使用縮排格式化 while 語句(或 for,...)

可以使用 GNU 縮排將 while(或 for,...)語句格式化為單行嗎?

我的縮排(GNU indent 2.2.11)輸出這個

while (a == b)
    b++;

我希望它輸出一行。我嘗試了很多選項,但還無法想出正確的組合(這是完全可能的)。

while (a == b) b++;
for (i = 0; i < 100; i++) arr[i] = i;

答案1

我不能使用indent但使用uncrustify。和:

uncrustify --show-config

您可以看到它的配置選項,然後您必須建立~/.uncrustify.cfg用於定義樣式的檔案。對於與您的問題有關的內容,您必須將其放入設定檔中:

nl_create_if_one_liner 真
nl_create_for_one_liner 真
nl_create_while_one_liner 真

請參閱man uncrustify以了解如何調用uncrustify.

相關內容