summaryrefslogtreecommitdiff
path: root/.perltidyrc
blob: 2e08554de9c2cbfe289f7af4eeb641de2765955f (plain)
  1. # use best practices, except use of stdout
  2. --perl-best-practices
  3. --no-standard-output
  4. --no-standard-error-output
  5. # use TAB for lead indentation
  6. --tabs
  7. --entab-leading-whitespace=4
  8. -nola
  9. # indent only already indented comments
  10. --indent-spaced-block-comments
  11. # put brace on new line for named subroutines
  12. --opening-sub-brace-on-new-line
  13. # preserve horisontally styled lists
  14. --break-at-old-comma-breakpoints
  15. # overwrite (we use CVS), and leave backup only on error
  16. --backup-file-extension=/~
hl">B<biblatex-tidy> reformats BibLaTeX data.
  • If a only a single filename is given,
  • the file contents are replaced.
  • If two filenames are given,
  • the first is read and cleaned output is saved the the second.
  • If no filenames are given,
  • then data is expected on STDIN
  • and cleaned data is emitted on STDOUT.
  • Internally,
  • the tool B<bibclean> is called internally to do the actual tidying.
  • If data contains a line beginning with C<@Comment{jabref-meta:>,
  • typically added by JabRef at the end of BibLaTeX data,
  • then the remaining data is I<not> cleaned,
  • because B<bibclean> fails to parse such comments.
  • =cut
  • # slurp INFILE if passed as first argument, or else STDIN
  • my ( $infile, $outfile, $bogus ) = @ARGV;
  • die 'Too many arguments: expected INFILE and OUTFILE' if $bogus;
  • @ARGV = ($infile) if $infile;
  • my $content = do { local $/ = undef; <> };
  • # put aside eventual trailing JabRef comments to not confuse bibclean
  • my ( $data, $comments ) = split /(?=\n\@Comment\{jabref-meta:)/, $content, 2;
  • # call bibclean on comment-stripped data
  • my @command = qw(bibclean -max-width 0);
  • my $newdata;
  • run3( \@command, \$data, \$newdata,
  • { binmode_stdin => ':utf8', binmode_stdout => ':utf8' } )
  • or die "Failed to execute @command: $?";
  • # save/replace/spew cleaned data, reviving eventual trailing comments
  • if ($infile) {
  • open( FH, '>', $outfile || $infile ) or die $!;
  • print FH $newdata, $comments;
  • }
  • else {
  • print $newdata, $comments;
  • }
  • =encoding UTF-8
  • =head1 AUTHOR
  • Jonas Smedegaard C<< <dr@jones.dk> >>
  • =head1 COPYRIGHT AND LICENSE
  • Copyright © 2024 Jonas Smedegaard
  • This program is free software:
  • you can redistribute it and/or modify it
  • under the terms of the GNU Affero General Public License
  • as published by the Free Software Foundation,
  • either version 3, or (at your option) any later version.
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY;
  • without even the implied warranty
  • of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  • See the GNU Affero General Public License for more details.
  • You should have received a copy
  • of the GNU Affero General Public License along with this program.
  • If not, see <https://www.gnu.org/licenses/>.
  • =cut
  • 1;