Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cmhughes committed Oct 13, 2023
2 parents 098808b + c463648 commit 49f77d8
Show file tree
Hide file tree
Showing 63 changed files with 2,226 additions and 1,774 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-documentation-and-executables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: load the "base actions/checkout" so as to access latexindent.pl
uses: actions/checkout@v4
- name: installing texlive full
uses: xu-cheng/texlive-action/full@v1
uses: xu-cheng/texlive-action/full@v2
with:
run: |
github_sha_short=$(echo $GITHUB_SHA | cut -c1-7)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-docker-ghcr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
id: buildx
with:
install: true
- uses: docker/metadata-action@v4
- uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/${{ github.repository }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ FROM perl:5.38.0-slim-threaded-buster
#

ARG LATEXINDENT_VERSION
ENV LATEXINDENT_VERSION ${LATEXINDENT_VERSION:-V3.23.2}
ENV LATEXINDENT_VERSION ${LATEXINDENT_VERSION:-V3.23.3}

RUN apt-get update \
&& apt-get install \
Expand Down
142 changes: 58 additions & 84 deletions LatexIndent/BackUpFileProcedure.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ use Exporter qw/import/;
use Encode qw/decode/;
our @EXPORT_OK = qw/create_back_up_file check_if_different/;

# copy main file to a back up in the case of the overwrite switch being active
# copy main file to a backup in the case of the overwrite switch being active

sub create_back_up_file {
my $self = shift;

return unless ( ${$self}{overwrite} );

# if we want to over write the current file create a backup first
# if we want to overwrite the current file create a backup first
$logger->info("*Backup procedure (-w flag active):");

my $fileName = decode( "utf-8", ${$self}{fileName} );
Expand All @@ -46,110 +46,83 @@ sub create_back_up_file {
= sort { $fileExtensionPreference{$a} <=> $fileExtensionPreference{$b} } keys(%fileExtensionPreference);

# backup file name is the base name
my $backupFile = basename( ${$self}{fileName}, @fileExtensions );
my $backupFileNoExt = basename( ${$self}{fileName}, @fileExtensions );

# add the user's backup directory to the backup path
$backupFile = decode( "utf-8", "${$self}{cruftDirectory}/$backupFile" );
$backupFileNoExt = decode( "utf-8", "${$self}{cruftDirectory}/$backupFileNoExt" );

# local variables, determined from the YAML settings
my $onlyOneBackUp = $mainSettings{onlyOneBackUp};
my $maxNumberOfBackUps = $mainSettings{maxNumberOfBackUps};
my $cycleThroughBackUps = $mainSettings{cycleThroughBackUps};
my $backupExtension = $mainSettings{backupExtension};

# if both ($onlyOneBackUp and $maxNumberOfBackUps) then we have
# a conflict- er on the side of caution and turn off onlyOneBackUp
if ( $onlyOneBackUp and $maxNumberOfBackUps > 1 ) {
$logger->warn("*onlyOneBackUp=$onlyOneBackUp and maxNumberOfBackUps: $maxNumberOfBackUps");
$logger->warn("setting onlyOneBackUp=0 which will allow you to reach $maxNumberOfBackUps back ups");
# if both onlyOneBackUp and maxNumberOfBackUps are set, then we have a conflict
# err on the side of caution and turn off onlyOneBackUp
if ( $onlyOneBackUp and $maxNumberOfBackUps >= 1 ) {
$logger->warn("*onlyOneBackUp=$onlyOneBackUp and maxNumberOfBackUps=$maxNumberOfBackUps");
$logger->warn("setting onlyOneBackUp=0 which will allow you to reach $maxNumberOfBackUps backups");
$onlyOneBackUp = 0;
}

# if the user has specified that $maxNumberOfBackUps = 1 then
# they only want one backup
if ( $maxNumberOfBackUps == 1 ) {
$onlyOneBackUp = 1;
$logger->info("you set maxNumberOfBackUps=1, so I'm setting onlyOneBackUp: 1 ");
}
elsif ( $maxNumberOfBackUps <= 0 and !$onlyOneBackUp ) {
$onlyOneBackUp = 0;
$maxNumberOfBackUps = -1;
}
# determine the backup file name by adjoining backupExtension
my $backupFile = $backupFileNoExt . $backupExtension;

# if onlyOneBackUp is set, then the backup file will
# be overwritten each time
if ($onlyOneBackUp) {
$backupFile .= $backupExtension;
$logger->info("copying $fileName to $backupFile");
$logger->info("$backupFile was overwritten (see onlyOneBackUp)") if ( -e $backupFile );
}
else {
# start with a backup file .bak0 (or whatever $backupExtension is present)
# if onlyOneBackUp is *not* set, add a number to the backup file name
if ( !$onlyOneBackUp ) {
my $backupCounter = 0;
$backupFile .= $backupExtension . $backupCounter;

# if it exists, then keep going: .bak0, .bak1, ...
while ( -e $backupFile or $maxNumberOfBackUps > 1 ) {
if ( $backupCounter == $maxNumberOfBackUps ) {
$logger->info("maxNumberOfBackUps reached ($maxNumberOfBackUps, see maxNumberOfBackUps)");

# some users may wish to cycle through back up files, e.g:
# copy myfile.bak1 to myfile.bak0
# copy myfile.bak2 to myfile.bak1
# copy myfile.bak3 to myfile.bak2
#
# current back up is stored in myfile.bak4
if ($cycleThroughBackUps) {
$logger->info("cycleThroughBackUps detected (see cycleThroughBackUps) ");
for ( my $i = 1; $i <= $maxNumberOfBackUps; $i++ ) {

# remove number from backUpFile
my $oldBackupFile = decode( "utf-8", $backupFile );
$oldBackupFile =~ s/$backupExtension.*/$backupExtension/;
my $newBackupFile = decode( "utf-8", $oldBackupFile );

# add numbers back on
$oldBackupFile .= $i;
$newBackupFile .= $i - 1;

# check that the oldBackupFile exists
if ( -e $oldBackupFile ) {
$logger->info(" copying $oldBackupFile to $newBackupFile ");
my $backUpFilePossible = 1;
copy( $oldBackupFile, $newBackupFile ) or ( $backUpFilePossible = 0 );
if ( $backUpFilePossible == 0 ) {
$logger->fatal(
"*Could not write to backup file $backupFile. Please check permissions. Exiting.");
$logger->fatal("Exiting, no indentation done.");
$self->output_logfile();
exit(5);
}

# if the file already exists, increment the number until either
# the file does not exist, or you reach the maximal number of backups
while ( -e ( $backupFile . $backupCounter ) and $backupCounter != ( $maxNumberOfBackUps - 1 ) ) {
$logger->info("$backupFile$backupCounter already exists, incrementing by 1 (see maxNumberOfBackUps)");
$backupCounter++;
}
$backupFile .= $backupCounter;
}

# if the backup file already exists, output some information in the log file
# and proceed to cycleThroughBackUps if the latter is set
if ( -e $backupFile ) {
if ($onlyOneBackUp) {
$logger->info("$backupFile will be overwritten (see onlyOneBackUp)");
}
else {
$logger->info("$backupFile will be overwritten (maxNumberOfBackUps reached, see maxNumberOfBackUps)");

# some users may wish to cycle through backup files, e.g.:
# copy myfile.bak1 to myfile.bak0
# copy myfile.bak2 to myfile.bak1
# copy myfile.bak3 to myfile.bak2
#
# current backup is stored in myfile.bak4
if ($cycleThroughBackUps) {
$logger->info("cycleThroughBackUps detected (see cycleThroughBackUps)");
my $oldBackupFile;
my $newBackupFile;
for ( my $i = 1; $i < $maxNumberOfBackUps; $i++ ) {
$oldBackupFile = $backupFileNoExt . $backupExtension . $i;
$newBackupFile = $backupFileNoExt . $backupExtension . ( $i - 1 );

# check that the oldBackupFile exists
if ( -e $oldBackupFile ) {
$logger->info("Copying $oldBackupFile to $newBackupFile...");
if ( !( copy( $oldBackupFile, $newBackupFile ) ) ) {
$logger->fatal("*Could not write to backup file $newBackupFile. Please check permissions.");
$logger->fatal("Exiting, no indentation done.");
$self->output_logfile();
exit(5);
}
}
}

# rest maxNumberOfBackUps
$maxNumberOfBackUps = 1;
last; # break out of the loop
}
elsif ( !( -e $backupFile ) ) {
$maxNumberOfBackUps = 1;
last; # break out of the loop
}
$logger->info(
"$backupFile already exists, incrementing by 1... (see maxNumberOfBackUps and onlyOneBackUp)");
$backupCounter++;
$backupFile =~ s/$backupExtension.*/$backupExtension$backupCounter/;
}
$logger->info("copying $fileName to $backupFile");
}

# output these lines to the log file
$logger->info("Backup file: $backupFile");
$logger->info("Backing up $fileName to $backupFile...");
$logger->info("$fileName will be overwritten after indentation");
my $backUpFilePossible = 1;
copy( $fileName, $backupFile ) or ( $backUpFilePossible = 0 );
if ( $backUpFilePossible == 0 ) {
if ( !( copy( $fileName, $backupFile ) ) ) {
$logger->fatal("*Could not write to backup file $backupFile. Please check permissions.");
$logger->fatal("Exiting, no indentation done.");
$self->output_logfile();
Expand All @@ -162,7 +135,7 @@ sub check_if_different {

if ( ${$self}{originalBody} eq ${$self}{body} ) {
$logger->info("*-wd switch active");
$logger->info("Original body matches indented body, NOT overwriting, no back up files created");
$logger->info("Original body matches indented body, NOT overwriting, no backup files created");
return;
}

Expand All @@ -173,4 +146,5 @@ sub check_if_different {
${$self}{overwrite} = 1;
$self->create_back_up_file;
}

1;
28 changes: 27 additions & 1 deletion LatexIndent/Environment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,32 @@ sub construct_environments_regexp {

# read from fine tuning
my $environmentNameRegExp = qr/${${$mainSettings{fineTuning}}{environments}}{name}/;
$environmentRegExp = qr/

if ( defined ${ ${ $mainSettings{fineTuning} }{environments} }{begin}
and defined ${ ${ $mainSettings{fineTuning} }{environments} }{end} )
{
$environmentRegExp = qr/
(
${${$mainSettings{fineTuning}}{environments}}{begin}
(\R*)? # possible line breaks (into $3)
) # begin statement captured into $1
(
(?: # cluster-only (), don't capture
(?! # don't include \begin in the body
(?:\\begin\{) # cluster-only (), don't capture
). # any character, but not \\begin
)*? # non-greedy
(\R*)? # possible line breaks (into $5)
) # environment body captured into $4
(
${${$mainSettings{fineTuning}}{environments}}{end}
) # captured into $6
(\h*)? # possibly followed by horizontal space
(\R)? # possibly followed by a line break
/sx;
}
else {
$environmentRegExp = qr/
(
\\begin\{
(
Expand All @@ -62,6 +87,7 @@ sub construct_environments_regexp {
(\h*)? # possibly followed by horizontal space
(\R)? # possibly followed by a line break
/sx;
}
}

sub find_environments {
Expand Down
4 changes: 2 additions & 2 deletions LatexIndent/Version.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ use warnings;
use Exporter qw/import/;
our @EXPORT_OK = qw/$versionNumber $versionDate/;

our $versionNumber = '3.23.2';
our $versionDate = '2023-09-23';
our $versionNumber = '3.23.3';
our $versionDate = '2023-10-13';
1

0 comments on commit 49f77d8

Please sign in to comment.