Uncrustify Colapse Multiline Вызов функции

У меня есть вызовы функций, которые выглядят так (без видимой причины):

func
(
a,
b,
c
)

Есть ли способ заставить uncrustify свернуть функцию в одну строку? Я уже два дня пытаюсь не включать и выключать …

Я заставил его работать для объявлений функций, но я не получал его для вызовов функций.

Пока мы занимаемся этим, у меня также есть функции, которые выглядят так:

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

Есть ли способ справиться с этим делом, не нарушая код? Поскольку uncrustify хранит комментарии, я думаю, что это невозможно. С объявлениями функций это сворачивает это к первому комментарию.

3

Решение

Читая документы, я придумал это:

# 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
2

Другие решения

После некоторого исследования LOOONG я пришел к выводу, что uncrustify не может этого сделать. Для моих частей я взломал небольшой скрипт на 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.

0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector