Skip to content

Commit

Permalink
Add perltidy formatter (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohkale authored Apr 22, 2023
1 parent 2686e7b commit 93c11bf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ The format is based on [Keep a Changelog].
* [`cmake-format`](https://github.com/cheshirekow/cmake_format)
for [CMake](https://cmake.org/) ([#172]).
* [`html-tidy`](https://www.html-tidy.org/) for HTML/XML ([#173]).
* [`perltidy`](https://perltidy.sourceforge.net/) for
[perl](https://www.perl.org/) ([#175]).

[#168]: https://github.com/radian-software/apheleia/pull/168
[#169]: https://github.com/radian-software/apheleia/pull/169
Expand All @@ -37,6 +39,7 @@ The format is based on [Keep a Changelog].
[#172]: https://github.com/radian-software/apheleia/pull/172
[#173]: https://github.com/radian-software/apheleia/pull/173
[#174]: https://github.com/radian-software/apheleia/pull/174
[#175]: https://github.com/radian-software/apheleia/pull/175
[#182]: https://github.com/radian-software/apheleia/pull/182
[#187]: https://github.com/radian-software/apheleia/pull/187

Expand Down
2 changes: 2 additions & 0 deletions apheleia.el
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
(nixfmt . ("nixfmt"))
(ocamlformat . ("ocamlformat" "-" "--name" filepath
"--enable-outside-detected-project"))
(perltidy . ("perltidy" "--quiet" "--standard-error-output"))
(phpcs . ("apheleia-phpcs"))
(prettier
. (npx "prettier" "--stdin-filepath" filepath
Expand Down Expand Up @@ -255,6 +256,7 @@ rather than using this system."
(lisp-mode . lisp-indent)
(nasm-mode . asmfmt)
(nix-mode . nixfmt)
(perl-mode . perltidy)
(purescript-mode . purs-tidy)
(python-mode . black)
(python-ts-mode . black)
Expand Down
1 change: 1 addition & 0 deletions test/formatters/installers/perltidy.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apt-get install -y perltidy
2 changes: 2 additions & 0 deletions test/formatters/samplecode/perltidy/in.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Taken from https://stackoverflow.com/q/30848816
while(read+STDIN,$_,2048){$a=29;$b=73;$c=142;$t=255;@t=map{$_%16or$t^=$c^=($m=(11,10,116,100,11,122,20,100)[$_/16%8])&110;$t^=(72,@z=(64,72,$a^=12*($_%16-2?0:$m&17)),$b^=$_%64?12:0,@z)[$_%8]}(16..271);if((@a=unx"C*",$_)[20]&48){$h=5;$_=unxb24,join"",@b=map{xB8,unxb8,chr($_^$a[--$h+84])}@ARGV;s/...$/1$&/;$d=unxV,xb25,$_;$e=256|(ord$b[4])<<9|ord$b[3];$d=$d>>8^($f=$t&($d>>12^$d>>4^$d^$d/8))<<17,$e=$e>>8^($t&($g=($q=$e>>14&7^$e)^$q*8^$q<<6))<<9,$_=$t[$_]^(($h>>=8)+=$f+(~$g&$t))for@a[128..$#a]}print+x"C*",@a}
32 changes: 32 additions & 0 deletions test/formatters/samplecode/perltidy/out.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Taken from https://stackoverflow.com/q/30848816
while ( read +STDIN, $_, 2048 ) {
$a = 29;
$b = 73;
$c = 142;
$t = 255;
@t = map {
$_ % 16
or $t ^= $c ^=
( $m = ( 11, 10, 116, 100, 11, 122, 20, 100 )[ $_ / 16 % 8 ] ) & 110;
$t ^= (
72,
@z = ( 64, 72, $a ^= 12 * ( $_ % 16 - 2 ? 0 : $m & 17 ) ),
$b ^= $_ % 64 ? 12 : 0, @z
)[ $_ % 8 ]
} ( 16 .. 271 );
if ( ( @a = unx "C*", $_ )[20] & 48 ) {
$h = 5;
$_ = unxb24, join "",
@b = map { xB8, unxb8, chr( $_ ^ $a[ --$h + 84 ] ) } @ARGV;
s/...$/1$&/;
$d = unxV, xb25, $_;
$e = 256 | ( ord $b[4] ) << 9 | ord $b[3];
$d = $d >> 8 ^ ( $f = $t & ( $d >> 12 ^ $d >> 4 ^ $d ^ $d / 8 ) ) << 17,
$e =
$e
>> 8 ^ ( $t & ( $g = ( $q = $e >> 14 & 7 ^ $e ) ^ $q * 8 ^ $q << 6 ) )
<< 9, $_ = $t[$_] ^ ( ( $h >>= 8 ) += $f + ( ~$g & $t ) )
for @a[ 128 .. $#a ];
}
print +x "C*", @a;
}

0 comments on commit 93c11bf

Please sign in to comment.