2012-09-05 15 views
3

我有函數調用看起來像這樣(沒有明顯的理由):Uncrustify COLAPSE多行函數調用

func 
(
    a, 
    b, 
    c 
) 

有沒有一種方法,使uncrustify摺疊功能到一個單一的線?我一直在嘗試兩天不開關...

我得到它的功能聲明的工作,但我不明白它爲函數調用工作。

雖然我們在這我也有看起來像這樣的功能:

func 
(
    a, // (IN) the A 
    b, // (IN) something b 
    c // (OUT) the resulting value 
) 

有沒有一種方法來處理這種情況下也不會破壞代碼?由於uncrustify保留評論,我認爲這是不可能的。使用函數聲明將其摺疊爲第一個註釋。

+0

感謝您告訴我關於uncrustify。我想我可能會喜歡它(除了)/(over)astyle,我通常使用:) – sehe

+0

您可能想要嘗試UniversalIndentGUI,在那裏您可以嘗試一堆不同的格式化工具並立即看到結果。 – rioki

+0

哦,我用了C++的所有免費格式化工具(我可以找到):http://www.rioki.org/2012/09/04/cleanup-yerr-code.html – rioki

回答

0

經過一番龍鳳研究後,我得出結論,uncrustify不能這樣做。對於我porposses我一起砍死一個小perl腳本:

$filename = $ARGV[0]; 

{ 
    open(FILE, "<", $filename) or die "Cant open $filename for reading\n"; 
    local $/ = undef; 
    $lines = <FILE>; 
    close(FILE); 
} 

# squash comments in function calls and declarations 
$lines =~ s/,[ \t]*\/\/[^\n\r]*/,/gm; 
# squash last comment in function calls and declarations 
$lines =~ s/[ \t]*\/\/[^\n\r]*\r\n[ \t]*\)/\)/gm; 
# squash newlines at the start of a function call or declaration 
$lines =~ s/\([ \t]*\r\n[ \t]*/\(/gm; 
# squash newlines in function calls and declarations 
$lines =~ s/,[ \t]*\r\n[ \t]*/, /gm; 
# squash the last newline in a function call or declaration 
$lines =~ s/[ \t]*\r\n[ \t]*\)/\)/gm; 

{ 
    open(FILE, ">", $filename) or die "Cant open $filename for writing\n"; 
    print FILE $lines; 
    close(FILE); 
} 

我會考慮,如果我可以建立該功能集成到uncustify補丁。

2

閱讀的文檔,我想出了這個:

# Add or remove newline between a function name and the opening '(' 
nl_func_paren       = remove # ignore/add/remove/force 

# Add or remove newline between a function name and the opening '(' in the definition 
nl_func_def_paren      = remove # ignore/add/remove/force 

# Add or remove newline after '(' in a function declaration 
nl_func_decl_start      = remove # ignore/add/remove/force 

# Add or remove newline after '(' in a function definition 
nl_func_def_start      = remove # ignore/add/remove/force 

# Add or remove newline after each ',' in a function declaration 
nl_func_decl_args      = remove # ignore/add/remove/force 

# Add or remove newline after each ',' in a function definition 
nl_func_def_args       = remove # ignore/add/remove/force 

# Add or remove newline before the ')' in a function declaration 
nl_func_decl_end       = remove # ignore/add/remove/force 

# Add or remove newline before the ')' in a function definition 
nl_func_def_end       = remove # ignore/add/remove/force 

按照你的希望,意見那種-的廢墟,雖然。有改變單行雖然評論//)到塊註釋/* ... */),它應該更容易讓你手動加入行的選項(例如,在VIM v%J

# Whether to change cpp-comments into c-comments 
cmt_cpp_to_c        = true # false/true 

我有原型,聲明電話進行了測試:

的通話不受影響。還請注意以下相關選項:

# Whether to fully split long function protos/calls at commas 
ls_func_split_full      = false # false/true 
+0

那麼我已經使用nl_func ***選項。他們對功能的聲明和定義進行了很好的處理,但不是要求。我知道cmt_cpp_to_c,但我不想因爲其他原因使用它,我可以忍受它。我需要一個「刪除函數調用/定義中的註釋」選項。如果調用合併會起作用,我只需將編輯器中的評論刪除並重新運行uncrustify ... – rioki

+0

下一次,請在帖子中說明此信息。它爲你節省了閱讀你已知的能量。專業提示:要刪除評論,請考慮使用預處理器(例如,在vim中):':'<,'>!cpp | grep -Ev'^ \#'' – sehe

+0

「我已經爲函數聲明工作了,但我不明白它是爲函數調用工作的。」 - rioki很抱歉,雖然很清楚,但無論如何都要感謝。 – rioki