Комплексное форматирование perltidy, если
Как я могу настроить perltidy для форматирования long, если такие заявления:
if (
('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6) or
('hello world' =~ /world/ and 6 = 3 * 2 * 1)
) {
print "hello\n";
}
или как это
if (
('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6)
or ('hello world' =~ /world/ and 6 == 3 * 2 * 1)
) {
print "hello\n";
}
Edit1: perltidyrc
--maximum-line-length=100
--indent-columns=4
--default-tabsize=4
--continuation-indentation=4
--closing-token-indentation=0
--no-indent-closing-brace
--paren-tightness=2
--square-bracket-tightness=2
--block-brace-tightness=0
--trim-qw
--nospace-terminal-semicolon
--nospace-for-semicolon
--indent-spaced-block-comments
--ignore-side-comment-lengths
--cuddled-else
--no-opening-brace-on-new-line
--no-opening-sub-brace-on-new-line
--no-opening-anonymous-sub-brace-on-new-line
--no-brace-left-and-indent
--blanks-before-comments
--blank-lines-before-subs=1
--blanks-before-blocks
--maximum-consecutive-blank-lines=1
Edit2: идея состоит в том, чтобы иметь новую строку после первого (
а также последний )
быть на новой линии с {
, Если это невозможно, будут приветствоваться любые другие предложения по улучшению форматирования.
3 ответа
Стиль по умолчанию для perltidy - по возможности следовать Руководству по стилю Perl. Что приводит к такому выводу:
if ( ( 'this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6 )
or ( 'hello world' =~ /world/ and 6 == 3 * 2 * 1 ) )
{
print "hello\n";
}
Вы можете контролировать фигурные скобки, независимо от того, находятся они на новой линии или нет. Вы можете контролировать герметичность скобок. Однако вы не можете контролировать новые строки скобок в блоках кода.
Стиль по умолчанию настолько близок, насколько вы собираетесь достичь желаемого результата.
Если он слишком длинный, одной из идей может быть ограничение максимальной длины каждой строки -l=n
, где n
максимальная длина каждой строки:
$ cat perltidy_test.pl
if (
('this is an example' =~ /an.*example/ and 1 * 2 * 3 == 6) or('hello world' =~ /world/ and 6 = 3 * 2 * 1)
) {
print "hello\n";
}
$ perltidy -l=60 perltidy_test.pl
$ cat pertidy_test.pl.tdy
if (
(
'this is an example' =~ /an.*example/
and 1 * 2 * 3 == 6
)
or ( 'hello world' =~ /world/ and 6 == 3 * 2 * 1 )
)
{
print "hello\n";
}
Пытаться
$ perltidy -bli -wba='or' perltidy_test.pl
это работает для этого примера...