如何防止 PerlTidy 对齐分配但继续添加单个空格?
如何防止 PerlTidy 对齐分配但继续添加单个空格?
这个问题类似于如何防止 PerlTidy 对齐我的作业? 但我想在指示的地方添加单个空格。由于这个 -naws
开关对我不起作用。我只是不想插入多个空格。可以使用 perltidy 或其他工具吗?
Perl 整洁的更改:
my $a = 1;
my $aa = 2;
my $aaa= 3;
使用
my $a = 1;
my $aa = 2;
my $aaa = 3;
-naws 后它保持不变:
my $a = 1;
my $aa = 2;
my $aaa= 3;
我希望将此代码格式化为:
my $a = 1;
my $aa = 2;
my $aaa = 3;
How can I prevent PerlTidy from aligning assignments but keep adding single spaces?
This question is similar to How can I prevent PerlTidy from aligning my assignments? but I would like single spaces to be added where directed. Due to this -naws
switch does not work for me. I just do not want multiple spaces to be inserted. Is it possibe with perltidy or some other tool?
Perl tidy changes:
my $a = 1;
my $aa = 2;
my $aaa= 3;
into
my $a = 1;
my $aa = 2;
my $aaa = 3;
with -naws it remains unchanged:
my $a = 1;
my $aa = 2;
my $aaa= 3;
I would like this code to be formatted as:
my $a = 1;
my $aa = 2;
my $aaa = 3;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一个未记录的标志
--no-valign
似乎可以在不修改 perltidy 源的情况下实现两全其美。正如您所指出的,
--no-add-whitespace
过于激进,会阻止在其他所需位置(运算符周围等)添加空格。使用--no-valign
perltidy 仍在将my ($arg)=@_;
更正为my ($arg) = @_;
code> 但不会尝试跨行垂直对齐运算符。该设置不会完全禁用垂直对齐器,因此您仍然可以在其他地方获得一些好处(例如侧面注释)。到目前为止,我发现的唯一问题是,侧面注释块的第一个侧面注释与后续注释不一致:
它仅尊重
--minimum-space-to-comment.我不确定为什么后续(第三和第四)行可以正常工作。我不太使用旁注,因此这不是一个主要问题(您可以在此类块上使用
--format-skipping
)。There is an undocumented flag
--no-valign
which appears to achieve the best of both worlds without modifying the perltidy source.As you point out,
--no-add-whitespace
is too aggressive and prevents whitespace from being added in other, desirable locations (around operators etc.). With--no-valign
perltidy is still correcting things likemy ($arg)=@_;
tomy ($arg) = @_;
but does not attempt to vertically align operators across lines. The setting does not completely disable the vertical aligner, so you still get some benefits in other places (e.g. side-comments).The only problem I have found with this so far is that the first side-comment of a block of side-comments is not aligned with the subsequent ones:
It is only respecting
--minimum-space-to-comment
. I'm not sure why the subsequent (third and fourth) lines work properly. I don't use side-comments much so it's not a major issue (and you could use--format-skipping
on such blocks).以下补丁对我有用:
The following patch worked for me: